@@ -214,7 +214,11 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.
214
214
}
215
215
216
216
// Always attempt to Patch the KubeadmControlPlane object and status after each reconciliation.
217
- if err := patchKubeadmControlPlane (ctx , patchHelper , kcp ); err != nil {
217
+ patchOpts := []patch.Option {}
218
+ if reterr == nil {
219
+ patchOpts = append (patchOpts , patch.WithStatusObservedGeneration {})
220
+ }
221
+ if err := patchKubeadmControlPlane (ctx , patchHelper , kcp , patchOpts ... ); err != nil {
218
222
log .Error (err , "Failed to patch KubeadmControlPlane" )
219
223
reterr = kerrors .NewAggregate ([]error {reterr , err })
220
224
}
@@ -307,7 +311,7 @@ func (r *KubeadmControlPlaneReconciler) initControlPlaneScope(ctx context.Contex
307
311
return controlPlane , false , nil
308
312
}
309
313
310
- func patchKubeadmControlPlane (ctx context.Context , patchHelper * patch.Helper , kcp * controlplanev1.KubeadmControlPlane ) error {
314
+ func patchKubeadmControlPlane (ctx context.Context , patchHelper * patch.Helper , kcp * controlplanev1.KubeadmControlPlane , options ... patch. Option ) error {
311
315
// Always update the readyCondition by summarizing the state of other conditions.
312
316
conditions .SetSummary (kcp ,
313
317
conditions .WithConditions (
@@ -321,20 +325,19 @@ func patchKubeadmControlPlane(ctx context.Context, patchHelper *patch.Helper, kc
321
325
)
322
326
323
327
// Patch the object, ignoring conflicts on the conditions owned by this controller.
324
- return patchHelper .Patch (
325
- ctx ,
326
- kcp ,
327
- patch.WithOwnedConditions {Conditions : []clusterv1.ConditionType {
328
- controlplanev1 .MachinesCreatedCondition ,
329
- clusterv1 .ReadyCondition ,
330
- controlplanev1 .MachinesSpecUpToDateCondition ,
331
- controlplanev1 .ResizedCondition ,
332
- controlplanev1 .MachinesReadyCondition ,
333
- controlplanev1 .AvailableCondition ,
334
- controlplanev1 .CertificatesAvailableCondition ,
335
- }},
336
- patch.WithStatusObservedGeneration {},
337
- )
328
+ // Also, if requested, we are adding additional options like e.g. Patch ObservedGeneration when issuing the
329
+ // patch at the end of the reconcile loop.
330
+ options = append (options , patch.WithOwnedConditions {Conditions : []clusterv1.ConditionType {
331
+ controlplanev1 .MachinesCreatedCondition ,
332
+ clusterv1 .ReadyCondition ,
333
+ controlplanev1 .MachinesSpecUpToDateCondition ,
334
+ controlplanev1 .ResizedCondition ,
335
+ controlplanev1 .MachinesReadyCondition ,
336
+ controlplanev1 .AvailableCondition ,
337
+ controlplanev1 .CertificatesAvailableCondition ,
338
+ }})
339
+
340
+ return patchHelper .Patch (ctx , kcp , options ... )
338
341
}
339
342
340
343
// reconcile handles KubeadmControlPlane reconciliation.
0 commit comments