Skip to content

Commit 8ad3f83

Browse files
author
Rahul Ganesh
committed
Improve pause handling implementation on the controllers
Update pause handling in both cluster and machine controllers to pause further reconciliation when the capi cluster is paused. Signed-off-by: Rahul Ganesh <[email protected]>
1 parent a4ed73c commit 8ad3f83

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

controller/cluster/tinkerbellcluster.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,15 @@ func (tcr *TinkerbellClusterReconciler) Reconcile(ctx context.Context, req ctrl.
227227
return ctrl.Result{}, nil
228228
}
229229

230+
// TODO(enhancement): Currently using simple annotation-based pause checking. Need to implement
231+
// proper pause handling using paused.EnsurePausedCondition() as per:
232+
// https://cluster-api.sigs.k8s.io/developer/providers/contracts/infra-cluster#infracluster-pausing
233+
if annotations.IsPaused(crc.cluster, crc.tinkerbellCluster) {
234+
crc.log.Info("TinkerbellCluster is marked as paused. Won't reconcile")
235+
236+
return ctrl.Result{}, nil
237+
}
238+
230239
if !crc.tinkerbellCluster.ObjectMeta.DeletionTimestamp.IsZero() {
231240
if annotations.HasPaused(crc.tinkerbellCluster) {
232241
crc.log.Info("TinkerbellCluster is marked as paused. Won't reconcile deletion")
@@ -243,12 +252,6 @@ func (tcr *TinkerbellClusterReconciler) Reconcile(ctx context.Context, req ctrl.
243252
return ctrl.Result{}, nil
244253
}
245254

246-
if annotations.IsPaused(crc.cluster, crc.tinkerbellCluster) {
247-
crc.log.Info("TinkerbellCluster is marked as paused. Won't reconcile")
248-
249-
return ctrl.Result{}, nil
250-
}
251-
252255
return ctrl.Result{}, crc.reconcile()
253256
}
254257

controller/machine/tinkerbellmachine.go

+21-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
apierrors "k8s.io/apimachinery/pkg/api/errors"
2626
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2727
"sigs.k8s.io/cluster-api/util"
28+
"sigs.k8s.io/cluster-api/util/annotations"
2829
"sigs.k8s.io/cluster-api/util/collections"
2930
"sigs.k8s.io/cluster-api/util/patch"
3031
"sigs.k8s.io/cluster-api/util/predicates"
@@ -94,10 +95,6 @@ func (r *TinkerbellMachineReconciler) Reconcile(ctx context.Context, req ctrl.Re
9495

9596
scope.patchHelper = patchHelper
9697

97-
if scope.MachineScheduledForDeletion() {
98-
return ctrl.Result{}, scope.DeleteMachineWithDependencies()
99-
}
100-
10198
// We must be bound to a CAPI Machine object before we can continue.
10299
machine, err := scope.getReadyMachine()
103100
if err != nil {
@@ -108,6 +105,26 @@ func (r *TinkerbellMachineReconciler) Reconcile(ctx context.Context, req ctrl.Re
108105
return ctrl.Result{}, nil
109106
}
110107

108+
// Fetch the capi cluster owning the machine and check if the cluster is paused
109+
cluster, err := util.GetClusterFromMetadata(ctx, scope.client, machine.ObjectMeta)
110+
if err != nil {
111+
if !apierrors.IsNotFound(err) {
112+
return ctrl.Result{}, fmt.Errorf("getting owner cluster: %w", err)
113+
}
114+
}
115+
116+
// TODO(enhancement): Currently using simple annotation-based pause checking. Need to implement
117+
// proper pause handling using paused.EnsurePausedCondition() as per:
118+
// https://cluster-api.sigs.k8s.io/developer/providers/contracts/infra-cluster#infracluster-pausing
119+
if annotations.IsPaused(cluster, scope.tinkerbellMachine) {
120+
log.Info("TinkerbellMachine is paused, skipping reconciliation")
121+
return ctrl.Result{}, nil
122+
}
123+
124+
if scope.MachineScheduledForDeletion() {
125+
return ctrl.Result{}, scope.DeleteMachineWithDependencies()
126+
}
127+
111128
// We need a bootstrap cloud config secret to bootstrap the node so we can't proceed without it.
112129
// Typically, this is something akin to cloud-init user-data.
113130
bootstrapCloudConfig, err := scope.getReadyBootstrapCloudConfig(machine)

0 commit comments

Comments
 (0)