Skip to content

Commit d444496

Browse files
committed
machineset: set v1beta2 Paused condition
1 parent e6067ed commit d444496

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

internal/controllers/machineset/machineset_controller.go

+12-8
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import (
5555
"sigs.k8s.io/cluster-api/util/annotations"
5656
"sigs.k8s.io/cluster-api/util/collections"
5757
"sigs.k8s.io/cluster-api/util/conditions"
58+
v1beta2conditions "sigs.k8s.io/cluster-api/util/conditions/v1beta2"
5859
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
5960
"sigs.k8s.io/cluster-api/util/labels/format"
6061
clog "sigs.k8s.io/cluster-api/util/log"
@@ -116,14 +117,12 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
116117
handler.EnqueueRequestsFromMapFunc(r.MachineToMachineSets),
117118
).
118119
WithOptions(options).
119-
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(mgr.GetScheme(), predicateLog, r.WatchFilterValue)).
120120
Watches(
121121
&clusterv1.Cluster{},
122122
handler.EnqueueRequestsFromMapFunc(clusterToMachineSets),
123123
builder.WithPredicates(
124124
// TODO: should this wait for Cluster.Status.InfrastructureReady similar to Infra Machine resources?
125125
predicates.All(mgr.GetScheme(), predicateLog,
126-
predicates.ClusterUnpaused(mgr.GetScheme(), predicateLog),
127126
predicates.ResourceHasFilterLabel(mgr.GetScheme(), predicateLog, r.WatchFilterValue),
128127
),
129128
),
@@ -164,25 +163,27 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
164163
return ctrl.Result{}, err
165164
}
166165

167-
// Return early if the object or Cluster is paused.
168-
if annotations.IsPaused(cluster, machineSet) {
169-
log.Info("Reconciliation is paused for this object")
170-
return ctrl.Result{}, nil
171-
}
172-
173166
// Initialize the patch helper
174167
patchHelper, err := patch.NewHelper(machineSet, r.Client)
175168
if err != nil {
176169
return ctrl.Result{}, err
177170
}
178171

179172
defer func() {
173+
v1beta2conditions.SetPausedCondition(cluster, machineSet)
174+
180175
// Always attempt to patch the object and status after each reconciliation.
181176
if err := patchMachineSet(ctx, patchHelper, machineSet); err != nil {
182177
reterr = kerrors.NewAggregate([]error{reterr, err})
183178
}
184179
}()
185180

181+
// Return early if the object or Cluster is paused.
182+
if annotations.IsPaused(cluster, machineSet) {
183+
log.Info("Reconciliation is paused for this object")
184+
return ctrl.Result{}, nil
185+
}
186+
186187
// Handle deletion reconciliation loop.
187188
if !machineSet.DeletionTimestamp.IsZero() {
188189
return ctrl.Result{}, r.reconcileDelete(ctx, machineSet)
@@ -226,6 +227,9 @@ func patchMachineSet(ctx context.Context, patchHelper *patch.Helper, machineSet
226227
clusterv1.ResizedCondition,
227228
clusterv1.MachinesReadyCondition,
228229
}},
230+
patch.WithOwnedV1Beta2Conditions{Conditions: []string{
231+
clusterv1.MachineSetPausedV1Beta2Condition,
232+
}},
229233
)
230234
return patchHelper.Patch(ctx, machineSet, options...)
231235
}

0 commit comments

Comments
 (0)