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:
commit
64d88459bb
|
@ -1,6 +1,7 @@
|
||||||
package gracefuleviction
|
package gracefuleviction
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
@ -105,9 +106,16 @@ func nextRetry(tasks []workv1alpha2.GracefulEvictionTask, timeout time.Duration,
|
||||||
return 0
|
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 {
|
for i := range tasks {
|
||||||
|
if tasks[i].SuppressDeletion != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if tasks[i].GracePeriodSeconds != nil {
|
if tasks[i].GracePeriodSeconds != nil {
|
||||||
timeout = time.Duration(*tasks[i].GracePeriodSeconds) * time.Second
|
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
|
return retryInterval
|
||||||
}
|
}
|
||||||
|
|
|
@ -569,7 +569,46 @@ func Test_nextRetry(t *testing.T) {
|
||||||
timeout: timeout,
|
timeout: timeout,
|
||||||
timeNow: timeNow.Time,
|
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 {
|
for _, tt := range tests {
|
||||||
|
|
Loading…
Reference in New Issue