update GracefulEvictCluster() to set PurgeMode during eviction process
Signed-off-by: changzhen <changzhen5@huawei.com>
This commit is contained in:
parent
35b7e8f120
commit
db7982e9a9
|
@ -16,8 +16,11 @@ limitations under the License.
|
||||||
|
|
||||||
package v1alpha2
|
package v1alpha2
|
||||||
|
|
||||||
|
import policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
|
||||||
|
|
||||||
// TaskOptions represents options for GracefulEvictionTasks.
|
// TaskOptions represents options for GracefulEvictionTasks.
|
||||||
type TaskOptions struct {
|
type TaskOptions struct {
|
||||||
|
purgeMode policyv1alpha1.PurgeMode
|
||||||
producer string
|
producer string
|
||||||
reason string
|
reason string
|
||||||
message string
|
message string
|
||||||
|
@ -38,6 +41,13 @@ func NewTaskOptions(opts ...Option) *TaskOptions {
|
||||||
return &options
|
return &options
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithPurgeMode sets the purgeMode for TaskOptions
|
||||||
|
func WithPurgeMode(purgeMode policyv1alpha1.PurgeMode) Option {
|
||||||
|
return func(o *TaskOptions) {
|
||||||
|
o.purgeMode = purgeMode
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WithProducer sets the producer for TaskOptions
|
// WithProducer sets the producer for TaskOptions
|
||||||
func WithProducer(producer string) Option {
|
func WithProducer(producer string) Option {
|
||||||
return func(o *TaskOptions) {
|
return func(o *TaskOptions) {
|
||||||
|
@ -154,6 +164,7 @@ func (s *ResourceBindingSpec) GracefulEvictCluster(name string, options *TaskOpt
|
||||||
evictingCluster := evictCluster.DeepCopy()
|
evictingCluster := evictCluster.DeepCopy()
|
||||||
evictionTask := GracefulEvictionTask{
|
evictionTask := GracefulEvictionTask{
|
||||||
FromCluster: evictingCluster.Name,
|
FromCluster: evictingCluster.Name,
|
||||||
|
PurgeMode: options.purgeMode,
|
||||||
Reason: options.reason,
|
Reason: options.reason,
|
||||||
Message: options.message,
|
Message: options.message,
|
||||||
Producer: options.producer,
|
Producer: options.producer,
|
||||||
|
|
|
@ -21,6 +21,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"k8s.io/utils/ptr"
|
"k8s.io/utils/ptr"
|
||||||
|
|
||||||
|
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestResourceBindingSpec_TargetContains(t *testing.T) {
|
func TestResourceBindingSpec_TargetContains(t *testing.T) {
|
||||||
|
@ -172,6 +174,7 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
|
||||||
},
|
},
|
||||||
EvictEvent: GracefulEvictionTask{
|
EvictEvent: GracefulEvictionTask{
|
||||||
FromCluster: "m1",
|
FromCluster: "m1",
|
||||||
|
PurgeMode: policyv1alpha1.Immediately,
|
||||||
Reason: EvictionReasonTaintUntolerated,
|
Reason: EvictionReasonTaintUntolerated,
|
||||||
Message: "graceful eviction",
|
Message: "graceful eviction",
|
||||||
Producer: EvictionProducerTaintManager,
|
Producer: EvictionProducerTaintManager,
|
||||||
|
@ -181,6 +184,7 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
|
||||||
GracefulEvictionTasks: []GracefulEvictionTask{
|
GracefulEvictionTasks: []GracefulEvictionTask{
|
||||||
{
|
{
|
||||||
FromCluster: "m1",
|
FromCluster: "m1",
|
||||||
|
PurgeMode: policyv1alpha1.Immediately,
|
||||||
Replicas: ptr.To[int32](1),
|
Replicas: ptr.To[int32](1),
|
||||||
Reason: EvictionReasonTaintUntolerated,
|
Reason: EvictionReasonTaintUntolerated,
|
||||||
Message: "graceful eviction",
|
Message: "graceful eviction",
|
||||||
|
@ -196,6 +200,7 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
|
||||||
},
|
},
|
||||||
EvictEvent: GracefulEvictionTask{
|
EvictEvent: GracefulEvictionTask{
|
||||||
FromCluster: "m2",
|
FromCluster: "m2",
|
||||||
|
PurgeMode: policyv1alpha1.Never,
|
||||||
Reason: EvictionReasonTaintUntolerated,
|
Reason: EvictionReasonTaintUntolerated,
|
||||||
Message: "graceful eviction",
|
Message: "graceful eviction",
|
||||||
Producer: EvictionProducerTaintManager,
|
Producer: EvictionProducerTaintManager,
|
||||||
|
@ -205,6 +210,7 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
|
||||||
GracefulEvictionTasks: []GracefulEvictionTask{
|
GracefulEvictionTasks: []GracefulEvictionTask{
|
||||||
{
|
{
|
||||||
FromCluster: "m2",
|
FromCluster: "m2",
|
||||||
|
PurgeMode: policyv1alpha1.Never,
|
||||||
Replicas: ptr.To[int32](2),
|
Replicas: ptr.To[int32](2),
|
||||||
Reason: EvictionReasonTaintUntolerated,
|
Reason: EvictionReasonTaintUntolerated,
|
||||||
Message: "graceful eviction",
|
Message: "graceful eviction",
|
||||||
|
@ -220,6 +226,7 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
|
||||||
},
|
},
|
||||||
EvictEvent: GracefulEvictionTask{
|
EvictEvent: GracefulEvictionTask{
|
||||||
FromCluster: "m3",
|
FromCluster: "m3",
|
||||||
|
PurgeMode: policyv1alpha1.Graciously,
|
||||||
Reason: EvictionReasonTaintUntolerated,
|
Reason: EvictionReasonTaintUntolerated,
|
||||||
Message: "graceful eviction",
|
Message: "graceful eviction",
|
||||||
Producer: EvictionProducerTaintManager,
|
Producer: EvictionProducerTaintManager,
|
||||||
|
@ -229,6 +236,7 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
|
||||||
GracefulEvictionTasks: []GracefulEvictionTask{
|
GracefulEvictionTasks: []GracefulEvictionTask{
|
||||||
{
|
{
|
||||||
FromCluster: "m3",
|
FromCluster: "m3",
|
||||||
|
PurgeMode: policyv1alpha1.Graciously,
|
||||||
Replicas: ptr.To[int32](3),
|
Replicas: ptr.To[int32](3),
|
||||||
Reason: EvictionReasonTaintUntolerated,
|
Reason: EvictionReasonTaintUntolerated,
|
||||||
Message: "graceful eviction",
|
Message: "graceful eviction",
|
||||||
|
@ -245,6 +253,7 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
|
||||||
},
|
},
|
||||||
EvictEvent: GracefulEvictionTask{
|
EvictEvent: GracefulEvictionTask{
|
||||||
FromCluster: "m3",
|
FromCluster: "m3",
|
||||||
|
PurgeMode: policyv1alpha1.Graciously,
|
||||||
Reason: EvictionReasonTaintUntolerated,
|
Reason: EvictionReasonTaintUntolerated,
|
||||||
Message: "graceful eviction",
|
Message: "graceful eviction",
|
||||||
Producer: EvictionProducerTaintManager,
|
Producer: EvictionProducerTaintManager,
|
||||||
|
@ -257,6 +266,7 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
FromCluster: "m3",
|
FromCluster: "m3",
|
||||||
|
PurgeMode: policyv1alpha1.Graciously,
|
||||||
Replicas: ptr.To[int32](3),
|
Replicas: ptr.To[int32](3),
|
||||||
Reason: EvictionReasonTaintUntolerated,
|
Reason: EvictionReasonTaintUntolerated,
|
||||||
Message: "graceful eviction",
|
Message: "graceful eviction",
|
||||||
|
@ -286,6 +296,7 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
|
||||||
},
|
},
|
||||||
EvictEvent: GracefulEvictionTask{
|
EvictEvent: GracefulEvictionTask{
|
||||||
FromCluster: "m1",
|
FromCluster: "m1",
|
||||||
|
PurgeMode: policyv1alpha1.Graciously,
|
||||||
Replicas: ptr.To[int32](1),
|
Replicas: ptr.To[int32](1),
|
||||||
Reason: EvictionReasonTaintUntolerated,
|
Reason: EvictionReasonTaintUntolerated,
|
||||||
Message: "graceful eviction v2",
|
Message: "graceful eviction v2",
|
||||||
|
@ -309,7 +320,11 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
tc := test
|
tc := test
|
||||||
t.Run(tc.Name, func(t *testing.T) {
|
t.Run(tc.Name, func(t *testing.T) {
|
||||||
tc.InputSpec.GracefulEvictCluster(tc.EvictEvent.FromCluster, NewTaskOptions(WithProducer(tc.EvictEvent.Producer), WithReason(tc.EvictEvent.Reason), WithMessage(tc.EvictEvent.Message)))
|
tc.InputSpec.GracefulEvictCluster(tc.EvictEvent.FromCluster, NewTaskOptions(
|
||||||
|
WithPurgeMode(tc.EvictEvent.PurgeMode),
|
||||||
|
WithProducer(tc.EvictEvent.Producer),
|
||||||
|
WithReason(tc.EvictEvent.Reason),
|
||||||
|
WithMessage(tc.EvictEvent.Message)))
|
||||||
|
|
||||||
if !reflect.DeepEqual(tc.InputSpec.Clusters, tc.ExpectSpec.Clusters) {
|
if !reflect.DeepEqual(tc.InputSpec.Clusters, tc.ExpectSpec.Clusters) {
|
||||||
t.Fatalf("expect clusters: %v, but got: %v", tc.ExpectSpec.Clusters, tc.InputSpec.Clusters)
|
t.Fatalf("expect clusters: %v, but got: %v", tc.ExpectSpec.Clusters, tc.InputSpec.Clusters)
|
||||||
|
|
|
@ -7393,6 +7393,13 @@ func schema_pkg_apis_work_v1alpha2_TaskOptions(ref common.ReferenceCallback) com
|
||||||
Description: "TaskOptions represents options for GracefulEvictionTasks.",
|
Description: "TaskOptions represents options for GracefulEvictionTasks.",
|
||||||
Type: []string{"object"},
|
Type: []string{"object"},
|
||||||
Properties: map[string]spec.Schema{
|
Properties: map[string]spec.Schema{
|
||||||
|
"purgeMode": {
|
||||||
|
SchemaProps: spec.SchemaProps{
|
||||||
|
Default: "",
|
||||||
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
"producer": {
|
"producer": {
|
||||||
SchemaProps: spec.SchemaProps{
|
SchemaProps: spec.SchemaProps{
|
||||||
Default: "",
|
Default: "",
|
||||||
|
@ -7427,7 +7434,7 @@ func schema_pkg_apis_work_v1alpha2_TaskOptions(ref common.ReferenceCallback) com
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Required: []string{"producer", "reason", "message", "gracePeriodSeconds", "suppressDeletion"},
|
Required: []string{"purgeMode", "producer", "reason", "message", "gracePeriodSeconds", "suppressDeletion"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue