@@ -49,7 +49,6 @@ import (
49
49
"sigs.k8s.io/cluster-api/util/collections"
50
50
"sigs.k8s.io/cluster-api/util/conditions"
51
51
"sigs.k8s.io/cluster-api/util/patch"
52
- "sigs.k8s.io/cluster-api/util/predicates"
53
52
)
54
53
55
54
const (
@@ -80,15 +79,13 @@ type Reconciler struct {
80
79
}
81
80
82
81
func (r * Reconciler ) SetupWithManager (ctx context.Context , mgr ctrl.Manager , options controller.Options ) error {
83
- predicateLog := ctrl .LoggerFrom (ctx ).WithValues ("controller" , "cluster" )
84
82
c , err := ctrl .NewControllerManagedBy (mgr ).
85
83
For (& clusterv1.Cluster {}).
86
84
Watches (
87
85
& clusterv1.Machine {},
88
86
handler .EnqueueRequestsFromMapFunc (r .controlPlaneMachineToCluster ),
89
87
).
90
88
WithOptions (options ).
91
- WithEventFilter (predicates .ResourceNotPausedAndHasFilterLabel (mgr .GetScheme (), predicateLog , r .WatchFilterValue )).
92
89
Build (r )
93
90
94
91
if err != nil {
@@ -120,21 +117,17 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
120
117
return ctrl.Result {}, err
121
118
}
122
119
123
- // Return early if the object or Cluster is paused.
124
- if annotations .IsPaused (cluster , cluster ) {
125
- log .Info ("Reconciliation is paused for this object" )
126
- return ctrl.Result {}, nil
127
- }
128
-
129
120
// Initialize the patch helper.
130
121
patchHelper , err := patch .NewHelper (cluster , r .Client )
131
122
if err != nil {
132
123
return ctrl.Result {}, err
133
124
}
134
125
135
126
defer func () {
136
- // Always reconcile the Status.Phase field.
137
- r .reconcilePhase (ctx , cluster )
127
+ if isPaused := v1beta2conditions .SetPausedCondition (cluster , cluster ); ! isPaused {
128
+ // Always reconcile the Status.Phase field.
129
+ r .reconcilePhase (ctx , cluster )
130
+ }
138
131
139
132
// Always attempt to Patch the Cluster object and status after each reconciliation.
140
133
// Patch ObservedGeneration only if the reconciliation completed successfully
@@ -147,6 +140,12 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
147
140
}
148
141
}()
149
142
143
+ // Return early if the object or Cluster is paused.
144
+ if annotations .IsPaused (cluster , cluster ) {
145
+ log .Info ("Reconciliation is paused for this object" )
146
+ return ctrl.Result {}, nil
147
+ }
148
+
150
149
// Handle deletion reconciliation loop.
151
150
if ! cluster .ObjectMeta .DeletionTimestamp .IsZero () {
152
151
return r .reconcileDelete (ctx , cluster )
@@ -181,6 +180,9 @@ func patchCluster(ctx context.Context, patchHelper *patch.Helper, cluster *clust
181
180
clusterv1 .ControlPlaneReadyCondition ,
182
181
clusterv1 .InfrastructureReadyCondition ,
183
182
}},
183
+ patch.WithOwnedV1Beta2Conditions {Conditions : []string {
184
+ clusterv1 .MachinePausedV1Beta2Condition ,
185
+ }},
184
186
)
185
187
return patchHelper .Patch (ctx , cluster , options ... )
186
188
}
0 commit comments