Skip to content

✨ migrate Requeue to RequeueAfter #12308

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 0 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,6 @@ linters:
- linters:
- staticcheck
text: 'SA1019: .*\.Deprecated\.V1Beta1.* is deprecated'
# CR v0.21 deprecated Result.Requeue, will be fixed incrementally and tracked via https://github.com/kubernetes-sigs/cluster-api/issues/12272
- linters:
- staticcheck
text: 'SA1019: .*(res|result|i|j)\.Requeue is deprecated: Use `RequeueAfter` instead'
- linters:
- revive
text: 'exported: exported method .*\.(Reconcile|SetupWithManager|SetupWebhookWithManager) should have comment or be unexported'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package controllers

import (
"testing"
"time"

. "github.com/onsi/gomega"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -58,7 +59,7 @@ func TestKubeadmConfigReconciler(t *testing.T) {
},
})
g.Expect(err).To(Succeed())
g.Expect(result.Requeue).To(BeFalse())
g.Expect(result.RequeueAfter).To(Equal(time.Duration(0)))
})
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ func TestKubeadmConfigReconciler_Reconcile_ReturnEarlyIfKubeadmConfigIsReady(t *
}
result, err := k.Reconcile(ctx, request)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(result.Requeue).To(BeFalse())
g.Expect(result.RequeueAfter).To(Equal(time.Duration(0)))
}

Expand Down Expand Up @@ -297,7 +296,6 @@ func TestKubeadmConfigReconciler_Reconcile_ReturnEarlyIfMachineHasDataSecretName
actual := &bootstrapv1.KubeadmConfig{}
g.Expect(myclient.Get(ctx, client.ObjectKey{Namespace: config.Namespace, Name: config.Name}, actual)).To(Succeed())
g.Expect(err).ToNot(HaveOccurred())
g.Expect(result.Requeue).To(BeFalse())
g.Expect(result.RequeueAfter).To(Equal(time.Duration(0)))
assertHasTrueCondition(g, myclient, request, bootstrapv1.KubeadmConfigDataSecretAvailableCondition)
}
Expand Down Expand Up @@ -470,7 +468,6 @@ func TestKubeadmConfigReconciler_Reconcile_RequeueJoiningNodesIfControlPlaneNotI

result, err := k.Reconcile(ctx, tc.request)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(result.Requeue).To(BeFalse())
g.Expect(result.RequeueAfter).To(Equal(30 * time.Second))
assertHasFalseCondition(g, myclient, tc.request, bootstrapv1.KubeadmConfigDataSecretAvailableCondition, bootstrapv1.KubeadmConfigDataSecretNotAvailableReason)
})
Expand Down Expand Up @@ -523,7 +520,6 @@ func TestKubeadmConfigReconciler_Reconcile_GenerateCloudConfigData(t *testing.T)

result, err := k.Reconcile(ctx, request)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(result.Requeue).To(BeFalse())
g.Expect(result.RequeueAfter).To(Equal(time.Duration(0)))

cfg, err := getKubeadmConfig(myclient, "control-plane-init-cfg", metav1.NamespaceDefault)
Expand Down Expand Up @@ -627,7 +623,6 @@ func TestKubeadmConfigReconciler_Reconcile_RequeueIfControlPlaneIsMissingAPIEndp
}
result, err := k.Reconcile(ctx, request)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(result.Requeue).To(BeFalse())
g.Expect(result.RequeueAfter).To(Equal(10 * time.Second))

actualConfig := &bootstrapv1.KubeadmConfig{}
Expand Down Expand Up @@ -705,7 +700,6 @@ func TestReconcileIfJoinCertificatesAvailableConditioninNodesAndControlPlaneIsRe
}
result, err := k.Reconcile(ctx, request)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(result.Requeue).To(BeFalse())
g.Expect(result.RequeueAfter).To(Equal(time.Duration(0)))

cfg, err := getKubeadmConfig(myclient, rt.configName, metav1.NamespaceDefault)
Expand Down Expand Up @@ -783,7 +777,6 @@ func TestReconcileIfJoinNodePoolsAndControlPlaneIsReady(t *testing.T) {
}
result, err := k.Reconcile(ctx, request)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(result.Requeue).To(BeFalse())
g.Expect(result.RequeueAfter).To(Equal(time.Duration(0)))

