From eaa31680486356a2777ecf2da7ee938dd773d0e1 Mon Sep 17 00:00:00 2001 From: Malte Sander Date: Fri, 12 Sep 2025 17:03:26 +0200 Subject: [PATCH 1/4] add finalizers to ObjectMetaBuilder --- crates/stackable-operator/src/builder/meta.rs | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/crates/stackable-operator/src/builder/meta.rs b/crates/stackable-operator/src/builder/meta.rs index ed1c3b20c..c35a0ce3a 100644 --- a/crates/stackable-operator/src/builder/meta.rs +++ b/crates/stackable-operator/src/builder/meta.rs @@ -24,12 +24,13 @@ pub enum Error { /// It is strongly recommended to always call [`Self::with_recommended_labels()`]! #[derive(Clone, Default)] pub struct ObjectMetaBuilder { - ownerreference: Option, annotations: Option, + finalizers: Option>, generate_name: Option, - namespace: Option, labels: Option, + namespace: Option, name: Option, + ownerreference: Option, } impl ObjectMetaBuilder { @@ -163,6 +164,27 @@ impl ObjectMetaBuilder { Ok(self) } + /// This adds a single finalizer to the existing finalizers. + pub fn with_finalizer(&mut self, finalizer: impl Into) -> &mut Self { + self.finalizers + .get_or_insert(Vec::new()) + .push(finalizer.into()); + self + } + + /// This adds multiple finalizers to the existing finalizers. + pub fn with_finalizers(&mut self, finalizers: Vec) -> &mut Self { + self.finalizers.get_or_insert(Vec::new()).extend(finalizers); + + self + } + + /// This will replace all existing finalizers + pub fn finalizers(&mut self, finalizers: Vec) -> &mut Self { + self.finalizers = Some(finalizers); + self + } + pub fn build(&self) -> ObjectMeta { // NOTE (Techassi): Shouldn't this take self instead of &self to consume // the builder and build ObjectMeta without cloning? @@ -187,6 +209,7 @@ impl ObjectMetaBuilder { .map(|ownerreference| vec![ownerreference.clone()]), labels: self.labels.clone().map(|l| l.into()), annotations: self.annotations.clone().map(|a| a.into()), + finalizers: self.finalizers.clone(), ..ObjectMeta::default() } } @@ -339,6 +362,7 @@ mod tests { }) .unwrap() .with_annotation(("foo", "bar").try_into().unwrap()) + .with_finalizer("finalizer") .build(); assert_eq!(meta.generate_name, Some("generate_foo".to_string())); @@ -352,5 +376,9 @@ mod tests { meta.annotations.as_ref().unwrap().get(&"foo".to_string()), Some(&"bar".to_string()) ); + assert_eq!( + meta.finalizers.as_ref().unwrap().get(0), + Some(&"finalizer".to_string()) + ); } } From ff12cdf37f2dbe28010f40ae12bda43fda036e05 Mon Sep 17 00:00:00 2001 From: Malte Sander Date: Fri, 12 Sep 2025 17:05:22 +0200 Subject: [PATCH 2/4] adapt changelog --- crates/stackable-operator/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/stackable-operator/CHANGELOG.md b/crates/stackable-operator/CHANGELOG.md index c191ee5e9..9e0ec53b7 100644 --- a/crates/stackable-operator/CHANGELOG.md +++ b/crates/stackable-operator/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Added + +- Extend `ObjectMetaBuilder` with `finalizers` ([#1094]). + +[#1094]: https://github.com/stackabletech/operator-rs/pull/1094 + ## [0.97.0] - 2025-09-09 ### Added From fa658f1a26ccff16c5f1577a1e67f957856195f2 Mon Sep 17 00:00:00 2001 From: Malte Sander Date: Fri, 12 Sep 2025 17:07:24 +0200 Subject: [PATCH 3/4] remove empty line --- crates/stackable-operator/src/builder/meta.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/stackable-operator/src/builder/meta.rs b/crates/stackable-operator/src/builder/meta.rs index c35a0ce3a..3b15d8e88 100644 --- a/crates/stackable-operator/src/builder/meta.rs +++ b/crates/stackable-operator/src/builder/meta.rs @@ -175,7 +175,6 @@ impl ObjectMetaBuilder { /// This adds multiple finalizers to the existing finalizers. pub fn with_finalizers(&mut self, finalizers: Vec) -> &mut Self { self.finalizers.get_or_insert(Vec::new()).extend(finalizers); - self } From 730a48e5f502bc70aa57ece01112a98e29d3d785 Mon Sep 17 00:00:00 2001 From: Malte Sander Date: Fri, 12 Sep 2025 17:14:10 +0200 Subject: [PATCH 4/4] fix pre commit --- crates/stackable-operator/src/builder/meta.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/stackable-operator/src/builder/meta.rs b/crates/stackable-operator/src/builder/meta.rs index 3b15d8e88..df48fa815 100644 --- a/crates/stackable-operator/src/builder/meta.rs +++ b/crates/stackable-operator/src/builder/meta.rs @@ -376,7 +376,7 @@ mod tests { Some(&"bar".to_string()) ); assert_eq!( - meta.finalizers.as_ref().unwrap().get(0), + meta.finalizers.as_ref().unwrap().first(), Some(&"finalizer".to_string()) ); }