Skip to content

Commit a40e4de

Browse files
committed
machine: set v1beta2 Paused condition
1 parent d444496 commit a40e4de

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

internal/controllers/machine/machine_controller.go

+13-9
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import (
5252
"sigs.k8s.io/cluster-api/util/annotations"
5353
"sigs.k8s.io/cluster-api/util/collections"
5454
"sigs.k8s.io/cluster-api/util/conditions"
55+
v1beta2conditions "sigs.k8s.io/cluster-api/util/conditions/v1beta2"
5556
clog "sigs.k8s.io/cluster-api/util/log"
5657
"sigs.k8s.io/cluster-api/util/patch"
5758
"sigs.k8s.io/cluster-api/util/predicates"
@@ -120,15 +121,13 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
120121
c, err := ctrl.NewControllerManagedBy(mgr).
121122
For(&clusterv1.Machine{}).
122123
WithOptions(options).
123-
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(mgr.GetScheme(), predicateLog, r.WatchFilterValue)).
124124
Watches(
125125
&clusterv1.Cluster{},
126126
handler.EnqueueRequestsFromMapFunc(clusterToMachines),
127127
builder.WithPredicates(
128128
// TODO: should this wait for Cluster.Status.InfrastructureReady similar to Infra Machine resources?
129129
predicates.All(mgr.GetScheme(), predicateLog,
130130
predicates.Any(mgr.GetScheme(), predicateLog,
131-
predicates.ClusterUnpaused(mgr.GetScheme(), predicateLog),
132131
predicates.ClusterControlPlaneInitialized(mgr.GetScheme(), predicateLog),
133132
),
134133
predicates.ResourceHasFilterLabel(mgr.GetScheme(), predicateLog, r.WatchFilterValue),
@@ -189,20 +188,16 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
189188
m.Spec.ClusterName, m.Name, m.Namespace)
190189
}
191190

192-
// Return early if the object or Cluster is paused.
193-
if annotations.IsPaused(cluster, m) {
194-
log.Info("Reconciliation is paused for this object")
195-
return ctrl.Result{}, nil
196-
}
197-
198191
// Initialize the patch helper
199192
patchHelper, err := patch.NewHelper(m, r.Client)
200193
if err != nil {
201194
return ctrl.Result{}, err
202195
}
203196

204197
defer func() {
205-
r.reconcilePhase(ctx, m)
198+
if isPaused := v1beta2conditions.SetPausedCondition(cluster, m); !isPaused {
199+
r.reconcilePhase(ctx, m)
200+
}
206201

207202
// Always attempt to patch the object and status after each reconciliation.
208203
// Patch ObservedGeneration only if the reconciliation completed successfully
@@ -215,6 +210,12 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
215210
}
216211
}()
217212

213+
// Return early if the object or Cluster is paused.
214+
if annotations.IsPaused(cluster, m) {
215+
log.Info("Reconciliation is paused for this object")
216+
return ctrl.Result{}, nil
217+
}
218+
218219
// Reconcile labels.
219220
if m.Labels == nil {
220221
m.Labels = make(map[string]string)
@@ -285,6 +286,9 @@ func patchMachine(ctx context.Context, patchHelper *patch.Helper, machine *clust
285286
clusterv1.MachineHealthCheckSucceededCondition,
286287
clusterv1.MachineOwnerRemediatedCondition,
287288
}},
289+
patch.WithOwnedV1Beta2Conditions{Conditions: []string{
290+
clusterv1.MachinePausedV1Beta2Condition,
291+
}},
288292
)
289293

290294
return patchHelper.Patch(ctx, machine, options...)

0 commit comments

Comments
 (0)