From c602c4ba028524fe9c2e26fc86662cf8b8039095 Mon Sep 17 00:00:00 2001 From: chaunceyjiang Date: Mon, 15 May 2023 11:28:12 +0800 Subject: [PATCH] fix: When suppression and graciously Tasks coexist in the GracefulEvictionTask queue, the graciously task cannot work. Signed-off-by: chaunceyjiang --- .../gracefuleviction/evictiontask.go | 14 ++++++- .../gracefuleviction/evictiontask_test.go | 41 ++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/pkg/controllers/gracefuleviction/evictiontask.go b/pkg/controllers/gracefuleviction/evictiontask.go index 077cb1a2f..4bf2e3e19 100644 --- a/pkg/controllers/gracefuleviction/evictiontask.go +++ b/pkg/controllers/gracefuleviction/evictiontask.go @@ -1,6 +1,7 @@ package gracefuleviction import ( + "math" "time" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -105,9 +106,16 @@ func nextRetry(tasks []workv1alpha2.GracefulEvictionTask, timeout time.Duration, return 0 } - retryInterval := timeout / 10 + retryInterval := time.Duration(math.MaxInt64) + // Skip tasks whose type is SuppressDeletion because they are manually controlled by users. + // We currently take the minimum value of the timeout of all GracefulEvictionTasks besides above. + // When the application on the new cluster becomes healthy, a new event will be queued + // because the controller can watch the changes of binding status. for i := range tasks { + if tasks[i].SuppressDeletion != nil { + continue + } if tasks[i].GracePeriodSeconds != nil { timeout = time.Duration(*tasks[i].GracePeriodSeconds) * time.Second } @@ -117,5 +125,9 @@ func nextRetry(tasks []workv1alpha2.GracefulEvictionTask, timeout time.Duration, } } + // When there are only tasks whose type is SuppressDeletion, we do not need to retry. + if retryInterval == time.Duration(math.MaxInt64) { + retryInterval = 0 + } return retryInterval } diff --git a/pkg/controllers/gracefuleviction/evictiontask_test.go b/pkg/controllers/gracefuleviction/evictiontask_test.go index 2efb87853..e086e3210 100644 --- a/pkg/controllers/gracefuleviction/evictiontask_test.go +++ b/pkg/controllers/gracefuleviction/evictiontask_test.go @@ -569,7 +569,46 @@ func Test_nextRetry(t *testing.T) { timeout: timeout, timeNow: timeNow.Time, }, - want: timeout / 10, + want: time.Minute * 10, + }, + { + name: "suppression and graciously tasks co-exist", + args: args{ + task: []workv1alpha2.GracefulEvictionTask{ + { + FromCluster: "member1", + CreationTimestamp: metav1.Time{Time: timeNow.Add(time.Minute * -60)}, + SuppressDeletion: pointer.Bool(true), + }, + { + FromCluster: "member2", + CreationTimestamp: metav1.Time{Time: timeNow.Add(time.Minute * -5)}, + }, + }, + timeout: timeout, + timeNow: timeNow.Time, + }, + want: time.Minute * 15, + }, + { + name: "only suppression tasks", + args: args{ + task: []workv1alpha2.GracefulEvictionTask{ + { + FromCluster: "member1", + CreationTimestamp: metav1.Time{Time: timeNow.Add(time.Minute * -60)}, + SuppressDeletion: pointer.Bool(true), + }, + { + FromCluster: "member2", + CreationTimestamp: metav1.Time{Time: timeNow.Add(time.Minute * -5)}, + SuppressDeletion: pointer.Bool(true), + }, + }, + timeout: timeout, + timeNow: timeNow.Time, + }, + want: 0, }, } for _, tt := range tests {