@@ -24,12 +24,13 @@ pub enum Error {
24
24
/// It is strongly recommended to always call [`Self::with_recommended_labels()`]!
25
25
#[ derive( Clone , Default ) ]
26
26
pub struct ObjectMetaBuilder {
27
- ownerreference : Option < OwnerReference > ,
28
27
annotations : Option < Annotations > ,
28
+ finalizers : Option < Vec < String > > ,
29
29
generate_name : Option < String > ,
30
- namespace : Option < String > ,
31
30
labels : Option < Labels > ,
31
+ namespace : Option < String > ,
32
32
name : Option < String > ,
33
+ ownerreference : Option < OwnerReference > ,
33
34
}
34
35
35
36
impl ObjectMetaBuilder {
@@ -163,6 +164,26 @@ impl ObjectMetaBuilder {
163
164
Ok ( self )
164
165
}
165
166
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
+
166
187
pub fn build ( & self ) -> ObjectMeta {
167
188
// NOTE (Techassi): Shouldn't this take self instead of &self to consume
168
189
// the builder and build ObjectMeta without cloning?
@@ -187,6 +208,7 @@ impl ObjectMetaBuilder {
187
208
. map ( |ownerreference| vec ! [ ownerreference. clone( ) ] ) ,
188
209
labels : self . labels . clone ( ) . map ( |l| l. into ( ) ) ,
189
210
annotations : self . annotations . clone ( ) . map ( |a| a. into ( ) ) ,
211
+ finalizers : self . finalizers . clone ( ) ,
190
212
..ObjectMeta :: default ( )
191
213
}
192
214
}
@@ -339,6 +361,7 @@ mod tests {
339
361
} )
340
362
. unwrap ( )
341
363
. with_annotation ( ( "foo" , "bar" ) . try_into ( ) . unwrap ( ) )
364
+ . with_finalizer ( "finalizer" )
342
365
. build ( ) ;
343
366
344
367
assert_eq ! ( meta. generate_name, Some ( "generate_foo" . to_string( ) ) ) ;
@@ -352,5 +375,9 @@ mod tests {
352
375
meta. annotations. as_ref( ) . unwrap( ) . get( & "foo" . to_string( ) ) ,
353
376
Some ( & "bar" . to_string( ) )
354
377
) ;
378
+ assert_eq ! (
379
+ meta. finalizers. as_ref( ) . unwrap( ) . first( ) ,
380
+ Some ( & "finalizer" . to_string( ) )
381
+ ) ;
355
382
}
356
383
}
0 commit comments