@@ -464,7 +464,7 @@ func (r *Reconciler) reconcileMachineHealthCheck(ctx context.Context, current, d
464464 if err != nil {
465465 return errors .Wrapf (err , "failed to create patch helper for MachineHealthCheck %s" , klog .KObj (desired ))
466466 }
467- if err := helper .Patch (ctx ); err != nil {
467+ if _ , err := helper .Patch (ctx ); err != nil {
468468 return errors .Wrapf (err , "failed to create MachineHealthCheck %s" , klog .KObj (desired ))
469469 }
470470 r .recorder .Eventf (desired , corev1 .EventTypeNormal , createEventReason , "Created MachineHealthCheck %q" , klog .KObj (desired ))
@@ -500,7 +500,7 @@ func (r *Reconciler) reconcileMachineHealthCheck(ctx context.Context, current, d
500500 }
501501
502502 log .Info ("Patching MachineHealthCheck" )
503- if err := patchHelper .Patch (ctx ); err != nil {
503+ if _ , err := patchHelper .Patch (ctx ); err != nil {
504504 return errors .Wrapf (err , "failed to patch MachineHealthCheck %s" , klog .KObj (current ))
505505 }
506506 r .recorder .Eventf (current , corev1 .EventTypeNormal , updateEventReason , "Updated MachineHealthCheck %q" , klog .KObj (current ))
@@ -530,19 +530,19 @@ func (r *Reconciler) reconcileCluster(ctx context.Context, s *scope.Scope) error
530530 } else {
531531 log .Info ("Patching Cluster" , "diff" , string (changes ))
532532 }
533- if err := patchHelper .Patch (ctx ); err != nil {
533+ modifiedResourceVersion , err := patchHelper .Patch (ctx )
534+ if err != nil {
534535 return errors .Wrapf (err , "failed to patch Cluster %s" , klog .KObj (s .Current .Cluster ))
535536 }
536537 r .recorder .Eventf (s .Current .Cluster , corev1 .EventTypeNormal , updateEventReason , "Updated Cluster %q" , klog .KObj (s .Current .Cluster ))
537538
538539 // Wait until Cluster is updated in the cache.
539540 // Note: We have to do this because otherwise using a cached client in the Reconcile func could
540541 // return a stale state of the Cluster we just patched (because the cache might be stale).
541- // Note: It is good enough to check that the resource version changed. Other controllers might have updated the
542- // Cluster as well, but the combination of the patch call above without a conflict and a changed resource
543- // version here guarantees that we see the changes of our own update.
544542 // Note: Using DeepCopy to not modify s.Current.Cluster as it's not trivial to figure out what impact that would have.
545- return clientutil .WaitForCacheToBeUpToDate (ctx , r .Client , "Cluster update" , s .Current .Cluster .DeepCopy ())
543+ cluster := s .Current .Cluster .DeepCopy ()
544+ cluster .ResourceVersion = modifiedResourceVersion
545+ return clientutil .WaitForCacheToBeUpToDate (ctx , r .Client , "Cluster update" , cluster )
546546}
547547
548548// reconcileMachineDeployments reconciles the desired state of the MachineDeployment objects.
@@ -693,7 +693,7 @@ func (r *Reconciler) createMachineDeployment(ctx context.Context, s *scope.Scope
693693 bootstrapCleanupFunc ()
694694 return createErrorWithoutObjectName (ctx , err , md .Object )
695695 }
696- if err := helper .Patch (ctx ); err != nil {
696+ if _ , err := helper .Patch (ctx ); err != nil {
697697 // Best effort cleanup of the InfrastructureMachineTemplate & BootstrapTemplate (only on creation).
698698 infrastructureMachineCleanupFunc ()
699699 bootstrapCleanupFunc ()
@@ -814,7 +814,8 @@ func (r *Reconciler) updateMachineDeployment(ctx context.Context, s *scope.Scope
814814 } else {
815815 log .Info ("Patching MachineDeployment" , "diff" , string (changes ))
816816 }
817- if err := patchHelper .Patch (ctx ); err != nil {
817+ modifiedResourceVersion , err := patchHelper .Patch (ctx )
818+ if err != nil {
818819 // Best effort cleanup of the InfrastructureMachineTemplate & BootstrapTemplate (only on template rotation).
819820 infrastructureMachineCleanupFunc ()
820821 bootstrapCleanupFunc ()
@@ -825,10 +826,10 @@ func (r *Reconciler) updateMachineDeployment(ctx context.Context, s *scope.Scope
825826 // Wait until MachineDeployment is updated in the cache.
826827 // Note: We have to do this because otherwise using a cached client in current state could
827828 // return a stale state of a MachineDeployment we just patched (because the cache might be stale).
828- // Note: It is good enough to check that the resource version changed. Other controllers might have updated the
829- // MachineDeployment as well, but the combination of the patch call above without a conflict and a changed resource
830- // version here guarantees that we see the changes of our own update.
831- if err := clientutil .WaitForCacheToBeUpToDate (ctx , r .Client , "MachineDeployment update" , currentMD . Object ); err != nil {
829+ // Note: Using DeepCopy to not modify currentMD.Object as it's not trivial to figure out what impact that would have.
830+ md := currentMD . Object . DeepCopy ()
831+ md . ResourceVersion = modifiedResourceVersion
832+ if err := clientutil .WaitForCacheToBeUpToDate (ctx , r .Client , "MachineDeployment update" , md ); err != nil {
832833 return err
833834 }
834835
@@ -1016,7 +1017,7 @@ func (r *Reconciler) createMachinePool(ctx context.Context, s *scope.Scope, mp *
10161017 bootstrapCleanupFunc ()
10171018 return createErrorWithoutObjectName (ctx , err , mp .Object )
10181019 }
1019- if err := helper .Patch (ctx ); err != nil {
1020+ if _ , err := helper .Patch (ctx ); err != nil {
10201021 // Best effort cleanup of the InfrastructureMachinePool & BootstrapConfig (only on creation).
10211022 infrastructureMachineMachinePoolCleanupFunc ()
10221023 bootstrapCleanupFunc ()
@@ -1077,7 +1078,8 @@ func (r *Reconciler) updateMachinePool(ctx context.Context, s *scope.Scope, mpTo
10771078 } else {
10781079 log .Info ("Patching MachinePool" , "diff" , string (changes ))
10791080 }
1080- if err := patchHelper .Patch (ctx ); err != nil {
1081+ modifiedResourceVersion , err := patchHelper .Patch (ctx )
1082+ if err != nil {
10811083 return errors .Wrapf (err , "failed to patch MachinePool %s" , klog .KObj (currentMP .Object ))
10821084 }
10831085 r .recorder .Eventf (cluster , corev1 .EventTypeNormal , updateEventReason , "Updated MachinePool %q%s" , klog .KObj (currentMP .Object ), logMachinePoolVersionChange (currentMP .Object , desiredMP .Object ))
@@ -1088,7 +1090,9 @@ func (r *Reconciler) updateMachinePool(ctx context.Context, s *scope.Scope, mpTo
10881090 // Note: It is good enough to check that the resource version changed. Other controllers might have updated the
10891091 // MachinePool as well, but the combination of the patch call above without a conflict and a changed resource
10901092 // version here guarantees that we see the changes of our own update.
1091- if err := clientutil .WaitForCacheToBeUpToDate (ctx , r .Client , "MachinePool update" , currentMP .Object ); err != nil {
1093+ mp := currentMP .Object .DeepCopy ()
1094+ mp .ResourceVersion = modifiedResourceVersion
1095+ if err := clientutil .WaitForCacheToBeUpToDate (ctx , r .Client , "MachinePool update" , mp ); err != nil {
10921096 return err
10931097 }
10941098
@@ -1193,7 +1197,7 @@ func (r *Reconciler) reconcileReferencedObject(ctx context.Context, in reconcile
11931197 if err != nil {
11941198 return false , errors .Wrap (createErrorWithoutObjectName (ctx , err , in .desired ), "failed to create patch helper" )
11951199 }
1196- if err := helper .Patch (ctx ); err != nil {
1200+ if _ , err := helper .Patch (ctx ); err != nil {
11971201 return false , createErrorWithoutObjectName (ctx , err , in .desired )
11981202 }
11991203 r .recorder .Eventf (in .cluster , corev1 .EventTypeNormal , createEventReason , "Created %s %q" , in .desired .GetKind (), klog .KObj (in .desired ))
@@ -1224,7 +1228,7 @@ func (r *Reconciler) reconcileReferencedObject(ctx context.Context, in reconcile
12241228 } else {
12251229 log .Info (fmt .Sprintf ("Patching %s" , in .desired .GetKind ()), "diff" , string (changes ))
12261230 }
1227- if err := patchHelper .Patch (ctx ); err != nil {
1231+ if _ , err := patchHelper .Patch (ctx ); err != nil {
12281232 return false , errors .Wrapf (err , "failed to patch %s %s" , in .current .GetKind (), klog .KObj (in .current ))
12291233 }
12301234 r .recorder .Eventf (in .cluster , corev1 .EventTypeNormal , updateEventReason , "Updated %s %q%s" , in .desired .GetKind (), klog .KObj (in .desired ), logUnstructuredVersionChange (in .current , in .desired , in .versionGetter ))
@@ -1279,7 +1283,7 @@ func (r *Reconciler) reconcileReferencedTemplate(ctx context.Context, in reconci
12791283 if err != nil {
12801284 return false , errors .Wrap (createErrorWithoutObjectName (ctx , err , in .desired ), "failed to create patch helper" )
12811285 }
1282- if err := helper .Patch (ctx ); err != nil {
1286+ if _ , err := helper .Patch (ctx ); err != nil {
12831287 return false , createErrorWithoutObjectName (ctx , err , in .desired )
12841288 }
12851289 r .recorder .Eventf (in .cluster , corev1 .EventTypeNormal , createEventReason , "Created %s %q" , in .desired .GetKind (), klog .KObj (in .desired ))
@@ -1319,7 +1323,7 @@ func (r *Reconciler) reconcileReferencedTemplate(ctx context.Context, in reconci
13191323 } else {
13201324 log .Info (fmt .Sprintf ("Patching %s" , in .desired .GetKind ()), "diff" , string (changes ))
13211325 }
1322- if err := patchHelper .Patch (ctx ); err != nil {
1326+ if _ , err := patchHelper .Patch (ctx ); err != nil {
13231327 return false , errors .Wrapf (err , "failed to patch %s %s" , in .desired .GetKind (), klog .KObj (in .desired ))
13241328 }
13251329 r .recorder .Eventf (in .cluster , corev1 .EventTypeNormal , updateEventReason , "Updated %s %q (metadata changes)" , in .desired .GetKind (), klog .KObj (in .desired ))
@@ -1344,7 +1348,7 @@ func (r *Reconciler) reconcileReferencedTemplate(ctx context.Context, in reconci
13441348 if err != nil {
13451349 return false , errors .Wrap (createErrorWithoutObjectName (ctx , err , in .desired ), "failed to create patch helper" )
13461350 }
1347- if err := helper .Patch (ctx ); err != nil {
1351+ if _ , err := helper .Patch (ctx ); err != nil {
13481352 return false , createErrorWithoutObjectName (ctx , err , in .desired )
13491353 }
13501354 r .recorder .Eventf (in .cluster , corev1 .EventTypeNormal , createEventReason , "Created %s %q as a replacement for %q (template rotation)" , in .desired .GetKind (), klog .KObj (in .desired ), in .ref .Name )
0 commit comments