Skip to content

Commit eaa3168

Browse files
committed
add finalizers to ObjectMetaBuilder
1 parent 65bd2b1 commit eaa3168

File tree

1 file changed

+30
-2
lines changed
  • crates/stackable-operator/src/builder

1 file changed

+30
-2
lines changed

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

Lines changed: 30 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,27 @@ 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+
179+
self
180+
}
181+
182+
/// This will replace all existing finalizers
183+
pub fn finalizers(&mut self, finalizers: Vec<String>) -> &mut Self {
184+
self.finalizers = Some(finalizers);
185+
self
186+
}
187+
166188
pub fn build(&self) -> ObjectMeta {
167189
// NOTE (Techassi): Shouldn't this take self instead of &self to consume
168190
// the builder and build ObjectMeta without cloning?
@@ -187,6 +209,7 @@ impl ObjectMetaBuilder {
187209
.map(|ownerreference| vec![ownerreference.clone()]),
188210
labels: self.labels.clone().map(|l| l.into()),
189211
annotations: self.annotations.clone().map(|a| a.into()),
212+
finalizers: self.finalizers.clone(),
190213
..ObjectMeta::default()
191214
}
192215
}
@@ -339,6 +362,7 @@ mod tests {
339362
})
340363
.unwrap()
341364
.with_annotation(("foo", "bar").try_into().unwrap())
365+
.with_finalizer("finalizer")
342366
.build();
343367

344368
assert_eq!(meta.generate_name, Some("generate_foo".to_string()));
@@ -352,5 +376,9 @@ mod tests {
352376
meta.annotations.as_ref().unwrap().get(&"foo".to_string()),
353377
Some(&"bar".to_string())
354378
);
379+
assert_eq!(
380+
meta.finalizers.as_ref().unwrap().get(0),
381+
Some(&"finalizer".to_string())
382+
);
355383
}
356384
}

0 commit comments

Comments
 (0)