@@ -354,8 +354,16 @@ func (r *FunctionReconciler) ApplyFunctionVPA(ctx context.Context, function *v1a
354354}
355355
356356func (r * FunctionReconciler ) ApplyFunctionCleanUpJob (ctx context.Context , function * v1alpha1.Function ) error {
357+ desiredJob := spec .MakeFunctionCleanUpJob (function )
358+ hasCleanupFinalizer := containsCleanupFinalizer (function .ObjectMeta .Finalizers )
359+ if desiredJob == nil {
360+ if hasCleanupFinalizer {
361+ function .ObjectMeta .Finalizers = removeCleanupFinalizer (function .ObjectMeta .Finalizers )
362+ return r .Update (ctx , function )
363+ }
364+ return nil
365+ }
357366 if ! spec .NeedCleanup (function ) {
358- desiredJob := spec .MakeFunctionCleanUpJob (function )
359367 if err := r .Delete (ctx , desiredJob , getBackgroundDeletionPolicy ()); err != nil {
360368 if errors .IsNotFound (err ) {
361369 return nil
@@ -367,12 +375,10 @@ func (r *FunctionReconciler) ApplyFunctionCleanUpJob(ctx context.Context, functi
367375 }
368376 return nil
369377 }
370- hasCleanupFinalizer := containsCleanupFinalizer (function .ObjectMeta .Finalizers )
371378 if function .Spec .CleanupSubscription {
372379 // add finalizer if function is updated to clean up subscription
373380 if function .ObjectMeta .DeletionTimestamp .IsZero () {
374381 if ! hasCleanupFinalizer {
375- desiredJob := spec .MakeFunctionCleanUpJob (function )
376382 if _ , err := ctrl .CreateOrUpdate (ctx , r .Client , desiredJob , func () error {
377383 return nil
378384 }); err != nil {
@@ -387,7 +393,6 @@ func (r *FunctionReconciler) ApplyFunctionCleanUpJob(ctx context.Context, functi
387393 }
388394 }
389395 } else {
390- desiredJob := spec .MakeFunctionCleanUpJob (function )
391396 // if function is deleting, send an "INT" signal to the cleanup job to clean up subscription
392397 if hasCleanupFinalizer {
393398 if err := spec .TriggerCleanup (ctx , r .Client , r .RestClient , r .Config , desiredJob ); err != nil {
@@ -413,7 +418,6 @@ func (r *FunctionReconciler) ApplyFunctionCleanUpJob(ctx context.Context, functi
413418 return err
414419 }
415420
416- desiredJob := spec .MakeFunctionCleanUpJob (function )
417421 // delete the cleanup job
418422 if err := r .Delete (ctx , desiredJob , getBackgroundDeletionPolicy ()); err != nil {
419423 return err
0 commit comments