Skip to content

Commit 3624ef3

Browse files
Implements paused condition for kubeadm kcp
1 parent a54f49d commit 3624ef3

File tree

2 files changed

+154
-11
lines changed

2 files changed

+154
-11
lines changed

controlplane/kubeadm/internal/controllers/controller.go

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,6 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.
158158
log = log.WithValues("Cluster", klog.KObj(cluster))
159159
ctx = ctrl.LoggerInto(ctx, log)
160160

161-
if annotations.IsPaused(cluster, kcp) {
162-
log.Info("Reconciliation is paused for this object")
163-
return ctrl.Result{}, nil
164-
}
165-
166161
// Initialize the patch helper.
167162
patchHelper, err := patch.NewHelper(kcp, r.Client)
168163
if err != nil {
@@ -178,27 +173,28 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.
178173
// patch and return right away instead of reusing the main defer,
179174
// because the main defer may take too much time to get cluster status
180175
// 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?
181179
patchOpts := []patch.Option{patch.WithStatusObservedGeneration{}}
182180
if err := patchHelper.Patch(ctx, kcp, patchOpts...); err != nil {
183181
return ctrl.Result{}, errors.Wrapf(err, "failed to add finalizer")
184182
}
185-
183+
log.Info("Returning early to add finalizer")
186184
return ctrl.Result{}, nil
187185
}
188186

189187
// Initialize the control plane scope; this includes also checking for orphan machines and
190188
// adopt them if necessary.
191189
controlPlane, adoptableMachineFound, err := r.initControlPlaneScope(ctx, cluster, kcp)
192190
if err != nil {
191+
log.Error(err, "Failed to initControlPlaneScope")
193192
return ctrl.Result{}, err
194193
}
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")
200195

201196
defer func() {
197+
log.Info("start of deferred update status")
202198
// Always attempt to update status.
203199
if err := r.updateStatus(ctx, controlPlane); err != nil {
204200
var connFailure *internal.RemoteClusterConnectionError
@@ -215,6 +211,7 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.
215211
log.Error(err, "Failed to patch KubeadmControlPlane")
216212
reterr = kerrors.NewAggregate([]error{reterr, err})
217213
}
214+
log.Info("patched KubeadmControlPlane")
218215

219216
// Only requeue if there is no error, Requeue or RequeueAfter and the object does not have a deletion timestamp.
220217
if reterr == nil && res.IsZero() && kcp.ObjectMeta.DeletionTimestamp.IsZero() {
@@ -236,6 +233,21 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.
236233
}
237234
}()
238235

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+
239251
if !kcp.ObjectMeta.DeletionTimestamp.IsZero() {
240252
// Handle deletion reconciliation loop.
241253
res, err = r.reconcileDelete(ctx, controlPlane)
@@ -324,6 +336,7 @@ func patchKubeadmControlPlane(ctx context.Context, patchHelper *patch.Helper, kc
324336
patch.WithOwnedConditions{Conditions: []clusterv1.ConditionType{
325337
controlplanev1.MachinesCreatedCondition,
326338
clusterv1.ReadyCondition,
339+
clusterv1.PausedCondition,
327340
controlplanev1.MachinesSpecUpToDateCondition,
328341
controlplanev1.ResizedCondition,
329342
controlplanev1.MachinesReadyCondition,

0 commit comments

Comments
 (0)