Skip to content

Commit

Permalink
Merge pull request #5821 from XiShanYongYe-Chang/update-GracefulEvict…
Browse files Browse the repository at this point in the history
…Cluster-to-set-purgemode

Support PurgeMode setting in evection tasks
  • Loading branch information
karmada-bot authored Nov 16, 2024
2 parents 3acc14c + db7982e commit 35a8237
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
11 changes: 11 additions & 0 deletions pkg/apis/work/v1alpha2/binding_types_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ limitations under the License.

package v1alpha2

import policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"

// TaskOptions represents options for GracefulEvictionTasks.
type TaskOptions struct {
purgeMode policyv1alpha1.PurgeMode
producer string
reason string
message string
Expand All @@ -38,6 +41,13 @@ func NewTaskOptions(opts ...Option) *TaskOptions {
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
func WithProducer(producer string) Option {
return func(o *TaskOptions) {
Expand Down Expand Up @@ -154,6 +164,7 @@ func (s *ResourceBindingSpec) GracefulEvictCluster(name string, options *TaskOpt
evictingCluster := evictCluster.DeepCopy()
evictionTask := GracefulEvictionTask{
FromCluster: evictingCluster.Name,
PurgeMode: options.purgeMode,
Reason: options.reason,
Message: options.message,
Producer: options.producer,
Expand Down
17 changes: 16 additions & 1 deletion pkg/apis/work/v1alpha2/binding_types_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"testing"

"k8s.io/utils/ptr"

policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
)

func TestResourceBindingSpec_TargetContains(t *testing.T) {
Expand Down Expand Up @@ -172,6 +174,7 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
},
EvictEvent: GracefulEvictionTask{
FromCluster: "m1",
PurgeMode: policyv1alpha1.Immediately,
Reason: EvictionReasonTaintUntolerated,
Message: "graceful eviction",
Producer: EvictionProducerTaintManager,
Expand All @@ -181,6 +184,7 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
GracefulEvictionTasks: []GracefulEvictionTask{
{
FromCluster: "m1",
PurgeMode: policyv1alpha1.Immediately,
Replicas: ptr.To[int32](1),
Reason: EvictionReasonTaintUntolerated,
Message: "graceful eviction",
Expand All @@ -196,6 +200,7 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
},
EvictEvent: GracefulEvictionTask{
FromCluster: "m2",
PurgeMode: policyv1alpha1.Never,
Reason: EvictionReasonTaintUntolerated,
Message: "graceful eviction",
Producer: EvictionProducerTaintManager,
Expand All @@ -205,6 +210,7 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
GracefulEvictionTasks: []GracefulEvictionTask{
{
FromCluster: "m2",
PurgeMode: policyv1alpha1.Never,
Replicas: ptr.To[int32](2),
Reason: EvictionReasonTaintUntolerated,
Message: "graceful eviction",
Expand All @@ -220,6 +226,7 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
},
EvictEvent: GracefulEvictionTask{
FromCluster: "m3",
PurgeMode: policyv1alpha1.Graciously,
Reason: EvictionReasonTaintUntolerated,
Message: "graceful eviction",
Producer: EvictionProducerTaintManager,
Expand All @@ -229,6 +236,7 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
GracefulEvictionTasks: []GracefulEvictionTask{
{
FromCluster: "m3",
PurgeMode: policyv1alpha1.Graciously,
Replicas: ptr.To[int32](3),
Reason: EvictionReasonTaintUntolerated,
Message: "graceful eviction",
Expand All @@ -245,6 +253,7 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
},
EvictEvent: GracefulEvictionTask{
FromCluster: "m3",
PurgeMode: policyv1alpha1.Graciously,
Reason: EvictionReasonTaintUntolerated,
Message: "graceful eviction",
Producer: EvictionProducerTaintManager,
Expand All @@ -257,6 +266,7 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
},
{
FromCluster: "m3",
PurgeMode: policyv1alpha1.Graciously,
Replicas: ptr.To[int32](3),
Reason: EvictionReasonTaintUntolerated,
Message: "graceful eviction",
Expand Down Expand Up @@ -286,6 +296,7 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
},
EvictEvent: GracefulEvictionTask{
FromCluster: "m1",
PurgeMode: policyv1alpha1.Graciously,
Replicas: ptr.To[int32](1),
Reason: EvictionReasonTaintUntolerated,
Message: "graceful eviction v2",
Expand All @@ -309,7 +320,11 @@ func TestResourceBindingSpec_GracefulEvictCluster(t *testing.T) {
for _, test := range tests {
tc := test
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) {
t.Fatalf("expect clusters: %v, but got: %v", tc.ExpectSpec.Clusters, tc.InputSpec.Clusters)
Expand Down
9 changes: 8 additions & 1 deletion pkg/generated/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 35a8237

Please sign in to comment.