@@ -11,19 +11,30 @@ use stackable_operator::{
1111 } ,
1212} ;
1313
14- /// Updates the owner list of the `target` according to it's scope.
15- /// For namespaced objects it uses the `ns_owner` whereas for cluster wide
16- /// objects it uses the `cluster_owner`.
14+ /// Updates owner references of objects created by this deployer so that when an operator is
15+ /// uninstalled by OLM, all created objects are also removed by Kubernetes garbage collection.
16+ ///
17+ /// Namespaced object's owner references are updated in place with the value of `ns_owner`.
18+ ///
19+ /// A previous version of this function also updated cluster scoped objects to set the owner
20+ /// reference to `cluster_owner`, but this turned out to be problematic. First, this is not how OLM
21+ /// and Helm behave by default. Second, when updating the listener operator, deleting and recreating
22+ /// the CSI driver definition the cluster was left in a broken state.
23+ /// See: this comment for more details: https://github.com/stackabletech/issues/issues/799#issuecomment-3601121617
1724pub ( super ) fn maybe_update_owner (
1825 target : & mut DynamicObject ,
1926 scope : & Scope ,
2027 ns_owner : & Deployment ,
2128 cluster_owner : & ClusterRole ,
2229) -> Result < ( ) > {
2330 let owner_ref = owner_ref ( scope, ns_owner, cluster_owner) ?;
24- match target. metadata . owner_references {
25- Some ( ref mut ors) => ors. push ( owner_ref) ,
26- None => target. metadata . owner_references = Some ( vec ! [ owner_ref] ) ,
31+ // 2025-12-10: do not set owner references for cluster scoped objects anymore to prevent them from being
32+ // deleted upon operator upgrades.
33+ if scope == & Scope :: Namespaced {
34+ match target. metadata . owner_references {
35+ Some ( ref mut ors) => ors. push ( owner_ref) ,
36+ None => target. metadata . owner_references = Some ( vec ! [ owner_ref] ) ,
37+ }
2738 }
2839 Ok ( ( ) )
2940}
@@ -147,13 +158,7 @@ rules:
147158 let mut daemonset = DAEMONSET . clone ( ) ;
148159 maybe_update_owner ( & mut daemonset, & Scope :: Cluster , & DEPLOYMENT , & CLUSTER_ROLE ) ?;
149160
150- let expected = Some ( vec ! [ OwnerReference {
151- uid: "d9287d0a-3069-47c3-8c90-b714dc6dddaa" . to_string( ) ,
152- name: "listener-operator-clusterrole" . to_string( ) ,
153- kind: "ClusterRole" . to_string( ) ,
154- api_version: "rbac.authorization.k8s.io/v1" . to_string( ) ,
155- ..OwnerReference :: default ( )
156- } ] ) ;
161+ let expected = None ;
157162 assert_eq ! ( daemonset. metadata. owner_references, expected) ;
158163 Ok ( ( ) )
159164 }
0 commit comments