@@ -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,36 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.
243
240
}
244
241
}()
245
242
243
+ // Return early and set the paused condition to True if the object or Cluster
244
+ // is paused.
245
+ if annotations .IsPaused (cluster , kcp ) {
246
+ log .Info ("Reconciliation is paused for this object" )
247
+
248
+ newPausedCondition := & clusterv1.Condition {
249
+ Type : clusterv1 .PausedCondition ,
250
+ Status : corev1 .ConditionTrue ,
251
+ Severity : clusterv1 .ConditionSeverityInfo ,
252
+ }
253
+
254
+ if cluster .Spec .Paused {
255
+ newPausedCondition .Reason = clusterv1 .ClusterPausedReason
256
+ } else {
257
+ newPausedCondition .Reason = clusterv1 .AnnotationPausedReason
258
+ }
259
+
260
+ conditions .Set (kcp , newPausedCondition )
261
+ return ctrl.Result {}, nil
262
+ }
263
+ log .Info ("Object not paused" )
264
+ conditions .MarkFalseWithNegativePolarity (kcp , clusterv1 .PausedCondition )
265
+
266
+ if adoptableMachineFound {
267
+ // if there are no errors but at least one CP machine has been adopted, then requeue and
268
+ // wait for the update event for the ownership to be set.
269
+ log .Info ("Returning early, adoptableMachineFound" )
270
+ return ctrl.Result {}, nil
271
+ }
272
+
246
273
if ! kcp .ObjectMeta .DeletionTimestamp .IsZero () {
247
274
// Handle deletion reconciliation loop.
248
275
res , err = r .reconcileDelete (ctx , controlPlane )
@@ -325,19 +352,21 @@ func patchKubeadmControlPlane(ctx context.Context, patchHelper *patch.Helper, kc
325
352
)
326
353
327
354
// 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 ... )
355
+ return patchHelper .Patch (
356
+ ctx ,
357
+ kcp ,
358
+ patch.WithOwnedConditions {Conditions : []clusterv1.ConditionType {
359
+ controlplanev1 .MachinesCreatedCondition ,
360
+ clusterv1 .ReadyCondition ,
361
+ clusterv1 .PausedCondition ,
362
+ controlplanev1 .MachinesSpecUpToDateCondition ,
363
+ controlplanev1 .ResizedCondition ,
364
+ controlplanev1 .MachinesReadyCondition ,
365
+ controlplanev1 .AvailableCondition ,
366
+ controlplanev1 .CertificatesAvailableCondition ,
367
+ }},
368
+ patch.WithStatusObservedGeneration {},
369
+ )
341
370
}
342
371
343
372
// reconcile handles KubeadmControlPlane reconciliation.
0 commit comments