Skip to content

Commit d92adfc

Browse files
committed
migrate from Requeue to RequeueAfter in kcp
Signed-off-by: sivchari <shibuuuu5@gmail.com>
1 parent 4fe9364 commit d92adfc

File tree

6 files changed

+15
-20
lines changed

6 files changed

+15
-20
lines changed

controlplane/kubeadm/internal/controllers/controller.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,7 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.
211211
// Initialize the patch helper.
212212
patchHelper, err := patch.NewHelper(kcp, r.Client)
213213
if err != nil {
214-
log.Error(err, "Failed to configure the patch helper")
215-
return ctrl.Result{Requeue: true}, nil
214+
return ctrl.Result{}, err
216215
}
217216

218217
if isPaused, requeue, err := paused.EnsurePausedCondition(ctx, r.Client, cluster, kcp); err != nil || isPaused || requeue {
@@ -558,8 +557,7 @@ func (r *KubeadmControlPlaneReconciler) reconcile(ctx context.Context, controlPl
558557
// Get the workload cluster client.
559558
workloadCluster, err := controlPlane.GetWorkloadCluster(ctx)
560559
if err != nil {
561-
log.V(2).Info("cannot get remote client to workload cluster, will requeue", "cause", err)
562-
return ctrl.Result{Requeue: true}, nil
560+
return ctrl.Result{}, err
563561
}
564562

565563
// Update kube-proxy daemonset.

controlplane/kubeadm/internal/controllers/controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ func TestReconcileClusterNoEndpoints(t *testing.T) {
488488
result, err = r.Reconcile(ctx, ctrl.Request{NamespacedName: util.ObjectKey(kcp)})
489489
g.Expect(err).ToNot(HaveOccurred())
490490
// TODO: this should stop to re-queue as soon as we have a proper remote cluster cache in place.
491-
g.Expect(result).To(BeComparableTo(ctrl.Result{Requeue: false, RequeueAfter: 20 * time.Second}))
491+
g.Expect(result.RequeueAfter).To(Equal(20 * time.Second))
492492
g.Expect(r.Client.Get(ctx, util.ObjectKey(kcp), kcp)).To(Succeed())
493493

494494
// Always expect that the Finalizer is set on the passed in resource

controlplane/kubeadm/internal/controllers/remediation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ func (r *KubeadmControlPlaneReconciler) reconcileUnhealthyMachines(ctx context.C
368368
controlplanev1.RemediationInProgressAnnotation: remediationInProgressValue,
369369
})
370370

371-
return ctrl.Result{Requeue: true}, nil
371+
return ctrl.Result{RequeueAfter: time.Millisecond}, nil // Technically there is no need to requeue here. Machine deletion above triggers reconciliation. But we have to return a non-zero Result so reconcile above returns.
372372
}
373373

374374
// Gets the machine to be remediated, which is the "most broken" among the unhealthy machines, determined as the machine

controlplane/kubeadm/internal/controllers/scale.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ func (r *KubeadmControlPlaneReconciler) initializeControlPlane(ctx context.Conte
5959
newMachine.Spec.InfrastructureRef.Kind, klog.KRef(newMachine.Namespace, newMachine.Spec.InfrastructureRef.Name),
6060
newMachine.Spec.Bootstrap.ConfigRef.Kind, klog.KRef(newMachine.Namespace, newMachine.Spec.Bootstrap.ConfigRef.Name))
6161

62-
// Requeue the control plane, in case there are additional operations to perform
63-
return ctrl.Result{Requeue: true}, nil
62+
return ctrl.Result{}, nil // No need to requeue here. Machine creation above triggers reconciliation.
6463
}
6564

6665
func (r *KubeadmControlPlaneReconciler) scaleUpControlPlane(ctx context.Context, controlPlane *internal.ControlPlane) (ctrl.Result, error) {
@@ -93,8 +92,7 @@ func (r *KubeadmControlPlaneReconciler) scaleUpControlPlane(ctx context.Context,
9392
newMachine.Spec.InfrastructureRef.Kind, klog.KRef(newMachine.Namespace, newMachine.Spec.InfrastructureRef.Name),
9493
newMachine.Spec.Bootstrap.ConfigRef.Kind, klog.KRef(newMachine.Namespace, newMachine.Spec.Bootstrap.ConfigRef.Name))
9594

96-
// Requeue the control plane, in case there are other operations to perform
97-
return ctrl.Result{Requeue: true}, nil
95+
return ctrl.Result{}, nil // No need to requeue here. Machine creation above triggers reconciliation.
9896
}
9997