cfg, err := getKubeadmConfig(myclient, rt.configName, metav1.NamespaceDefault)
Expand Down Expand Up @@ -991,7 +984,6 @@ func TestKubeadmConfigSecretCreatedStatusNotPatched(t *testing.T) {
g.Expect(err).ToNot(HaveOccurred())
result, err := k.Reconcile(ctx, request)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(result.Requeue).To(BeFalse())
g.Expect(result.RequeueAfter).To(Equal(time.Duration(0)))

cfg, err := getKubeadmConfig(myclient, "worker-join-cfg", metav1.NamespaceDefault)
Expand Down Expand Up @@ -1245,7 +1237,6 @@ func TestBootstrapTokenTTLExtension(t *testing.T) {
} {
result, err := k.Reconcile(ctx, req)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(result.Requeue).To(BeFalse())
g.Expect(result.RequeueAfter).To(Equal(time.Duration(0)))
}

Expand Down Expand Up @@ -2096,7 +2087,6 @@ func TestKubeadmConfigReconciler_Reconcile_ExactlyOneControlPlaneMachineInitiali
}
result, err := k.Reconcile(ctx, request)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(result.Requeue).To(BeFalse())
g.Expect(result.RequeueAfter).To(Equal(time.Duration(0)))

request = ctrl.Request{
Expand All @@ -2107,7 +2097,6 @@ func TestKubeadmConfigReconciler_Reconcile_ExactlyOneControlPlaneMachineInitiali
}
result, err = k.Reconcile(ctx, request)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(result.Requeue).To(BeFalse())
g.Expect(result.RequeueAfter).To(Equal(30 * time.Second))
confList := &bootstrapv1.KubeadmConfigList{}
g.Expect(myclient.List(ctx, confList)).To(Succeed())
Expand Down Expand Up @@ -2164,7 +2153,6 @@ func TestKubeadmConfigReconciler_Reconcile_PatchWhenErrorOccurred(t *testing.T)

result, err := k.Reconcile(ctx, request)
g.Expect(err).To(HaveOccurred())
g.Expect(result.Requeue).To(BeFalse())
g.Expect(result.RequeueAfter).To(Equal(time.Duration(0)))

cfg, err := getKubeadmConfig(myclient, "control-plane-init-cfg", metav1.NamespaceDefault)
Expand Down
6 changes: 6 additions & 0 deletions controlplane/kubeadm/internal/controllers/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ const (
// dependentCertRequeueAfter is how long to wait before checking again to see if
// dependent certificates have been created.
dependentCertRequeueAfter = 30 * time.Second

// scaleRequeueAfter is how long to wait before scaling up/down again after a scale operation has been requested.
scaleRequeueAfter = 15 * time.Second

// initializationRequeueAfter is how long to wait before checking again to see if the initialization has been completed.
initializationRequeueAfter = 15 * time.Second
)
6 changes: 2 additions & 4 deletions controlplane/kubeadm/internal/controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.
// Initialize the patch helper.
patchHelper, err := patch.NewHelper(kcp, r.Client)
if err != nil {
log.Error(err, "Failed to configure the patch helper")
return ctrl.Result{Requeue: true}, nil
return ctrl.Result{}, errors.Wrap(err, "failed to configure the patch helper")
}

