Skip to content

fix pause handling implementation on the controllers #460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions controller/cluster/tinkerbellcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ func (tcr *TinkerbellClusterReconciler) Reconcile(ctx context.Context, req ctrl.
return ctrl.Result{}, nil
}

// TODO(enhancement): Currently using simple annotation-based pause checking. Need to implement
// proper pause handling using paused.EnsurePausedCondition() as per:
// https://cluster-api.sigs.k8s.io/developer/providers/contracts/infra-cluster#infracluster-pausing
if annotations.IsPaused(crc.cluster, crc.tinkerbellCluster) {
crc.log.Info("TinkerbellCluster is marked as paused. Won't reconcile")

Expand Down
26 changes: 22 additions & 4 deletions controller/machine/tinkerbellmachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/cluster-api/util/annotations"
"sigs.k8s.io/cluster-api/util/collections"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/cluster-api/util/predicates"
Expand Down Expand Up @@ -94,10 +95,6 @@ func (r *TinkerbellMachineReconciler) Reconcile(ctx context.Context, req ctrl.Re

scope.patchHelper = patchHelper

if scope.MachineScheduledForDeletion() {
return ctrl.Result{}, scope.DeleteMachineWithDependencies()
}

// We must be bound to a CAPI Machine object before we can continue.
machine, err := scope.getReadyMachine()
if err != nil {
Expand All @@ -108,6 +105,27 @@ func (r *TinkerbellMachineReconciler) Reconcile(ctx context.Context, req ctrl.Re
return ctrl.Result{}, nil
}

// Fetch the capi cluster owning the machine and check if the cluster is paused
cluster, err := util.GetClusterFromMetadata(ctx, scope.client, machine.ObjectMeta)
if err != nil {
if !apierrors.IsNotFound(err) {
return ctrl.Result{}, fmt.Errorf("getting cluster from metadata:: %w", err)
}
}

// TODO(enhancement): Currently using simple annotation-based pause checking. Need to implement
// proper pause handling using paused.EnsurePausedCondition() as per:
// https://cluster-api.sigs.k8s.io/developer/providers/contracts/infra-cluster#infracluster-pausing
if cluster != nil && annotations.IsPaused(cluster, scope.tinkerbellMachine) {
log.Info("TinkerbellMachine is paused, skipping reconciliation")

return ctrl.Result{}, nil
}

if scope.MachineScheduledForDeletion() {
return ctrl.Result{}, scope.DeleteMachineWithDependencies()
}

// We need a bootstrap cloud config secret to bootstrap the node so we can't proceed without it.
// Typically, this is something akin to cloud-init user-data.
bootstrapCloudConfig, err := scope.getReadyBootstrapCloudConfig(machine)
Expand Down