Skip to content

Commit 5c45d27

Browse files
authored
Check for ownerReferences in ClusterResources (#862)
* Check for `ownerReferences` in `ClusterResources` Fixes #861 * Changelog
1 parent b262bde commit 5c45d27

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

crates/stackable-operator/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ All notable changes to this project will be documented in this file.
1717

1818
- Fix the CRD description of `ClientAuthenticationDetails` to not contain internal Rust doc, but a public CRD description ([#846]).
1919
- `StackableAffinity` fields are no longer erroneously marked as required ([#855]).
20+
- BREAKING: `ClusterResources` will now only consider deleting objects that are marked as directly owned (via `.metadata.ownerReferences`) ([#862]).
2021

2122
[#846]: https://github.com/stackabletech/operator-rs/pull/846
2223
[#851]: https://github.com/stackabletech/operator-rs/pull/851
2324
[#855]: https://github.com/stackabletech/operator-rs/pull/855
2425
[#858]: https://github.com/stackabletech/operator-rs/pull/858
26+
[#862]: https://github.com/stackabletech/operator-rs/pull/862
2527

2628
## [0.74.0] - 2024-08-22
2729

crates/stackable-operator/src/cluster_resources.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,9 @@ pub struct ClusterResources {
388388
/// The name of the application
389389
app_name: String,
390390

391+
/// The uid of the cluster object
392+
cluster_uid: String,
393+
391394
// TODO (Techassi): Add doc comments
392395
operator_name: String,
393396

@@ -434,17 +437,22 @@ impl ClusterResources {
434437
) -> Result<Self> {
435438
let namespace = cluster
436439
.namespace
437-
.to_owned()
440+
.clone()
438441
.context(MissingObjectKeySnafu { key: "namespace" })?;
439442
let app_instance = cluster
440443
.name
441-
.to_owned()
444+
.clone()
442445
.context(MissingObjectKeySnafu { key: "name" })?;
446+
let cluster_uid = cluster
447+
.uid
448+
.clone()
449+
.context(MissingObjectKeySnafu { key: "uid" })?;
443450

444451
Ok(ClusterResources {
445452
namespace,
446453
app_instance,
447454
app_name: app_name.into(),
455+
cluster_uid,
448456
operator_name: operator_name.into(),
449457
controller_name: controller_name.into(),
450458
manager: format_full_controller_name(operator_name, controller_name),
@@ -741,10 +749,22 @@ impl ClusterResources {
741749
..Default::default()
742750
};
743751

744-
let resources = client
752+
let mut resources = client
745753
.list_with_label_selector::<T>(&self.namespace, &label_selector)
746754
.await?;
747755

756+
// filter out objects without a direct ownership relationship, for example:
757+
// - indirect ownership where the labels are still propagated
758+
// - objects owned by versions of the cluster recreated before/after the current snapshot
759+
resources.retain(|resource| {
760+
resource
761+
.meta()
762+
.owner_references
763+
.iter()
764+
.flatten()
765+
.any(|reference| reference.uid == self.cluster_uid)
766+
});
767+
748768
Ok(resources)
749769
}
750770
}

0 commit comments

Comments
 (0)