From f109634e46465ce158f80e749f3c7cd846363f9e Mon Sep 17 00:00:00 2001 From: sivchari Date: Fri, 21 Nov 2025 16:52:54 +0900 Subject: [PATCH 1/2] migrate from Requeue to RequeueAfter in kcp Signed-off-by: sivchari --- controlplane/kubeadm/internal/controllers/controller.go | 4 ++-- .../kubeadm/internal/controllers/controller_test.go | 2 +- controlplane/kubeadm/internal/controllers/remediation.go | 2 +- controlplane/kubeadm/internal/controllers/scale.go | 6 +++--- controlplane/kubeadm/internal/controllers/scale_test.go | 8 ++++---- controlplane/kubeadm/internal/controllers/update_test.go | 8 ++++---- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/controlplane/kubeadm/internal/controllers/controller.go b/controlplane/kubeadm/internal/controllers/controller.go index f879cb34ea53..45caf3bd0f50 100644 --- a/controlplane/kubeadm/internal/controllers/controller.go +++ b/controlplane/kubeadm/internal/controllers/controller.go @@ -212,7 +212,7 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl. 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{RequeueAfter: 20 * time.Second}, nil } if isPaused, requeue, err := paused.EnsurePausedCondition(ctx, r.Client, cluster, kcp); err != nil || isPaused || requeue { @@ -559,7 +559,7 @@ func (r *KubeadmControlPlaneReconciler) reconcile(ctx context.Context, controlPl 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{RequeueAfter: 20 * time.Second}, nil } // Update kube-proxy daemonset. diff --git a/controlplane/kubeadm/internal/controllers/controller_test.go b/controlplane/kubeadm/internal/controllers/controller_test.go index d5a7d8c13c0b..0db718ee7d33 100644 --- a/controlplane/kubeadm/internal/controllers/controller_test.go +++ b/controlplane/kubeadm/internal/controllers/controller_test.go @@ -488,7 +488,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.RequeueAfter).To(Equal(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 diff --git a/controlplane/kubeadm/internal/controllers/remediation.go b/controlplane/kubeadm/internal/controllers/remediation.go index f8295868dffc..e8f4582f6678 100644 --- a/controlplane/kubeadm/internal/controllers/remediation.go +++ b/controlplane/kubeadm/internal/controllers/remediation.go @@ -368,7 +368,7 @@ func (r *KubeadmControlPlaneReconciler) reconcileUnhealthyMachines(ctx context.C controlplanev1.RemediationInProgressAnnotation: remediationInProgressValue, }) - return ctrl.Result{Requeue: true}, nil + return ctrl.Result{RequeueAfter: 20 * time.Second}, nil } // Gets the machine to be remediated, which is the "most broken" among the unhealthy machines, determined as the machine diff --git a/controlplane/kubeadm/internal/controllers/scale.go b/controlplane/kubeadm/internal/controllers/scale.go index e9301b199527..c966f4f3e084 100644 --- a/controlplane/kubeadm/internal/controllers/scale.go +++ b/controlplane/kubeadm/internal/controllers/scale.go @@ -60,7 +60,7 @@ func (r *KubeadmControlPlaneReconciler) initializeControlPlane(ctx context.Conte newMachine.Spec.Bootstrap.ConfigRef.Kind, klog.KRef(newMachine.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: 20 * time.Second}, nil } func (r *KubeadmControlPlaneReconciler) scaleUpControlPlane(ctx context.Context, controlPlane *internal.ControlPlane) (ctrl.Result, error) { @@ -94,7 +94,7 @@ func (r *KubeadmControlPlaneReconciler) scaleUpControlPlane(ctx context.Context, newMachine.Spec.Bootstrap.ConfigRef.Kind, klog.KRef(newMachine.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: 20 * time.Second}, nil } func (r *KubeadmControlPlaneReconciler) scaleDownControlPlane( @@ -148,7 +148,7 @@ func (r *KubeadmControlPlaneReconciler) scaleDownControlPlane( Info(fmt.Sprintf("Machine %s deleting (scale down)", machineToDelete.Name), "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: 20 * time.Second}, nil } // preflightChecks checks if the control plane is stable before proceeding with a scale up/scale down operation, diff --git a/controlplane/kubeadm/internal/controllers/scale_test.go b/controlplane/kubeadm/internal/controllers/scale_test.go index ccd5bb1aa66a..a39cac3502c2 100644 --- a/controlplane/kubeadm/internal/controllers/scale_test.go +++ b/controlplane/kubeadm/internal/controllers/scale_test.go @@ -84,7 +84,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.RequeueAfter).To(Equal(20 * time.Second)) g.Expect(err).ToNot(HaveOccurred()) machineList := &clusterv1.MachineList{} @@ -164,7 +164,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.RequeueAfter).To(Equal(20 * time.Second)) g.Expect(err).ToNot(HaveOccurred()) controlPlaneMachines := clusterv1.MachineList{} @@ -297,7 +297,7 @@ func TestKubeadmControlPlaneReconciler_scaleDownControlPlane_NoError(t *testing. g.Expect(err).ToNot(HaveOccurred()) result, err := r.scaleDownControlPlane(context.Background(), controlPlane, machineToDelete) g.Expect(err).ToNot(HaveOccurred()) - g.Expect(result).To(BeComparableTo(ctrl.Result{Requeue: true})) + g.Expect(result.RequeueAfter).To(Equal(20 * time.Second)) controlPlaneMachines := clusterv1.MachineList{} g.Expect(fakeClient.List(context.Background(), &controlPlaneMachines)).To(Succeed()) @@ -341,7 +341,7 @@ func TestKubeadmControlPlaneReconciler_scaleDownControlPlane_NoError(t *testing. g.Expect(err).ToNot(HaveOccurred()) result, err := r.scaleDownControlPlane(context.Background(), controlPlane, machineToDelete) g.Expect(err).ToNot(HaveOccurred()) - g.Expect(result).To(BeComparableTo(ctrl.Result{Requeue: true})) + g.Expect(result.RequeueAfter).To(Equal(20 * time.Second)) controlPlaneMachines := clusterv1.MachineList{} g.Expect(fakeClient.List(context.Background(), &controlPlaneMachines)).To(Succeed()) diff --git a/controlplane/kubeadm/internal/controllers/update_test.go b/controlplane/kubeadm/internal/controllers/update_test.go index 96d9736cad98..ce4e9fea75a6 100644 --- a/controlplane/kubeadm/internal/controllers/update_test.go +++ b/controlplane/kubeadm/internal/controllers/update_test.go @@ -116,7 +116,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.RequeueAfter).To(Equal(10 * time.Second)) g.Expect(err).ToNot(HaveOccurred()) // initial setup @@ -142,7 +142,7 @@ func TestKubeadmControlPlaneReconciler_RolloutStrategy_ScaleUp(t *testing.T) { machinesUpToDateResults[m.Name] = internal.UpToDateResult{EligibleForInPlaceUpdate: false} } result, err = r.updateControlPlane(ctx, controlPlane, needingUpgrade, machinesUpToDateResults) - g.Expect(result).To(BeComparableTo(ctrl.Result{Requeue: true})) + g.Expect(result.RequeueAfter).To(Equal(20 * time.Second)) g.Expect(err).ToNot(HaveOccurred()) bothMachines := &clusterv1.MachineList{} g.Eventually(func(g Gomega) { @@ -193,7 +193,7 @@ func TestKubeadmControlPlaneReconciler_RolloutStrategy_ScaleUp(t *testing.T) { // run upgrade the second time, expect we scale down result, err = r.updateControlPlane(ctx, controlPlane, machinesRequireUpgrade, machinesUpToDateResults) g.Expect(err).ToNot(HaveOccurred()) - g.Expect(result).To(BeComparableTo(ctrl.Result{Requeue: true})) + g.Expect(result.RequeueAfter).To(Equal(20 * time.Second)) finalMachine := &clusterv1.MachineList{} g.Eventually(func(g Gomega) { g.Expect(env.List(ctx, finalMachine, client.InNamespace(cluster.Namespace))).To(Succeed()) @@ -287,7 +287,7 @@ func TestKubeadmControlPlaneReconciler_RolloutStrategy_ScaleDown(t *testing.T) { machinesUpToDateResults[m.Name] = internal.UpToDateResult{EligibleForInPlaceUpdate: false} } result, err = r.updateControlPlane(ctx, controlPlane, needingUpgrade, machinesUpToDateResults) - g.Expect(result).To(BeComparableTo(ctrl.Result{Requeue: true})) + g.Expect(result.RequeueAfter).To(Equal(20 * time.Second)) g.Expect(err).ToNot(HaveOccurred()) remainingMachines := &clusterv1.MachineList{} g.Expect(fakeClient.List(ctx, remainingMachines, client.InNamespace(cluster.Namespace))).To(Succeed()) From 952c490dc9d98cc20582e78a9b71311611c5150e Mon Sep 17 00:00:00 2001 From: sivchari Date: Fri, 21 Nov 2025 16:57:55 +0900 Subject: [PATCH 2/2] drop Requeue entirely Signed-off-by: sivchari --- internal/util/controller/controller_test.go | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/internal/util/controller/controller_test.go b/internal/util/controller/controller_test.go index 3edaf4eb4322..3641622376e8 100644 --- a/internal/util/controller/controller_test.go +++ b/internal/util/controller/controller_test.go @@ -185,7 +185,6 @@ func TestReconcileMetrics(t *testing.T) { res, err = r.Reconcile(t.Context(), req) g.Expect(err).To(HaveOccurred()) g.Expect(res.RequeueAfter).To(Equal(time.Duration(0))) - g.Expect(res.Requeue).To(BeFalse()) //nolint:staticcheck // We have to handle Requeue until it is removed g.Expect(counterMetricValue(reconcileTotal.WithLabelValues(r.name, labelError))).To(Equal(1)) g.Expect(counterMetricValue(reconcileTotal.WithLabelValues(r.name, labelRequeueAfter))).To(Equal(0)) g.Expect(counterMetricValue(reconcileTotal.WithLabelValues(r.name, labelRequeue))).To(Equal(0)) @@ -199,26 +198,11 @@ func TestReconcileMetrics(t *testing.T) { res, err = r.Reconcile(t.Context(), req) g.Expect(err).ToNot(HaveOccurred()) g.Expect(res.RequeueAfter).To(Equal(5 * time.Second)) - g.Expect(res.Requeue).To(BeFalse()) //nolint:staticcheck // We have to handle Requeue until it is removed g.Expect(counterMetricValue(reconcileTotal.WithLabelValues(r.name, labelError))).To(Equal(1)) g.Expect(counterMetricValue(reconcileTotal.WithLabelValues(r.name, labelRequeueAfter))).To(Equal(1)) g.Expect(counterMetricValue(reconcileTotal.WithLabelValues(r.name, labelRequeue))).To(Equal(0)) g.Expect(counterMetricValue(reconcileTotal.WithLabelValues(r.name, labelSuccess))).To(Equal(1)) g.Expect(histogramMetricValue(reconcileTime.WithLabelValues(r.name))).To(Equal(3)) - - // Requeue - r.reconciler = reconcile.Func(func(_ context.Context, _ reconcile.Request) (reconcile.Result, error) { - return reconcile.Result{Requeue: true}, nil - }) - res, err = r.Reconcile(t.Context(), req) - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(res.RequeueAfter).To(Equal(time.Duration(0))) - g.Expect(res.Requeue).To(BeTrue()) //nolint:staticcheck // We have to handle Requeue until it is removed - g.Expect(counterMetricValue(reconcileTotal.WithLabelValues(r.name, labelError))).To(Equal(1)) - g.Expect(counterMetricValue(reconcileTotal.WithLabelValues(r.name, labelRequeueAfter))).To(Equal(1)) - g.Expect(counterMetricValue(reconcileTotal.WithLabelValues(r.name, labelRequeue))).To(Equal(1)) - g.Expect(counterMetricValue(reconcileTotal.WithLabelValues(r.name, labelSuccess))).To(Equal(1)) - g.Expect(histogramMetricValue(reconcileTime.WithLabelValues(r.name))).To(Equal(4)) }) }