@@ -24,12 +24,13 @@ pub enum Error {
2424/// It is strongly recommended to always call [`Self::with_recommended_labels()`]!
2525#[ derive( Clone , Default ) ]
2626pub 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
3536impl 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