Skip to content

Commit

Permalink
remove disableMachineCreate annotation from old machinesets during ro…
Browse files Browse the repository at this point in the history
…lling machine deployment reconciliation
  • Loading branch information
Patryk-Stefanski committed Nov 13, 2024
1 parent c54a51b commit 05a906d
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package machinedeployment

import (
"context"
"sigs.k8s.io/cluster-api/util/patch"
"sort"

"github.com/pkg/errors"
Expand Down Expand Up @@ -116,6 +117,8 @@ func (r *Reconciler) reconcileOldMachineSets(ctx context.Context, allMSs []*clus
return nil
}

oldMSs, err := r.cleanupDisableMachineCreateAnnotation(ctx, oldMSs)

allMachinesCount := mdutil.GetReplicaCountForMachineSets(allMSs)
log.V(4).Info("New MachineSet has available machines",
"machineset", client.ObjectKeyFromObject(newMS).String(), "available-replicas", newMS.Status.AvailableReplicas)
Expand Down Expand Up @@ -293,3 +296,24 @@ func (r *Reconciler) scaleDownOldMachineSetsForRollingUpdate(ctx context.Context

return totalScaledDown, nil
}

// cleanupDisableMachineCreateAnnotation will remove the disable machine create annotation from old MachineSets that were created during reconcileOldMachineSetsOnDelete.
func (r *Reconciler) cleanupDisableMachineCreateAnnotation(ctx context.Context, oldMSs []*clusterv1.MachineSet) ([]*clusterv1.MachineSet, error) {
log := ctrl.LoggerFrom(ctx)

for _, targetMS := range oldMSs {
if _, ok := targetMS.Annotations[clusterv1.DisableMachineCreateAnnotation]; ok {
log.V(4).Info("removing disable machine create annotation from old MachineSet %s", targetMS.Name)
patchHelper, err := patch.NewHelper(targetMS, r.Client)
if err != nil {
return nil, err
}
delete(targetMS.Annotations, clusterv1.DisableMachineCreateAnnotation)
if err := patchHelper.Patch(ctx, targetMS); err != nil {
return nil, err
}
}
}

return oldMSs, nil
}

0 comments on commit 05a906d

Please sign in to comment.