diff --git a/pkg/controllers/common/task.go b/pkg/controllers/common/task.go index cc066021d0..d6c470706e 100644 --- a/pkg/controllers/common/task.go +++ b/pkg/controllers/common/task.go @@ -179,6 +179,6 @@ func TaskSuspendPod(state PodState, c client.Client) task.Task { return task.Fail().With("can't delete pod %s/%s: %v", pod.Namespace, pod.Name, err) } - return task.Wait().With("pod is deleting") + return task.Retry(task.DefaultRequeueAfter).With("pod is deleting") }) } diff --git a/pkg/controllers/common/task_finalizer.go b/pkg/controllers/common/task_finalizer.go index 281d6423f0..e25b5c4f12 100644 --- a/pkg/controllers/common/task_finalizer.go +++ b/pkg/controllers/common/task_finalizer.go @@ -98,7 +98,7 @@ func TaskGroupFinalizerDel[ return task.Fail().With("cannot delete subresources: %w", err) } if wait { - return task.Wait().With("wait all subresources deleted") + return task.Retry(defaultDelWaitTime).With("wait all subresources deleted") } if err := k8s.RemoveFinalizer(ctx, c, gt.To(state.Group())); err != nil { diff --git a/pkg/controllers/common/task_finalizer_test.go b/pkg/controllers/common/task_finalizer_test.go index d4ead8f355..37f0232da5 100644 --- a/pkg/controllers/common/task_finalizer_test.go +++ b/pkg/controllers/common/task_finalizer_test.go @@ -251,7 +251,7 @@ func testTaskGroupFinalizerDel[ ), }, - expectedStatus: task.SWait, + expectedStatus: task.SRetry, expectedObj: fake.Fake(func(obj RG) RG { obj.SetName("aaa") obj.SetDeletionTimestamp(&now) diff --git a/pkg/controllers/common/task_test.go b/pkg/controllers/common/task_test.go index 82cd79b621..26c1f8b909 100644 --- a/pkg/controllers/common/task_test.go +++ b/pkg/controllers/common/task_test.go @@ -358,7 +358,7 @@ func TestTaskSuspendPod(t *testing.T) { objs: []client.Object{ fake.FakeObj[corev1.Pod]("aaa"), }, - expectedResult: task.SWait, + expectedResult: task.SRetry, expectedObj: fake.FakeObj[corev1.Pod]("aaa"), }, { diff --git a/pkg/controllers/pd/tasks/finalizer.go b/pkg/controllers/pd/tasks/finalizer.go index 51435abfe2..6dee398657 100644 --- a/pkg/controllers/pd/tasks/finalizer.go +++ b/pkg/controllers/pd/tasks/finalizer.go @@ -42,7 +42,7 @@ func TaskFinalizerDel(state *ReconcileContext, c client.Client) task.Task { } if wait { - return task.Wait().With("wait all subresources deleted") + return task.Retry(task.DefaultRequeueAfter).With("wait all subresources deleted") } if err := k8s.RemoveFinalizer(ctx, c, state.PD()); err != nil { @@ -54,7 +54,7 @@ func TaskFinalizerDel(state *ReconcileContext, c client.Client) task.Task { return task.Fail().With("cannot delete subresources: %v", err) } if wait { - return task.Wait().With("wait all subresources deleted") + return task.Retry(task.DefaultRequeueAfter).With("wait all subresources deleted") } if err := k8s.RemoveFinalizer(ctx, c, state.PD()); err != nil { diff --git a/pkg/controllers/pd/tasks/finalizer_test.go b/pkg/controllers/pd/tasks/finalizer_test.go index 63458a7724..b875b34954 100644 --- a/pkg/controllers/pd/tasks/finalizer_test.go +++ b/pkg/controllers/pd/tasks/finalizer_test.go @@ -122,7 +122,7 @@ func TestTaskFinalizerDel(t *testing.T) { }, needDelMember: true, - expectedStatus: task.SWait, + expectedStatus: task.SRetry, expectedObj: fake.FakeObj("aaa", func(obj *v1alpha1.PD) *v1alpha1.PD { obj.Finalizers = append(obj.Finalizers, v1alpha1.Finalizer) return obj @@ -287,7 +287,7 @@ func TestTaskFinalizerDel(t *testing.T) { }), }, - expectedStatus: task.SWait, + expectedStatus: task.SRetry, expectedObj: fake.FakeObj("aaa", func(obj *v1alpha1.PD) *v1alpha1.PD { obj.Finalizers = append(obj.Finalizers, v1alpha1.Finalizer) return obj diff --git a/pkg/controllers/pdgroup/tasks/finalizer.go b/pkg/controllers/pdgroup/tasks/finalizer.go index ab85d6ee39..157781918a 100644 --- a/pkg/controllers/pdgroup/tasks/finalizer.go +++ b/pkg/controllers/pdgroup/tasks/finalizer.go @@ -69,7 +69,7 @@ func TaskFinalizerDel(state State, c client.Client, m pdm.PDClientManager) task. return task.Fail().With("cannot delete subresources: %w", err) } if wait { - return task.Wait().With("wait all subresources deleted") + return task.Retry(task.DefaultRequeueAfter).With("wait all subresources deleted") } if err := k8s.RemoveFinalizer(ctx, c, state.PDGroup()); err != nil { diff --git a/pkg/controllers/pdgroup/tasks/finalizer_test.go b/pkg/controllers/pdgroup/tasks/finalizer_test.go index 0db2887fa9..5694cc69e9 100644 --- a/pkg/controllers/pdgroup/tasks/finalizer_test.go +++ b/pkg/controllers/pdgroup/tasks/finalizer_test.go @@ -118,7 +118,7 @@ func TestTaskFinalizerDel(t *testing.T) { ), }, - expectedStatus: task.SWait, + expectedStatus: task.SRetry, expectedObj: fake.FakeObj("aaa", fake.DeleteTimestamp[v1alpha1.PDGroup](&now), func(obj *v1alpha1.PDGroup) *v1alpha1.PDGroup { obj.Spec.Cluster.Name = defaultTestClusterName obj.Finalizers = append(obj.Finalizers, v1alpha1.Finalizer) diff --git a/pkg/controllers/tidb/tasks/finalizer.go b/pkg/controllers/tidb/tasks/finalizer.go index 6ce3227fd6..c5d3dc349f 100644 --- a/pkg/controllers/tidb/tasks/finalizer.go +++ b/pkg/controllers/tidb/tasks/finalizer.go @@ -33,7 +33,7 @@ func TaskFinalizerDel(state *ReconcileContext, c client.Client) task.Task { return task.Fail().With("cannot delete subresources: %w", err) } if wait { - return task.Wait().With("wait all subresources deleted") + return task.Retry(task.DefaultRequeueAfter).With("wait all subresources deleted") } if err := k8s.RemoveFinalizer(ctx, c, state.TiDB()); err != nil { return task.Fail().With("cannot remove finalizer: %w", err) diff --git a/pkg/controllers/tidb/tasks/finalizer_test.go b/pkg/controllers/tidb/tasks/finalizer_test.go index 51212969c5..dafa864d73 100644 --- a/pkg/controllers/tidb/tasks/finalizer_test.go +++ b/pkg/controllers/tidb/tasks/finalizer_test.go @@ -78,7 +78,7 @@ func TestTaskFinalizerDel(t *testing.T) { }, subresources: fakeSubresources("Pod", "ConfigMap", "PersistentVolumeClaim"), - expectedStatus: task.SWait, + expectedStatus: task.SRetry, expectedObj: fake.FakeObj("aaa", func(obj *v1alpha1.TiDB) *v1alpha1.TiDB { obj.Finalizers = append(obj.Finalizers, v1alpha1.Finalizer) return obj diff --git a/pkg/controllers/tiflash/tasks/finalizer.go b/pkg/controllers/tiflash/tasks/finalizer.go index 04e4d0ac99..82c487979f 100644 --- a/pkg/controllers/tiflash/tasks/finalizer.go +++ b/pkg/controllers/tiflash/tasks/finalizer.go @@ -41,7 +41,7 @@ func TaskFinalizerDel(state *ReconcileContext, c client.Client) task.Task { } if wait { - return task.Wait().With("wait all subresources deleted") + return task.Retry(task.DefaultRequeueAfter).With("wait all subresources deleted") } // whole cluster is deleting @@ -60,7 +60,7 @@ func TaskFinalizerDel(state *ReconcileContext, c client.Client) task.Task { } if wait { - return task.Wait().With("wait all subresources deleted") + return task.Retry(task.DefaultRequeueAfter).With("wait all subresources deleted") } // Store ID is empty may because of tiflash is not initialized // TODO: check whether tiflash is initialized diff --git a/pkg/controllers/tiflash/tasks/finalizer_test.go b/pkg/controllers/tiflash/tasks/finalizer_test.go index f19dce6524..e2819a8f63 100644 --- a/pkg/controllers/tiflash/tasks/finalizer_test.go +++ b/pkg/controllers/tiflash/tasks/finalizer_test.go @@ -83,7 +83,7 @@ func TestTaskFinalizerDel(t *testing.T) { }, subresources: fakeSubresources("Pod", "ConfigMap", "PersistentVolumeClaim"), - expectedStatus: task.SWait, + expectedStatus: task.SRetry, expectedObj: fake.FakeObj("aaa", func(obj *v1alpha1.TiFlash) *v1alpha1.TiFlash { obj.Finalizers = append(obj.Finalizers, v1alpha1.Finalizer) return obj @@ -298,7 +298,7 @@ func TestTaskFinalizerDel(t *testing.T) { }, subresources: fakeSubresources("Pod"), - expectedStatus: task.SWait, + expectedStatus: task.SRetry, expectedObj: fake.FakeObj("aaa", func(obj *v1alpha1.TiFlash) *v1alpha1.TiFlash { obj.Finalizers = append(obj.Finalizers, v1alpha1.Finalizer) return obj diff --git a/pkg/controllers/tikv/tasks/finalizer.go b/pkg/controllers/tikv/tasks/finalizer.go index 2b0ff1bc94..c41f56360c 100644 --- a/pkg/controllers/tikv/tasks/finalizer.go +++ b/pkg/controllers/tikv/tasks/finalizer.go @@ -44,7 +44,7 @@ func TaskFinalizerDel(state *ReconcileContext, c client.Client) task.Task { return task.Fail().With("cannot delete subresources: %w", err) } if wait { - return task.Wait().With("wait all subresources deleted") + return task.Retry(task.DefaultRequeueAfter).With("wait all subresources deleted") } // whole cluster is deleting @@ -61,7 +61,7 @@ func TaskFinalizerDel(state *ReconcileContext, c client.Client) task.Task { return task.Fail().With("cannot delete subresources: %w", err) } if wait { - return task.Wait().With("wait all subresources deleted") + return task.Retry(task.DefaultRequeueAfter).With("wait all subresources deleted") } // Store ID is empty may because of tikv is not initialized // TODO: check whether tikv is initialized diff --git a/pkg/controllers/tikv/tasks/finalizer_test.go b/pkg/controllers/tikv/tasks/finalizer_test.go index 709b3ecc64..3a5d379720 100644 --- a/pkg/controllers/tikv/tasks/finalizer_test.go +++ b/pkg/controllers/tikv/tasks/finalizer_test.go @@ -83,7 +83,7 @@ func TestTaskFinalizerDel(t *testing.T) { }, subresources: fakeSubresources("Pod", "ConfigMap", "PersistentVolumeClaim"), - expectedStatus: task.SWait, + expectedStatus: task.SRetry, expectedObj: fake.FakeObj("aaa", func(obj *v1alpha1.TiKV) *v1alpha1.TiKV { obj.Finalizers = append(obj.Finalizers, v1alpha1.Finalizer) return obj @@ -298,7 +298,7 @@ func TestTaskFinalizerDel(t *testing.T) { }, subresources: fakeSubresources("Pod"), - expectedStatus: task.SWait, + expectedStatus: task.SRetry, expectedObj: fake.FakeObj("aaa", func(obj *v1alpha1.TiKV) *v1alpha1.TiKV { obj.Finalizers = append(obj.Finalizers, v1alpha1.Finalizer) return obj diff --git a/pkg/utils/task/v3/result.go b/pkg/utils/task/v3/result.go index a19e243511..7666506d9d 100644 --- a/pkg/utils/task/v3/result.go +++ b/pkg/utils/task/v3/result.go @@ -20,6 +20,10 @@ import ( "time" ) +const ( + DefaultRequeueAfter = 5 * time.Second +) + type Status int const (