@@ -52,6 +52,7 @@ import (
52
52
"sigs.k8s.io/cluster-api/util/annotations"
53
53
"sigs.k8s.io/cluster-api/util/collections"
54
54
"sigs.k8s.io/cluster-api/util/conditions"
55
+ v1beta2conditions "sigs.k8s.io/cluster-api/util/conditions/v1beta2"
55
56
clog "sigs.k8s.io/cluster-api/util/log"
56
57
"sigs.k8s.io/cluster-api/util/patch"
57
58
"sigs.k8s.io/cluster-api/util/predicates"
@@ -120,15 +121,13 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
120
121
c , err := ctrl .NewControllerManagedBy (mgr ).
121
122
For (& clusterv1.Machine {}).
122
123
WithOptions (options ).
123
- WithEventFilter (predicates .ResourceNotPausedAndHasFilterLabel (mgr .GetScheme (), predicateLog , r .WatchFilterValue )).
124
124
Watches (
125
125
& clusterv1.Cluster {},
126
126
handler .EnqueueRequestsFromMapFunc (clusterToMachines ),
127
127
builder .WithPredicates (
128
128
// TODO: should this wait for Cluster.Status.InfrastructureReady similar to Infra Machine resources?
129
129
predicates .All (mgr .GetScheme (), predicateLog ,
130
130
predicates .Any (mgr .GetScheme (), predicateLog ,
131
- predicates .ClusterUnpaused (mgr .GetScheme (), predicateLog ),
132
131
predicates .ClusterControlPlaneInitialized (mgr .GetScheme (), predicateLog ),
133
132
),
134
133
predicates .ResourceHasFilterLabel (mgr .GetScheme (), predicateLog , r .WatchFilterValue ),
@@ -189,20 +188,16 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
189
188
m .Spec .ClusterName , m .Name , m .Namespace )
190
189
}
191
190
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
-
198
191
// Initialize the patch helper
199
192
patchHelper , err := patch .NewHelper (m , r .Client )
200
193
if err != nil {
201
194
return ctrl.Result {}, err
202
195
}
203
196
204
197
defer func () {
205
- r .reconcilePhase (ctx , m )
198
+ if isPaused := v1beta2conditions .SetPausedCondition (cluster , m ); ! isPaused {
199
+ r .reconcilePhase (ctx , m )
200
+ }
206
201
207
202
// Always attempt to patch the object and status after each reconciliation.
208
203
// Patch ObservedGeneration only if the reconciliation completed successfully
@@ -215,6 +210,12 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
215
210
}
216
211
}()
217
212
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
+
218
219
// Reconcile labels.
219
220
if m .Labels == nil {
220
221
m .Labels = make (map [string ]string )
@@ -285,6 +286,9 @@ func patchMachine(ctx context.Context, patchHelper *patch.Helper, machine *clust
285
286
clusterv1 .MachineHealthCheckSucceededCondition ,
286
287
clusterv1 .MachineOwnerRemediatedCondition ,
287
288
}},
289
+ patch.WithOwnedV1Beta2Conditions {Conditions : []string {
290
+ clusterv1 .MachinePausedV1Beta2Condition ,
291
+ }},
288
292
)
289
293
290
294
return patchHelper .Patch (ctx , machine , options ... )
0 commit comments