@@ -184,7 +184,7 @@ func (r *Reconciler) reconcileControlPlane(ctx context.Context, s *scope.Scope)
184
184
185
185
cpInfraRef , err := contract .ControlPlane ().MachineTemplate ().InfrastructureRef ().Get (s .Desired .ControlPlane .Object )
186
186
if err != nil {
187
- return errors .Wrapf (err , "failed to update %s" , tlog.KObj {Obj : s .Desired .ControlPlane .InfrastructureMachineTemplate })
187
+ return errors .Wrapf (err , "failed to reconcile %s" , tlog.KObj {Obj : s .Desired .ControlPlane .InfrastructureMachineTemplate })
188
188
}
189
189
190
190
// Create or update the MachineInfrastructureTemplate of the control plane.
@@ -198,13 +198,13 @@ func (r *Reconciler) reconcileControlPlane(ctx context.Context, s *scope.Scope)
198
198
},
199
199
)
200
200
if err != nil {
201
- return errors .Wrapf (err , "failed to update %s" , tlog.KObj {Obj : s .Desired .ControlPlane .InfrastructureMachineTemplate })
201
+ return errors .Wrapf (err , "failed to reconcile %s" , tlog.KObj {Obj : s .Desired .ControlPlane .InfrastructureMachineTemplate })
202
202
}
203
203
204
204
// The controlPlaneObject.Spec.machineTemplate.infrastructureRef has to be updated in the desired object
205
205
err = contract .ControlPlane ().MachineTemplate ().InfrastructureRef ().Set (s .Desired .ControlPlane .Object , refToUnstructured (cpInfraRef ))
206
206
if err != nil {
207
- return errors .Wrapf (err , "failed to update %s" , tlog.KObj {Obj : s .Desired .ControlPlane .Object })
207
+ return errors .Wrapf (err , "failed to reconcile %s" , tlog.KObj {Obj : s .Desired .ControlPlane .Object })
208
208
}
209
209
}
210
210
@@ -227,7 +227,7 @@ func (r *Reconciler) reconcileControlPlane(ctx context.Context, s *scope.Scope)
227
227
},
228
228
},
229
229
}); err != nil {
230
- return errors .Wrapf (err , "failed to update %s" , tlog.KObj {Obj : s .Desired .ControlPlane .Object })
230
+ return errors .Wrapf (err , "failed to reconcile %s" , tlog.KObj {Obj : s .Desired .ControlPlane .Object })
231
231
}
232
232
233
233
// If the ControlPlane has defined a current or desired MachineHealthCheck attempt to reconcile it.
@@ -242,7 +242,7 @@ func (r *Reconciler) reconcileControlPlane(ctx context.Context, s *scope.Scope)
242
242
243
243
// Reconcile the current and desired state of the MachineHealthCheck.
244
244
if err := r .reconcileMachineHealthCheck (ctx , s .Current .ControlPlane .MachineHealthCheck , s .Desired .ControlPlane .MachineHealthCheck ); err != nil {
245
- return errors . Wrapf ( err , "failed to update %s" , tlog. KObj { Obj : s . Desired . ControlPlane . MachineHealthCheck })
245
+ return err
246
246
}
247
247
}
248
248
return nil
@@ -403,21 +403,21 @@ func (r *Reconciler) createMachineDeployment(ctx context.Context, cluster *clust
403
403
cluster : cluster ,
404
404
desired : md .InfrastructureMachineTemplate ,
405
405
}); err != nil {
406
- return errors .Wrapf (err , "failed to create %s" , tlog. KObj { Obj : md .Object } )
406
+ return errors .Wrapf (err , "failed to create %s" , md .Object . Kind )
407
407
}
408
408
409
409
bootstrapCtx , _ := log .WithObject (md .BootstrapTemplate ).Into (ctx )
410
410
if err := r .reconcileReferencedTemplate (bootstrapCtx , reconcileReferencedTemplateInput {
411
411
cluster : cluster ,
412
412
desired : md .BootstrapTemplate ,
413
413
}); err != nil {
414
- return errors .Wrapf (err , "failed to create %s" , tlog. KObj { Obj : md .Object } )
414
+ return errors .Wrapf (err , "failed to create %s" , md .Object . Kind )
415
415
}
416
416
417
417
log = log .WithObject (md .Object )
418
418
log .Infof (fmt .Sprintf ("Creating %s" , tlog.KObj {Obj : md .Object }))
419
419
if err := r .Client .Create (ctx , md .Object .DeepCopy ()); err != nil {
420
- return errors . Wrapf (err , "failed to create %s" , tlog. KObj { Obj : md .Object } )
420
+ return createErrorWithoutObjectName (err , md .Object )
421
421
}
422
422
r .recorder .Eventf (cluster , corev1 .EventTypeNormal , createEventReason , "Created %q" , tlog.KObj {Obj : md .Object })
423
423
@@ -429,7 +429,7 @@ func (r *Reconciler) createMachineDeployment(ctx context.Context, cluster *clust
429
429
* ownerReferenceTo (md .Object ),
430
430
})
431
431
if err := r .reconcileMachineHealthCheck (ctx , nil , md .MachineHealthCheck ); err != nil {
432
- return errors . Wrapf ( err , "failed to create %s" , tlog. KObj { Obj : md . MachineHealthCheck })
432
+ return err
433
433
}
434
434
}
435
435
return nil
@@ -448,7 +448,7 @@ func (r *Reconciler) updateMachineDeployment(ctx context.Context, cluster *clust
448
448
templateNamePrefix : infrastructureMachineTemplateNamePrefix (cluster .Name , mdTopologyName ),
449
449
compatibilityChecker : check .ObjectsAreCompatible ,
450
450
}); err != nil {
451
- return errors .Wrapf (err , "failed to update %s" , tlog.KObj {Obj : currentMD .Object })
451
+ return errors .Wrapf (err , "failed to reconcile %s" , tlog.KObj {Obj : currentMD .Object })
452
452
}
453
453
454
454
bootstrapCtx , _ := log .WithObject (desiredMD .BootstrapTemplate ).Into (ctx )
@@ -460,13 +460,13 @@ func (r *Reconciler) updateMachineDeployment(ctx context.Context, cluster *clust
460
460
templateNamePrefix : bootstrapTemplateNamePrefix (cluster .Name , mdTopologyName ),
461
461
compatibilityChecker : check .ObjectsAreInTheSameNamespace ,
462
462
}); err != nil {
463
- return errors .Wrapf (err , "failed to update %s" , tlog.KObj {Obj : currentMD .Object })
463
+ return errors .Wrapf (err , "failed to reconcile %s" , tlog.KObj {Obj : currentMD .Object })
464
464
}
465
465
466
466
// Patch MachineHealthCheck for the MachineDeployment.
467
467
if desiredMD .MachineHealthCheck != nil || currentMD .MachineHealthCheck != nil {
468
468
if err := r .reconcileMachineHealthCheck (ctx , currentMD .MachineHealthCheck , desiredMD .MachineHealthCheck ); err != nil {
469
- return errors .Wrapf (err , "failed to update %s" , tlog.KObj {Obj : desiredMD .MachineHealthCheck })
469
+ return errors .Wrapf (err , "failed to reconcile %s" , tlog.KObj {Obj : desiredMD .MachineHealthCheck })
470
470
}
471
471
}
472
472
@@ -587,7 +587,7 @@ func (r *Reconciler) reconcileReferencedObject(ctx context.Context, in reconcile
587
587
return errors .Wrapf (err , "failed to create a copy of %s with the managed field annotation" , tlog.KObj {Obj : in .desired })
588
588
}
589
589
if err := r .Client .Create (ctx , desiredWithManagedFieldAnnotation ); err != nil {
590
- return errors . Wrapf (err , "failed to create %s" , tlog. KObj { Obj : desiredWithManagedFieldAnnotation } )
590
+ return createErrorWithoutObjectName (err , desiredWithManagedFieldAnnotation )
591
591
}
592
592
r .recorder .Eventf (in .cluster , corev1 .EventTypeNormal , createEventReason , "Created %q" , tlog.KObj {Obj : in .desired })
593
593
return nil
@@ -664,7 +664,7 @@ func (r *Reconciler) reconcileReferencedTemplate(ctx context.Context, in reconci
664
664
return errors .Wrapf (err , "failed to create a copy of %s with the managed field annotation" , tlog.KObj {Obj : in .desired })
665
665
}
666
666
if err := r .Client .Create (ctx , desiredWithManagedFieldAnnotation ); err != nil {
667
- return errors . Wrapf (err , "failed to create %s" , tlog. KObj { Obj : desiredWithManagedFieldAnnotation } )
667
+ return createErrorWithoutObjectName (err , desiredWithManagedFieldAnnotation )
668
668
}
669
669
r .recorder .Eventf (in .cluster , corev1 .EventTypeNormal , createEventReason , "Created %q" , tlog.KObj {Obj : in .desired })
670
670
return nil
@@ -716,7 +716,7 @@ func (r *Reconciler) reconcileReferencedTemplate(ctx context.Context, in reconci
716
716
return errors .Wrapf (err , "failed to create a copy of %s with the managed field annotation" , tlog.KObj {Obj : in .desired })
717
717
}
718
718
if err := r .Client .Create (ctx , desiredWithManagedFieldAnnotation ); err != nil {
719
- return errors . Wrapf (err , "failed to create %s" , tlog. KObj { Obj : desiredWithManagedFieldAnnotation } )
719
+ return createErrorWithoutObjectName (err , desiredWithManagedFieldAnnotation )
720
720
}
721
721
r .recorder .Eventf (in .cluster , corev1 .EventTypeNormal , createEventReason , "Created %q as a replacement for %q (template rotation)" , tlog.KObj {Obj : in .desired }, in .ref .Name )
722
722
@@ -727,3 +727,25 @@ func (r *Reconciler) reconcileReferencedTemplate(ctx context.Context, in reconci
727
727
728
728
return nil
729
729
}
730
+
731
+ // createErrorWithoutObjectName removes the name of the object from the error message. As each new Create call involves an
732
+ // object with a unique generated name each error appears to be a different error. As the errors are being surfaced in a condition
733
+ // on the Cluster, the name is removed here to prevent each creation error from triggering a new reconciliation.
734
+ func createErrorWithoutObjectName (err error , obj client.Object ) error {
735
+ var statusError * apierrors.StatusError
736
+ if errors .As (err , & statusError ) {
737
+ out := ""
738
+ if statusError .Status ().Details != nil {
739
+ for _ , cause := range statusError .Status ().Details .Causes {
740
+ out = fmt .Sprintf ("%s %s: %s: %s" , out , cause .Type , cause .Field , cause .Message )
741
+ }
742
+ out = fmt .Sprintf ("%s.%s: %s" , statusError .Status ().Details .Kind , statusError .Status ().Details .Group , out )
743
+ }
744
+
745
+ // Replace the statusError message with the constructed message.
746
+ statusError .ErrStatus .Message = fmt .Sprintf ("failed to create: %s" , out )
747
+ return statusError
748
+ }
749
+ // If this isn't a StatusError return a more generic error with the object details.
750
+ return errors .Wrapf (err , "failed to create %s" , tlog.KObj {Obj : obj })
751
+ }
0 commit comments