Merge pull request #3537 from chaunceyjiang/application

fix: When suppression and graciously Tasks coexist in the GracefulEvictionTask queue,  the graciously task cannot work.
This commit is contained in:
karmada-bot 2023-05-17 18:50:51 +08:00 committed by GitHub
commit 64d88459bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 2 deletions

View File

@ -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
}

View File

@ -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 {