@@ -161,11 +161,6 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.
161
161
log = log .WithValues ("Cluster" , klog .KObj (cluster ))
162
162
ctx = ctrl .LoggerInto (ctx , log )
163
163
164
- if annotations .IsPaused (cluster , kcp ) {
165
- log .Info ("Reconciliation is paused for this object" )
166
- return ctrl.Result {}, nil
167
- }
168
-
169
164
// Initialize the patch helper.
170
165
patchHelper , err := patch .NewHelper (kcp , r .Client )
171
166
if err != nil {
@@ -181,27 +176,28 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.
181
176
// patch and return right away instead of reusing the main defer,
182
177
// because the main defer may take too much time to get cluster status
183
178
// Patch ObservedGeneration only if the reconciliation completed successfully
179
+
180
+ // TODO theobarberbany: Is this ordering correct, do we want finalizer to
181
+ // take priority over the paused condition?
184
182
patchOpts := []patch.Option {patch.WithStatusObservedGeneration {}}
185
183
if err := patchHelper .Patch (ctx , kcp , patchOpts ... ); err != nil {
186
184
return ctrl.Result {}, errors .Wrapf (err , "failed to add finalizer" )
187
185
}
188
-
186
+ log . Info ( "Returning early to add finalizer" )
189
187
return ctrl.Result {}, nil
190
188
}
191
189
192
190
// Initialize the control plane scope; this includes also checking for orphan machines and
193
191
// adopt them if necessary.
194
192
controlPlane , adoptableMachineFound , err := r .initControlPlaneScope (ctx , cluster , kcp )
195
193
if err != nil {
194
+ log .Error (err , "Failed to initControlPlaneScope" )
196
195
return ctrl.Result {}, err
197
196
}
198
- if adoptableMachineFound {
199
- // if there are no errors but at least one CP machine has been adopted, then requeue and
200
- // wait for the update event for the ownership to be set.
201
- return ctrl.Result {}, nil
202
- }
197
+ log .Info ("initControlPlaneScope" )
203
198
204
199
defer func () {
200
+ log .Info ("start of deferred update status" )
205
201
// Always attempt to update status.
206
202
if err := r .updateStatus (ctx , controlPlane ); err != nil {
207
203
var connFailure * internal.RemoteClusterConnectionError
@@ -222,6 +218,7 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.
222
218
log .Error (err , "Failed to patch KubeadmControlPlane" )
223
219
reterr = kerrors .NewAggregate ([]error {reterr , err })
224
220
}
221
+ log .Info ("patched KubeadmControlPlane" )
225
222
226
223
// Only requeue if there is no error, Requeue or RequeueAfter and the object does not have a deletion timestamp.
227
224
if reterr == nil && res .IsZero () && kcp .ObjectMeta .DeletionTimestamp .IsZero () {
@@ -243,6 +240,21 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.
243
240
}
244
241
}()
245
242
243
+ if annotations .IsPaused (cluster , kcp ) {
244
+ log .Info ("Reconciliation is paused for this object" )
245
+ conditions .MarkTrue (kcp , clusterv1 .PausedCondition )
246
+ return ctrl.Result {}, nil
247
+ }
248
+ log .Info ("Object not paused" )
249
+ conditions .MarkFalse (kcp , clusterv1 .PausedCondition , clusterv1 .ResourceNotPausedReason , clusterv1 .ConditionSeverityInfo , "Resource is operating as expected" )
250
+
251
+ if adoptableMachineFound {
252
+ // if there are no errors but at least one CP machine has been adopted, then requeue and
253
+ // wait for the update event for the ownership to be set.
254
+ log .Info ("Returning early, adoptableMachineFound" )
255
+ return ctrl.Result {}, nil
256
+ }
257
+
246
258
if ! kcp .ObjectMeta .DeletionTimestamp .IsZero () {
247
259
// Handle deletion reconciliation loop.
248
260
res , err = r .reconcileDelete (ctx , controlPlane )
@@ -325,19 +337,21 @@ func patchKubeadmControlPlane(ctx context.Context, patchHelper *patch.Helper, kc
325
337
)
326
338
327
339
// Patch the object, ignoring conflicts on the conditions owned by this controller.
328
- // Also, if requested, we are adding additional options like e.g. Patch ObservedGeneration when issuing the
329
- // patch at the end of the reconcile loop.
330
- options = append (options , patch.WithOwnedConditions {Conditions : []clusterv1.ConditionType {
331
- controlplanev1 .MachinesCreatedCondition ,
332
- clusterv1 .ReadyCondition ,
333
- controlplanev1 .MachinesSpecUpToDateCondition ,
334
- controlplanev1 .ResizedCondition ,
335
- controlplanev1 .MachinesReadyCondition ,
336
- controlplanev1 .AvailableCondition ,
337
- controlplanev1 .CertificatesAvailableCondition ,
338
- }})
339
-
340
- return patchHelper .Patch (ctx , kcp , options ... )
340
+ return patchHelper .Patch (
341
+ ctx ,
342
+ kcp ,
343
+ patch.WithOwnedConditions {Conditions : []clusterv1.ConditionType {
344
+ controlplanev1 .MachinesCreatedCondition ,
345
+ clusterv1 .ReadyCondition ,
346
+ clusterv1 .PausedCondition ,
347
+ controlplanev1 .MachinesSpecUpToDateCondition ,
348
+ controlplanev1 .ResizedCondition ,
349
+ controlplanev1 .MachinesReadyCondition ,
350
+ controlplanev1 .AvailableCondition ,
351
+ controlplanev1 .CertificatesAvailableCondition ,
352
+ }},
353
+ patch.WithStatusObservedGeneration {},
354
+ )
341
355
}
342
356
343
357
// reconcile handles KubeadmControlPlane reconciliation.
0 commit comments