From bd6d5448b15162aecfaf0b8a601fbced0ccc3c72 Mon Sep 17 00:00:00 2001 From: pstefans Date: Wed, 13 Nov 2024 10:42:32 +0000 Subject: [PATCH] remove disableMachineCreate annotation from new machinesets during rolling machine deployment reconciliation --- .../machinedeployment_rolling.go | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/internal/controllers/machinedeployment/machinedeployment_rolling.go b/internal/controllers/machinedeployment/machinedeployment_rolling.go index 31bd697d8b24..ebb00b87df0e 100644 --- a/internal/controllers/machinedeployment/machinedeployment_rolling.go +++ b/internal/controllers/machinedeployment/machinedeployment_rolling.go @@ -18,6 +18,7 @@ package machinedeployment import ( "context" + "sigs.k8s.io/cluster-api/util/patch" "sort" "github.com/pkg/errors" @@ -85,6 +86,11 @@ func (r *Reconciler) reconcileNewMachineSet(ctx context.Context, allMSs []*clust return nil } + newMS, err := r.cleanupDisableMachineCreateAnnotation(ctx, newMS) + if err != nil { + return err + } + if *(newMS.Spec.Replicas) > *(deployment.Spec.Replicas) { // Scale down. return r.scaleMachineSet(ctx, newMS, *(deployment.Spec.Replicas), deployment) @@ -293,3 +299,25 @@ func (r *Reconciler) scaleDownOldMachineSetsForRollingUpdate(ctx context.Context return totalScaledDown, nil } + +// cleanupDisableMachineCreateAnnotation will remove the disable machine create annotation from new MachineSets that were created during reconcileOldMachineSetsOnDelete. +func (r *Reconciler) cleanupDisableMachineCreateAnnotation(ctx context.Context, newMS *clusterv1.MachineSet) (*clusterv1.MachineSet, error) { + log := ctrl.LoggerFrom(ctx) + + if newMS.Annotations != nil { + if _, ok := newMS.Annotations[clusterv1.DisableMachineCreateAnnotation]; ok { + log.V(4).Info("removing annotation on latest MachineSet to enable machine creation") + patchHelper, err := patch.NewHelper(newMS, r.Client) + if err != nil { + return nil, err + } + delete(newMS.Annotations, clusterv1.DisableMachineCreateAnnotation) + err = patchHelper.Patch(ctx, newMS) + if err != nil { + return nil, err + } + } + } + + return newMS, nil +}