Skip to content

Commit a562007

Browse files
authored
fix(olm): no owner for cluster scoped objects (#360)
* fix(olm): no owner for cluster scoped objects * update changelog * typo
1 parent 13b51fe commit a562007

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
### Changed
8+
9+
- OLM deployer doesn't add owner references to cluster scoped objects anymore ([#360]).
10+
Owner references ensure that objects are garbage collected by OpenShift upon operator removal but they cause problems when the operator is updated.
11+
This means that cluster wide objects are not removed anymore when the operator is uninstalled.
12+
This behaviour is in line with the default behaviour of Helm and OLM.
13+
714
## [25.11.0] - 2025-11-07
815

916
## [25.11.0-rc1] - 2025-11-06

rust/olm-deployer/src/owner/mod.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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
1724
pub(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

Comments
 (0)