if isPaused, requeue, err := paused.EnsurePausedCondition(ctx, r.Client, cluster, kcp); err != nil || isPaused || requeue {
Expand Down Expand Up @@ -503,8 +502,7 @@ func (r *KubeadmControlPlaneReconciler) reconcile(ctx context.Context, controlPl
// Get the workload cluster client.
workloadCluster, err := controlPlane.GetWorkloadCluster(ctx)
if err != nil {
log.V(2).Info("cannot get remote client to workload cluster, will requeue", "cause", err)
return ctrl.Result{Requeue: true}, nil
return ctrl.Result{}, errors.Wrapf(err, "cannot get remote client to workload cluster for KubeadmControlPlane %s/%s", controlPlane.KCP.Namespace, controlPlane.KCP.Name)
}

// Update kube-proxy daemonset.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ func TestReconcileClusterNoEndpoints(t *testing.T) {
result, err = r.Reconcile(ctx, ctrl.Request{NamespacedName: util.ObjectKey(kcp)})
g.Expect(err).ToNot(HaveOccurred())
// TODO: this should stop to re-queue as soon as we have a proper remote cluster cache in place.
g.Expect(result).To(BeComparableTo(ctrl.Result{Requeue: false, RequeueAfter: 20 * time.Second}))
g.Expect(result).To(BeComparableTo(ctrl.Result{RequeueAfter: 20 * time.Second}))
g.Expect(r.Client.Get(ctx, util.ObjectKey(kcp), kcp)).To(Succeed())

// Always expect that the Finalizer is set on the passed in resource
Expand Down
2 changes: 1 addition & 1 deletion controlplane/kubeadm/internal/controllers/remediation.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ func (r *KubeadmControlPlaneReconciler) reconcileUnhealthyMachines(ctx context.C
controlplanev1.RemediationInProgressAnnotation: remediationInProgressValue,
})

return ctrl.Result{Requeue: true}, nil
return ctrl.Result{RequeueAfter: time.Second * 20}, nil
}

// Gets the machine to be remediated, which is the "most broken" among the unhealthy machines, determined as the machine
Expand Down
6 changes: 3 additions & 3 deletions controlplane/kubeadm/internal/controllers/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (r *KubeadmControlPlaneReconciler) initializeControlPlane(ctx context.Conte
newMachine.Spec.Bootstrap.ConfigRef.Kind, klog.KRef(newMachine.Spec.Bootstrap.ConfigRef.Namespace, newMachine.Spec.Bootstrap.ConfigRef.Name))

// Requeue the control plane, in case there are additional operations to perform
return ctrl.Result{Requeue: true}, nil
return ctrl.Result{RequeueAfter: initializationRequeueAfter}, nil
}

func (r *KubeadmControlPlaneReconciler) scaleUpControlPlane(ctx context.Context, controlPlane *internal.ControlPlane) (ctrl.Result, error) {
Expand Down Expand Up @@ -107,7 +107,7 @@ func (r *KubeadmControlPlaneReconciler) scaleUpControlPlane(ctx context.Context,
newMachine.Spec.Bootstrap.ConfigRef.Kind, klog.KRef(newMachine.Spec.Bootstrap.ConfigRef.Namespace, newMachine.Spec.Bootstrap.ConfigRef.Name))

// Requeue the control plane, in case there are other operations to perform
return ctrl.Result{Requeue: true}, nil
return ctrl.Result{RequeueAfter: scaleRequeueAfter}, nil
}

