Skip to content

Commit

Permalink
remove disableMachineCreate annotation from new 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 b7f875b
Showing 1 changed file with 25 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 @@ -85,6 +86,8 @@ func (r *Reconciler) reconcileNewMachineSet(ctx context.Context, allMSs []*clust
return nil
}

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

Check failure on line 89 in internal/controllers/machinedeployment/machinedeployment_rolling.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to err (ineffassign)

Check failure on line 89 in internal/controllers/machinedeployment/machinedeployment_rolling.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to err (ineffassign)

if *(newMS.Spec.Replicas) > *(deployment.Spec.Replicas) {
// Scale down.
return r.scaleMachineSet(ctx, newMS, *(deployment.Spec.Replicas), deployment)
Expand Down Expand Up @@ -293,3 +296,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
}

0 comments on commit b7f875b

Please sign in to comment.