Skip to content

Commit d90e550

Browse files
authored
fix(olm): no owner for cluster scoped objects (#667)
* fix(olm): no owner for cluster scoped objects * update changelog * typo * cleanup
1 parent bb2fdd9 commit d90e550

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ 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 ([#667]).
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+
14+
[#667]: https://github.com/stackabletech/secret-operator/pull/667
15+
716
## [25.11.0] - 2025-11-07
817

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

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,27 @@ 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.
1721
pub(super) fn maybe_update_owner(
1822
target: &mut DynamicObject,
1923
scope: &Scope,
2024
ns_owner: &Deployment,
2125
cluster_owner: &ClusterRole,
2226
) -> Result<()> {
2327
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]),
28+
// 2025-12-12: do not set owner references for cluster scoped objects anymore to prevent them from being
29+
// deleted upon operator upgrades.
30+
if scope == &Scope::Namespaced {
31+
match target.metadata.owner_references {
32+
Some(ref mut ors) => ors.push(owner_ref),
33+
None => target.metadata.owner_references = Some(vec![owner_ref]),
34+
}
2735
}
2836
Ok(())
2937
}
@@ -147,13 +155,8 @@ rules:
147155
let mut daemonset = DAEMONSET.clone();
148156
maybe_update_owner(&mut daemonset, &Scope::Cluster, &DEPLOYMENT, &CLUSTER_ROLE)?;
149157

150-
let expected = Some(vec![OwnerReference {
151-
uid: "d9287d0a-3069-47c3-8c90-b714dc6dddaa".to_string(),
152-
name: "secret-operator-clusterrole".to_string(),
153-
kind: "ClusterRole".to_string(),
154-
api_version: "rbac.authorization.k8s.io/v1".to_string(),
155-
..OwnerReference::default()
156-
}]);
158+
let expected = None;
159+
157160
assert_eq!(daemonset.metadata.owner_references, expected);
158161
Ok(())
159162
}

0 commit comments

Comments
 (0)