@@ -158,11 +158,6 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.
158
158
log = log .WithValues ("Cluster" , klog .KObj (cluster ))
159
159
ctx = ctrl .LoggerInto (ctx , log )
160
160
161
- if annotations .IsPaused (cluster , kcp ) {
162
- log .Info ("Reconciliation is paused for this object" )
163
- return ctrl.Result {}, nil
164
- }
165
-
166
161
// Initialize the patch helper.
167
162
patchHelper , err := patch .NewHelper (kcp , r .Client )
168
163
if err != nil {
@@ -178,27 +173,28 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.
178
173
// patch and return right away instead of reusing the main defer,
179
174
// because the main defer may take too much time to get cluster status
180
175
// Patch ObservedGeneration only if the reconciliation completed successfully
176
+
177
+ // TODO theobarberbany: Is this ordering correct, do we want finalizer to
178
+ // take priority over the paused condition?
181
179
patchOpts := []patch.Option {patch.WithStatusObservedGeneration {}}
182
180
if err := patchHelper .Patch (ctx , kcp , patchOpts ... ); err != nil {
183
181
return ctrl.Result {}, errors .Wrapf (err , "failed to add finalizer" )
184
182
}
185
-
183
+ log . Info ( "Returning early to add finalizer" )
186
184
return ctrl.Result {}, nil
187
185
}
188
186
189
187
// Initialize the control plane scope; this includes also checking for orphan machines and
190
188
// adopt them if necessary.
191
189
controlPlane , adoptableMachineFound , err := r .initControlPlaneScope (ctx , cluster , kcp )
192
190
if err != nil {
191
+ log .Error (err , "Failed to initControlPlaneScope" )
193
192
return ctrl.Result {}, err
194
193
}
195
- if adoptableMachineFound {
196
- // if there are no errors but at least one CP machine has been adopted, then requeue and
197
- // wait for the update event for the ownership to be set.
198
- return ctrl.Result {}, nil
199
- }
194
+ log .Info ("initControlPlaneScope" )
200
195
201
196
defer func () {
197
+ log .Info ("start of deferred update status" )
202
198
// Always attempt to update status.
203
199
if err := r .updateStatus (ctx , controlPlane ); err != nil {
204
200
var connFailure * internal.RemoteClusterConnectionError
@@ -215,6 +211,7 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.
215
211
log .Error (err , "Failed to patch KubeadmControlPlane" )
216
212
reterr = kerrors .NewAggregate ([]error {reterr , err })
217
213
}
214
+ log .Info ("patched KubeadmControlPlane" )
218
215
219
216
// Only requeue if there is no error, Requeue or RequeueAfter and the object does not have a deletion timestamp.
220
217
if reterr == nil && res .IsZero () && kcp .ObjectMeta .DeletionTimestamp .IsZero () {
@@ -236,6 +233,21 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.
236
233
}
237
234
}()
238
235
236
+ if annotations .IsPaused (cluster , kcp ) {
237
+ log .Info ("Reconciliation is paused for this object" )
238
+ conditions .MarkTrue (kcp , clusterv1 .PausedCondition )
239
+ return ctrl.Result {}, nil
240
+ }
241
+ log .Info ("Object not paused" )
242
+ conditions .MarkFalse (kcp , clusterv1 .PausedCondition , clusterv1 .ResourceNotPausedReason , clusterv1 .ConditionSeverityInfo , "Resource is operating as expected" )
243
+
244
+ if adoptableMachineFound {
245
+ // if there are no errors but at least one CP machine has been adopted, then requeue and
246
+ // wait for the update event for the ownership to be set.
247
+ log .Info ("Returning early, adoptableMachineFound" )
248
+ return ctrl.Result {}, nil
249
+ }
250
+
239
251
if ! kcp .ObjectMeta .DeletionTimestamp .IsZero () {
240
252
// Handle deletion reconciliation loop.
241
253
res , err = r .reconcileDelete (ctx , controlPlane )
@@ -324,6 +336,7 @@ func patchKubeadmControlPlane(ctx context.Context, patchHelper *patch.Helper, kc
324
336
patch.WithOwnedConditions {Conditions : []clusterv1.ConditionType {
325
337
controlplanev1 .MachinesCreatedCondition ,
326
338
clusterv1 .ReadyCondition ,
339
+ clusterv1 .PausedCondition ,
327
340
controlplanev1 .MachinesSpecUpToDateCondition ,
328
341
controlplanev1 .ResizedCondition ,
329
342
controlplanev1 .MachinesReadyCondition ,
0 commit comments