Skip to content

Commit ef89fdb

Browse files
authored
Add finalizers to ObjectMetaBuilder (#1094)
* add finalizers to ObjectMetaBuilder * adapt changelog * remove empty line * fix pre commit
1 parent 65bd2b1 commit ef89fdb

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

crates/stackable-operator/CHANGELOG.md

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

55
## [Unreleased]
66

7+
### Added
8+
9+
- Extend `ObjectMetaBuilder` with `finalizers` ([#1094]).
10+
11+
[#1094]: https://github.com/stackabletech/operator-rs/pull/1094
12+
713
## [0.97.0] - 2025-09-09
814

915
### Added

crates/stackable-operator/src/builder/meta.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ pub enum Error {
2424
/// It is strongly recommended to always call [`Self::with_recommended_labels()`]!
2525
#[derive(Clone, Default)]
2626
pub struct ObjectMetaBuilder {
27-
ownerreference: Option<OwnerReference>,
2827
annotations: Option<Annotations>,
28+
finalizers: Option<Vec<String>>,
2929
generate_name: Option<String>,
30-
namespace: Option<String>,
3130
labels: Option<Labels>,
31+
namespace: Option<String>,
3232
name: Option<String>,
33+
ownerreference: Option<OwnerReference>,
3334
}
3435

3536
impl ObjectMetaBuilder {
@@ -163,6 +164,26 @@ impl ObjectMetaBuilder {
163164
Ok(self)
164165
}
165166

167+
/// This adds a single finalizer to the existing finalizers.
168+
pub fn with_finalizer(&mut self, finalizer: impl Into<String>) -> &mut Self {
169+
self.finalizers
170+
.get_or_insert(Vec::new())
171+
.push(finalizer.into());
172+
self
173+
}
174+
175+
/// This adds multiple finalizers to the existing finalizers.
176+
pub fn with_finalizers(&mut self, finalizers: Vec<String>) -> &mut Self {
177+
self.finalizers.get_or_insert(Vec::new()).extend(finalizers);
178+
self
179+
}
180+
181+
/// This will replace all existing finalizers
182+
pub fn finalizers(&mut self, finalizers: Vec<String>) -> &mut Self {
183+
self.finalizers = Some(finalizers);
184+
self
185+
}
186+
166187
pub fn build(&self) -> ObjectMeta {
167188
// NOTE (Techassi): Shouldn't this take self instead of &self to consume
168189
// the builder and build ObjectMeta without cloning?
@@ -187,6 +208,7 @@ impl ObjectMetaBuilder {
187208
.map(|ownerreference| vec![ownerreference.clone()]),
188209
labels: self.labels.clone().map(|l| l.into()),
189210
annotations: self.annotations.clone().map(|a| a.into()),
211+
finalizers: self.finalizers.clone(),
190212
..ObjectMeta::default()
191213
}
192214
}
@@ -339,6 +361,7 @@ mod tests {
339361
})
340362
.unwrap()
341363
.with_annotation(("foo", "bar").try_into().unwrap())
364+
.with_finalizer("finalizer")
342365
.build();
343366

344367
assert_eq!(meta.generate_name, Some("generate_foo".to_string()));
@@ -352,5 +375,9 @@ mod tests {
352375
meta.annotations.as_ref().unwrap().get(&"foo".to_string()),
353376
Some(&"bar".to_string())
354377
);
378+
assert_eq!(
379+
meta.finalizers.as_ref().unwrap().first(),
380+
Some(&"finalizer".to_string())
381+
);
355382
}
356383
}

0 commit comments

Comments
 (0)