From d89d6ea20257dfab491340d2ade224a7203537d7 Mon Sep 17 00:00:00 2001 From: goushicui Date: Fri, 20 Sep 2024 11:54:56 +0800 Subject: [PATCH 1/3] delete bootstrapRef when create infraRef failed --- internal/controllers/machineset/machineset_controller.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/controllers/machineset/machineset_controller.go b/internal/controllers/machineset/machineset_controller.go index 360616e58412..bd4779a83e11 100644 --- a/internal/controllers/machineset/machineset_controller.go +++ b/internal/controllers/machineset/machineset_controller.go @@ -541,6 +541,12 @@ func (r *Reconciler) syncReplicas(ctx context.Context, cluster *clusterv1.Cluste }, }) if err != nil { + // delete bootstrapRef after creat infraRef failed + if bootstrapRef != nil { + if err := r.Client.Delete(ctx, util.ObjectReferenceToUnstructured(*bootstrapRef)); !apierrors.IsNotFound(err) { + log.Error(err, "Failed to cleanup bootstrap configuration object after Machine creation error", bootstrapRef.Kind, klog.KRef(bootstrapRef.Namespace, bootstrapRef.Name)) + } + } conditions.MarkFalse(ms, clusterv1.MachinesCreatedCondition, clusterv1.InfrastructureTemplateCloningFailedReason, clusterv1.ConditionSeverityError, err.Error()) return ctrl.Result{}, errors.Wrapf(err, "failed to clone infrastructure machine from %s %s while creating a machine", ms.Spec.Template.Spec.InfrastructureRef.Kind, From 4882f933868c62e12f615f347faad7d3d1a99434 Mon Sep 17 00:00:00 2001 From: goushicui <38814264+goushicui@users.noreply.github.com> Date: Fri, 27 Sep 2024 15:06:06 +0800 Subject: [PATCH 2/3] Update internal/controllers/machineset/machineset_controller.go Co-authored-by: Vince Prignano --- internal/controllers/machineset/machineset_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/controllers/machineset/machineset_controller.go b/internal/controllers/machineset/machineset_controller.go index bd4779a83e11..7e38ea57e9cb 100644 --- a/internal/controllers/machineset/machineset_controller.go +++ b/internal/controllers/machineset/machineset_controller.go @@ -541,7 +541,7 @@ func (r *Reconciler) syncReplicas(ctx context.Context, cluster *clusterv1.Cluste }, }) if err != nil { - // delete bootstrapRef after creat infraRef failed + // Cleanup the bootstrap resource if we can't create the InfraMachine; or we might risk to leak it. if bootstrapRef != nil { if err := r.Client.Delete(ctx, util.ObjectReferenceToUnstructured(*bootstrapRef)); !apierrors.IsNotFound(err) { log.Error(err, "Failed to cleanup bootstrap configuration object after Machine creation error", bootstrapRef.Kind, klog.KRef(bootstrapRef.Namespace, bootstrapRef.Name)) From 2188c025458aed33c840a80e10c5f1d20b04f17b Mon Sep 17 00:00:00 2001 From: goushicui <38814264+goushicui@users.noreply.github.com> Date: Fri, 27 Sep 2024 15:06:42 +0800 Subject: [PATCH 3/3] Update internal/controllers/machineset/machineset_controller.go Co-authored-by: Vince Prignano --- internal/controllers/machineset/machineset_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/controllers/machineset/machineset_controller.go b/internal/controllers/machineset/machineset_controller.go index 7e38ea57e9cb..6870203b497f 100644 --- a/internal/controllers/machineset/machineset_controller.go +++ b/internal/controllers/machineset/machineset_controller.go @@ -543,7 +543,7 @@ func (r *Reconciler) syncReplicas(ctx context.Context, cluster *clusterv1.Cluste if err != nil { // Cleanup the bootstrap resource if we can't create the InfraMachine; or we might risk to leak it. if bootstrapRef != nil { - if err := r.Client.Delete(ctx, util.ObjectReferenceToUnstructured(*bootstrapRef)); !apierrors.IsNotFound(err) { + if err := r.Client.Delete(ctx, util.ObjectReferenceToUnstructured(*bootstrapRef)); err != nil && !apierrors.IsNotFound(err) { log.Error(err, "Failed to cleanup bootstrap configuration object after Machine creation error", bootstrapRef.Kind, klog.KRef(bootstrapRef.Namespace, bootstrapRef.Name)) } }