Skip to content

Commit

Permalink
Fix: use task.Retry() instead of task.Wait() in some cases (#6039)
Browse files Browse the repository at this point in the history
  • Loading branch information
fgksgf authored Jan 16, 2025
1 parent bb7a088 commit 6676ae2
Show file tree
Hide file tree
Showing 15 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pkg/controllers/common/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
}
2 changes: 1 addition & 1 deletion pkg/controllers/common/task_finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/common/task_finalizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/common/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
{
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/pd/tasks/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/pd/tasks/finalizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/pdgroup/tasks/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/pdgroup/tasks/finalizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/tidb/tasks/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/tidb/tasks/finalizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/tiflash/tasks/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/tiflash/tasks/finalizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/tikv/tasks/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/tikv/tasks/finalizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions pkg/utils/task/v3/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import (
"time"
)

const (
DefaultRequeueAfter = 5 * time.Second
)

type Status int

const (
Expand Down

0 comments on commit 6676ae2

Please sign in to comment.