@@ -133,7 +133,7 @@ func (r *CNINodeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
133133
134134 if cniNode .GetDeletionTimestamp ().IsZero () {
135135 cniNodeCopy := cniNode .DeepCopy ()
136- shouldPatch , err := r .ensureTagsAndLables (cniNodeCopy , node , nodeFound )
136+ shouldPatch , err := r .ensureTagsAndLabels (cniNodeCopy , node , nodeFound )
137137 shouldPatch = r .ensureFinalizer (cniNodeCopy ) || shouldPatch
138138
139139 if shouldPatch {
@@ -164,8 +164,11 @@ func (r *CNINodeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
164164 }
165165 }
166166
167- if err := r .finalizerManager . RemoveFinalizers (ctx , cniNode , config .NodeTerminationFinalizer ); err != nil {
167+ if err := r .removeFinalizers (ctx , cniNode , config .NodeTerminationFinalizer ); err != nil {
168168 r .log .Error (err , "failed to remove finalizer on CNINode, will retry" , "cniNode" , cniNode .Name , "finalizer" , config .NodeTerminationFinalizer )
169+ if apierrors .IsConflict (err ) {
170+ return ctrl.Result {Requeue : true }, nil
171+ }
169172 return ctrl.Result {}, err
170173 }
171174 return ctrl.Result {}, nil
@@ -185,7 +188,7 @@ func (r *CNINodeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
185188 Spec : cniNode .Spec ,
186189 }
187190
188- if err := r .finalizerManager . RemoveFinalizers (ctx , cniNode , config .NodeTerminationFinalizer ); err != nil {
191+ if err := r .removeFinalizers (ctx , cniNode , config .NodeTerminationFinalizer ); err != nil {
189192 r .log .Error (err , "failed to remove finalizer on CNINode, will retry" )
190193 return ctrl.Result {}, err
191194 }
@@ -255,7 +258,7 @@ func (r *CNINodeReconciler) GetNodeID(node *v1.Node) (string, error) {
255258 return "" , fmt .Errorf ("invalid provider ID format for node %s, with providerId" , node .Spec .ProviderID )
256259}
257260
258- func (r * CNINodeReconciler ) ensureTagsAndLables (cniNode * v1alpha1.CNINode , node * v1.Node , nodeFound bool ) (bool , error ) {
261+ func (r * CNINodeReconciler ) ensureTagsAndLabels (cniNode * v1alpha1.CNINode , node * v1.Node , nodeFound bool ) (bool , error ) {
259262 shouldPatch := false
260263 var err error
261264 if cniNode .Spec .Tags == nil {
@@ -296,3 +299,19 @@ func (r *CNINodeReconciler) ensureFinalizer(cniNode *v1alpha1.CNINode) bool {
296299 }
297300 return shouldPatch
298301}
302+
303+ func (r * CNINodeReconciler ) removeFinalizers (ctx context.Context , cniNode * v1alpha1.CNINode , finalizer string ) error {
304+ cniNodeCopy := cniNode .DeepCopy ()
305+ needsUpdate := false
306+
307+ if controllerutil .ContainsFinalizer (cniNodeCopy , finalizer ) {
308+ r .log .Info ("removing finalizer for cninode" , "name" , cniNode .GetName (), "finalizer" , finalizer )
309+ controllerutil .RemoveFinalizer (cniNodeCopy , finalizer )
310+ needsUpdate = true
311+ }
312+
313+ if ! needsUpdate {
314+ return nil
315+ }
316+ return r .Client .Patch (ctx , cniNodeCopy , client .MergeFromWithOptions (cniNode , client.MergeFromWithOptimisticLock {}))
317+ }
0 commit comments