From bd911d83cee2855355c0e0d17ed34a02bbce0606 Mon Sep 17 00:00:00 2001 From: chaosi-zju Date: Sat, 28 Dec 2024 11:18:24 +0800 Subject: [PATCH] fix rebalancer auto deleted failed Signed-off-by: chaosi-zju --- .../workloadrebalancer/workloadrebalancer_controller.go | 9 +++------ test/e2e/workloadrebalancer_test.go | 6 ++++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/controllers/workloadrebalancer/workloadrebalancer_controller.go b/pkg/controllers/workloadrebalancer/workloadrebalancer_controller.go index 0c6653c3c27e..16715431789e 100644 --- a/pkg/controllers/workloadrebalancer/workloadrebalancer_controller.go +++ b/pkg/controllers/workloadrebalancer/workloadrebalancer_controller.go @@ -90,15 +90,12 @@ func (c *RebalancerController) Reconcile(ctx context.Context, req controllerrunt return controllerruntime.Result{}, err } - if rebalancer.Status.FinishTime == nil { - // should never reach here. - klog.Errorf("finishTime shouldn't be nil, current status: %+v", rebalancer.Status) - return controllerruntime.Result{}, nil - } - // 3. when all workloads finished, judge whether the rebalancer needs cleanup. rebalancer.Status = *newStatus if rebalancer.Spec.TTLSecondsAfterFinished != nil { + if rebalancer.Status.FinishTime == nil { + return controllerruntime.Result{}, fmt.Errorf("finish time should not be nil") + } remainingTTL := timeLeft(rebalancer) if remainingTTL > 0 { return controllerruntime.Result{RequeueAfter: remainingTTL}, nil diff --git a/test/e2e/workloadrebalancer_test.go b/test/e2e/workloadrebalancer_test.go index 4ddc322ae149..97fa94b9fc43 100644 --- a/test/e2e/workloadrebalancer_test.go +++ b/test/e2e/workloadrebalancer_test.go @@ -193,6 +193,12 @@ var _ = framework.SerialDescribe("workload rebalancer testing", func() { framework.WaitRebalancerDisappear(karmadaClient, rebalancerName) }) }) + + ginkgo.It("create rebalancer with ttl and verify it can auto clean", func() { + rebalancer.Spec.TTLSecondsAfterFinished = ptr.To[int32](5) + framework.CreateWorkloadRebalancer(karmadaClient, rebalancer) + framework.WaitRebalancerDisappear(karmadaClient, rebalancerName) + }) }) // 2. static weight scheduling