@@ -33,6 +33,7 @@ import (
3333 "k8s.io/utils/ptr"
3434 ctrl "sigs.k8s.io/controller-runtime"
3535 "sigs.k8s.io/controller-runtime/pkg/client"
36+ "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
3637 klog "sigs.k8s.io/controller-runtime/pkg/log"
3738)
3839
@@ -64,8 +65,8 @@ func (r *JobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R
6465 return ctrl.Result {}, nil
6566 }
6667
67- // The job has not completed, and so we have nothing to do
68- if job .Status .CompletionTime .IsZero () {
68+ // The job has not completed, or StatefulSet has been updated, so we have nothing to do
69+ if job .Status .CompletionTime .IsZero () || ! controllerutil . ContainsFinalizer ( & job , finalizerName ) {
6970 return ctrl.Result {}, nil
7071 }
7172
@@ -76,13 +77,9 @@ func (r *JobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R
7677 return ctrl.Result {}, err
7778 }
7879
79- // If the job status is `done`, we want to delete this job
80+ // If the job status is `done`, we have nothing to do
8081 if sfs .Annotations [iamProbeStatus ] == iamProbeDone {
81- err := client .IgnoreNotFound (r .Delete (ctx , & job ))
82- if err != nil {
83- log .Error (err , "failed to queue job deletion" )
84- }
85- return ctrl.Result {}, err
82+ return ctrl.Result {}, nil
8683 }
8784
8885 // Parse the IAM probe status to find the original replica count
@@ -153,9 +150,11 @@ func (r *JobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R
153150 return ctrl.Result {}, err
154151 }
155152
156- if err := r .Delete (ctx , & job ); client .IgnoreNotFound (err ) != nil {
157- log .Error (err , "failed to queue job deletion" )
158- return ctrl.Result {}, err
153+ if controllerutil .RemoveFinalizer (& job , finalizerName ) {
154+ if err := r .Update (ctx , & job ); err != nil {
155+ log .Error (err , "failed to remove finalizer" )
156+ return ctrl.Result {}, err
157+ }
159158 }
160159
161160 return ctrl.Result {}, nil
0 commit comments