Skip to content

Commit db7982e

Browse files
update GracefulEvictCluster() to set PurgeMode during eviction process
Signed-off-by: changzhen <[email protected]>
1 parent 35b7e8f commit db7982e

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

Diff for: pkg/apis/work/v1alpha2/binding_types_helper.go

+11
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ limitations under the License.
1616

1717
package v1alpha2
1818

19+
import policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
20+
1921
// TaskOptions represents options for GracefulEvictionTasks.
2022
type TaskOptions struct {
23+
purgeMode policyv1alpha1.PurgeMode
2124
producer string
2225
reason string
2326
message string
@@ -38,6 +41,13 @@ func NewTaskOptions(opts ...Option) *TaskOptions {
3841
return &options
3942
}
4043

44+
// WithPurgeMode sets the purgeMode for TaskOptions
45+
func WithPurgeMode(purgeMode policyv1alpha1.PurgeMode) Option {
46+
return func(o *TaskOptions) {
47+
o.purgeMode = purgeMode
48+
}
49+
}
50+
4151
// WithProducer sets the producer for TaskOptions
4252
func WithProducer(producer string) Option {
4353
return func(o *TaskOptions) {
@@ -154,6 +164,7 @@ func (s *ResourceBindingSpec) GracefulEvictCluster(name string, options *TaskOpt
154164
evictingCluster := evictCluster.DeepCopy()
155165
evictionTask := GracefulEvictionTask{
156166
FromCluster: evictingCluster.Name,
167+
PurgeMode: options.purgeMode,
157168
Reason: options.reason,
158169
Message: options.message,
159170
Producer: options.producer,

Diff for: pkg/apis/work/v1alpha2/binding_types_helper_test.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"testing"
2222

2323
"k8s.io/utils/ptr"
24+
25+
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
2426
)
2527

2628
func TestResourceBindingSpec_TargetContains(t *testing.T) {
@@ -172,6 +174,7 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
172174
},
173175
EvictEvent: GracefulEvictionTask{
174176
FromCluster: "m1",
177+
PurgeMode: policyv1alpha1.Immediately,
175178
Reason: EvictionReasonTaintUntolerated,
176179
Message: "graceful eviction",
177180
Producer: EvictionProducerTaintManager,
@@ -181,6 +184,7 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
181184
GracefulEvictionTasks: []GracefulEvictionTask{
182185
{
183186
FromCluster: "m1",
187+
PurgeMode: policyv1alpha1.Immediately,
184188
Replicas: ptr.To[int32](1),
185189
Reason: EvictionReasonTaintUntolerated,
186190
Message: "graceful eviction",
@@ -196,6 +200,7 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
196200
},
197201
EvictEvent: GracefulEvictionTask{
198202
FromCluster: "m2",
203+
PurgeMode: policyv1alpha1.Never,
199204
Reason: EvictionReasonTaintUntolerated,
200205
Message: "graceful eviction",
201206
Producer: EvictionProducerTaintManager,
@@ -205,6 +210,7 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
205210
GracefulEvictionTasks: []GracefulEvictionTask{
206211
{
207212
FromCluster: "m2",
213+
PurgeMode: policyv1alpha1.Never,
208214
Replicas: ptr.To[int32](2),
209215
Reason: EvictionReasonTaintUntolerated,
210216
Message: "graceful eviction",
@@ -220,6 +226,7 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
220226
},
221227
EvictEvent: GracefulEvictionTask{
222228
FromCluster: "m3",
229+
PurgeMode: policyv1alpha1.Graciously,
223230
Reason: EvictionReasonTaintUntolerated,
224231
Message: "graceful eviction",
225232
Producer: EvictionProducerTaintManager,
@@ -229,6 +236,7 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
229236
GracefulEvictionTasks: []GracefulEvictionTask{
230237
{
231238
FromCluster: "m3",
239+
PurgeMode: policyv1alpha1.Graciously,
232240
Replicas: ptr.To[int32](3),
233241
Reason: EvictionReasonTaintUntolerated,
234242
Message: "graceful eviction",
@@ -245,6 +253,7 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
245253
},
246254
EvictEvent: GracefulEvictionTask{
247255
FromCluster: "m3",
256+
PurgeMode: policyv1alpha1.Graciously,
248257
Reason: EvictionReasonTaintUntolerated,
249258
Message: "graceful eviction",
250259
Producer: EvictionProducerTaintManager,
@@ -257,6 +266,7 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
257266
},
258267
{
259268
FromCluster: "m3",
269+
PurgeMode: policyv1alpha1.Graciously,
260270
Replicas: ptr.To[int32](3),
261271
Reason: EvictionReasonTaintUntolerated,
262272
Message: "graceful eviction",
@@ -286,6 +296,7 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
286296
},
287297
EvictEvent: GracefulEvictionTask{
288298
FromCluster: "m1",
299+
PurgeMode: policyv1alpha1.Graciously,
289300
Replicas: ptr.To[int32](1),
290301
Reason: EvictionReasonTaintUntolerated,
291302
Message: "graceful eviction v2",
@@ -309,7 +320,11 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
309320
for _, test := range tests {
310321
tc := test
311322
t.Run(tc.Name, func(t *testing.T) {
312-
tc.InputSpec.GracefulEvictCluster(tc.EvictEvent.FromCluster, NewTaskOptions(WithProducer(tc.EvictEvent.Producer), WithReason(tc.EvictEvent.Reason), WithMessage(tc.EvictEvent.Message)))
323+
tc.InputSpec.GracefulEvictCluster(tc.EvictEvent.FromCluster, NewTaskOptions(
324+
WithPurgeMode(tc.EvictEvent.PurgeMode),
325+
WithProducer(tc.EvictEvent.Producer),
326+
WithReason(tc.EvictEvent.Reason),
327+
WithMessage(tc.EvictEvent.Message)))
313328

314329
if !reflect.DeepEqual(tc.InputSpec.Clusters, tc.ExpectSpec.Clusters) {
315330
t.Fatalf("expect clusters: %v, but got: %v", tc.ExpectSpec.Clusters, tc.InputSpec.Clusters)

Diff for: pkg/generated/openapi/zz_generated.openapi.go

+8-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)