10098
func (r *KubeadmControlPlaneReconciler) scaleDownControlPlane(
@@ -147,8 +145,7 @@ func (r *KubeadmControlPlaneReconciler) scaleDownControlPlane(
147145
log.WithValues(controlPlane.StatusToLogKeyAndValues(nil, machineToDelete)...).
148146
Info(fmt.Sprintf("Machine %s deleting (scale down)", machineToDelete.Name), "Machine", klog.KObj(machineToDelete))
149147

150-
// Requeue the control plane, in case there are additional operations to perform
151-
return ctrl.Result{Requeue: true}, nil
148+
return ctrl.Result{}, nil // No need to requeue here. Machine deletion above triggers reconciliation.
152149
}
153150

154151
// preflightChecks checks if the control plane is stable before proceeding with a scale up/scale down operation,

controlplane/kubeadm/internal/controllers/scale_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func TestKubeadmControlPlaneReconciler_initializeControlPlane(t *testing.T) {
8484
}
8585

8686
result, err := r.initializeControlPlane(ctx, controlPlane)
87-
g.Expect(result).To(BeComparableTo(ctrl.Result{Requeue: true}))
87+
g.Expect(result.IsZero()).To(BeTrue())
8888
g.Expect(err).ToNot(HaveOccurred())
8989

9090
machineList := &clusterv1.MachineList{}
@@ -164,7 +164,7 @@ func TestKubeadmControlPlaneReconciler_scaleUpControlPlane(t *testing.T) {
164164
}
165165

166166
result, err := r.scaleUpControlPlane(ctx, controlPlane)
167-
g.Expect(result).To(BeComparableTo(ctrl.Result{Requeue: true}))
167+
g.Expect(result.IsZero()).To(BeTrue())
168168
g.Expect(err).ToNot(HaveOccurred())
169169

170170
controlPlaneMachines := clusterv1.MachineList{}
@@ -297,7 +297,7 @@ func TestKubeadmControlPlaneReconciler_scaleDownControlPlane_NoError(t *testing.
297297
g.Expect(err).ToNot(HaveOccurred())
298298
result, err := r.scaleDownControlPlane(context.Background(), controlPlane, machineToDelete)
299299
g.Expect(err).ToNot(HaveOccurred())
300-
g.Expect(result).To(BeComparableTo(ctrl.Result{Requeue: true}))
300+
g.Expect(result.IsZero()).To(BeTrue())
301301

302302
controlPlaneMachines := clusterv1.MachineList{}
303303
g.Expect(fakeClient.List(context.Background(), &controlPlaneMachines)).To(Succeed())
@@ -341,7 +341,7 @@ func TestKubeadmControlPlaneReconciler_scaleDownControlPlane_NoError(t *testing.
341341
g.Expect(err).ToNot(HaveOccurred())
342342
result, err := r.scaleDownControlPlane(context.Background(), controlPlane, machineToDelete)
343343
g.Expect(err).ToNot(HaveOccurred())
344-
g.Expect(result).To(BeComparableTo(ctrl.Result{Requeue: true}))
344+
g.Expect(result.IsZero()).To(BeTrue())
345345

346346
controlPlaneMachines := clusterv1.MachineList{}
347347
g.Expect(fakeClient.List(context.Background(), &controlPlaneMachines)).To(Succeed())

controlplane/kubeadm/internal/controllers/update_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func TestKubeadmControlPlaneReconciler_RolloutStrategy_ScaleUp(t *testing.T) {
116116
controlPlane.InjectTestManagementCluster(r.managementCluster)
117117

118118
result, err := r.initializeControlPlane(ctx, controlPlane)
119-
g.Expect(result).To(BeComparableTo(ctrl.Result{Requeue: true}))
119+
g.Expect(result.RequeueAfter).To(Equal(time.Duration(0)))
120120
g.Expect(err).ToNot(HaveOccurred())
121121

122122
// initial setup
@@ -142,7 +142,7 @@ func TestKubeadmControlPlaneReconciler_RolloutStrategy_ScaleUp(t *testing.T) {
142142
machinesUpToDateResults[m.Name] = internal.UpToDateResult{EligibleForInPlaceUpdate: false}
143143
}
144144
result, err = r.updateControlPlane(ctx, controlPlane, needingUpgrade, machinesUpToDateResults)
145-
g.Expect(result).To(BeComparableTo(ctrl.Result{Requeue: true}))
145+
g.Expect(result.IsZero()).To(BeTrue())
146146
g.Expect(err).ToNot(HaveOccurred())
147147
bothMachines := &clusterv1.MachineList{}
148148
g.Eventually(func(g Gomega) {
@@ -193,7 +193,7 @@ func TestKubeadmControlPlaneReconciler_RolloutStrategy_ScaleUp(t *testing.T) {
193193
// run upgrade the second time, expect we scale down
194194
result, err = r.updateControlPlane(ctx, controlPlane, machinesRequireUpgrade, machinesUpToDateResults)
195195
g.Expect(err).ToNot(HaveOccurred())
196-
g.Expect(result).To(BeComparableTo(ctrl.Result{Requeue: true}))
196+
g.Expect(result.IsZero()).To(BeTrue())
197197
finalMachine := &clusterv1.MachineList{}
198198
g.Eventually(func(g Gomega) {
199199
g.Expect(env.List(ctx, finalMachine, client.InNamespace(cluster.Namespace))).To(Succeed())
@@ -287,7 +287,7 @@ func TestKubeadmControlPlaneReconciler_RolloutStrategy_ScaleDown(t *testing.T) {
287287
machinesUpToDateResults[m.Name] = internal.UpToDateResult{EligibleForInPlaceUpdate: false}
288288
}
289289
result, err = r.updateControlPlane(ctx, controlPlane, needingUpgrade, machinesUpToDateResults)
290-
g.Expect(result).To(BeComparableTo(ctrl.Result{Requeue: true}))
290+
g.Expect(result.IsZero()).To(BeTrue())
291291
g.Expect(err).ToNot(HaveOccurred())
292292
remainingMachines := &clusterv1.MachineList{}
293293
g.Expect(fakeClient.List(ctx, remainingMachines, client.InNamespace(cluster.Namespace))).To(Succeed())

0 commit comments

Comments
 (0)