func (r *KubeadmControlPlaneReconciler) scaleDownControlPlane(
Expand Down Expand Up @@ -163,7 +163,7 @@ func (r *KubeadmControlPlaneReconciler) scaleDownControlPlane(
Info("Deleting Machine (scale down)", "Machine", klog.KObj(machineToDelete))

// Requeue the control plane, in case there are additional operations to perform
return ctrl.Result{Requeue: true}, nil
return ctrl.Result{RequeueAfter: scaleRequeueAfter}, nil
}

// preflightChecks checks if the control plane is stable before proceeding with a scale up/scale down operation,
Expand Down
8 changes: 4 additions & 4 deletions controlplane/kubeadm/internal/controllers/scale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestKubeadmControlPlaneReconciler_initializeControlPlane(t *testing.T) {
}

result, err := r.initializeControlPlane(ctx, controlPlane)
g.Expect(result).To(BeComparableTo(ctrl.Result{Requeue: true}))
g.Expect(result).To(BeComparableTo(ctrl.Result{RequeueAfter: initializationRequeueAfter}))
g.Expect(err).ToNot(HaveOccurred())

machineList := &clusterv1.MachineList{}
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestKubeadmControlPlaneReconciler_scaleUpControlPlane(t *testing.T) {
}

result, err := r.scaleUpControlPlane(ctx, controlPlane)
g.Expect(result).To(BeComparableTo(ctrl.Result{Requeue: true}))
g.Expect(result).To(BeComparableTo(ctrl.Result{RequeueAfter: scaleRequeueAfter}))
g.Expect(err).ToNot(HaveOccurred())

controlPlaneMachines := clusterv1.MachineList{}
Expand Down Expand Up @@ -286,7 +286,7 @@ func TestKubeadmControlPlaneReconciler_scaleDownControlPlane_NoError(t *testing.

result, err := r.scaleDownControlPlane(context.Background(), controlPlane, controlPlane.Machines)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(result).To(BeComparableTo(ctrl.Result{Requeue: true}))
g.Expect(result).To(BeComparableTo(ctrl.Result{RequeueAfter: scaleRequeueAfter}))

controlPlaneMachines := clusterv1.MachineList{}
g.Expect(fakeClient.List(context.Background(), &controlPlaneMachines)).To(Succeed())
Expand Down Expand Up @@ -328,7 +328,7 @@ func TestKubeadmControlPlaneReconciler_scaleDownControlPlane_NoError(t *testing.

result, err := r.scaleDownControlPlane(context.Background(), controlPlane, controlPlane.Machines)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(result).To(BeComparableTo(ctrl.Result{Requeue: true}))
g.Expect(result).To(BeComparableTo(ctrl.Result{RequeueAfter: scaleRequeueAfter}))

controlPlaneMachines := clusterv1.MachineList{}
g.Expect(fakeClient.List(context.Background(), &controlPlaneMachines)).To(Succeed())
Expand Down
8 changes: 4 additions & 4 deletions controlplane/kubeadm/internal/controllers/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestKubeadmControlPlaneReconciler_RolloutStrategy_ScaleUp(t *testing.T) {
controlPlane.InjectTestManagementCluster(r.managementCluster)

result, err := r.initializeControlPlane(ctx, controlPlane)
g.Expect(result).To(BeComparableTo(ctrl.Result{Requeue: true}))
g.Expect(result).To(BeComparableTo(ctrl.Result{RequeueAfter: initializationRequeueAfter}))
g.Expect(err).ToNot(HaveOccurred())

// initial setup
Expand All @@ -128,7 +128,7 @@ func TestKubeadmControlPlaneReconciler_RolloutStrategy_ScaleUp(t *testing.T) {
needingUpgrade := collections.FromMachineList(initialMachine)
controlPlane.Machines = needingUpgrade
result, err = r.upgradeControlPlane(ctx, controlPlane, needingUpgrade)
g.Expect(result).To(BeComparableTo(ctrl.Result{Requeue: true}))
g.Expect(result).To(BeComparableTo(ctrl.Result{RequeueAfter: scaleRequeueAfter}))
g.Expect(err).ToNot(HaveOccurred())
bothMachines := &clusterv1.MachineList{}
g.Eventually(func(g Gomega) {
Expand Down Expand Up @@ -171,7 +171,7 @@ func TestKubeadmControlPlaneReconciler_RolloutStrategy_ScaleUp(t *testing.T) {
// run upgrade the second time, expect we scale down
result, err = r.upgradeControlPlane(ctx, controlPlane, machinesRequireUpgrade)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(result).To(BeComparableTo(ctrl.Result{Requeue: true}))
g.Expect(result).To(BeComparableTo(ctrl.Result{RequeueAfter: scaleRequeueAfter}))
finalMachine := &clusterv1.MachineList{}
g.Eventually(func(g Gomega) {
g.Expect(env.List(ctx, finalMachine, client.InNamespace(cluster.Namespace))).To(Succeed())
Expand Down Expand Up @@ -262,7 +262,7 @@ func TestKubeadmControlPlaneReconciler_RolloutStrategy_ScaleDown(t *testing.T) {
controlPlane.Machines = needingUpgrade

result, err = r.upgradeControlPlane(ctx, controlPlane, needingUpgrade)
g.Expect(result).To(BeComparableTo(ctrl.Result{Requeue: true}))
g.Expect(result).To(BeComparableTo(ctrl.Result{RequeueAfter: scaleRequeueAfter}))
g.Expect(err).ToNot(HaveOccurred())
remainingMachines := &clusterv1.MachineList{}
g.Expect(fakeClient.List(ctx, remainingMachines, client.InNamespace(cluster.Namespace))).To(Succeed())
Expand Down
Loading