diff --git a/hack/update-generated-conversions.sh b/hack/update-generated-conversions.sh index 4b723a98a..58297b5ed 100755 --- a/hack/update-generated-conversions.sh +++ b/hack/update-generated-conversions.sh @@ -5,5 +5,5 @@ go build -o "${OS_OUTPUT_BINPATH}/conversion-gen" "k8s.io/code-generator/cmd/con ${OS_OUTPUT_BINPATH}/conversion-gen \ --go-header-file "hack/boilerplate/boilerplate.go.txt" \ - --input-dirs "${PRJ_PREFIX}/pkg/apis/componentconfig/v1alpha1,${PRJ_PREFIX}/pkg/api/v1alpha1,${PRJ_PREFIX}/pkg/framework/plugins/removefailedpods,${PRJ_PREFIX}/pkg/framework/plugins/nodeutilization,${PRJ_PREFIX}/pkg/framework/plugins/podlifetime" \ + --input-dirs "${PRJ_PREFIX}/pkg/apis/componentconfig/v1alpha1,${PRJ_PREFIX}/pkg/api/v1alpha1,${PRJ_PREFIX}/pkg/framework/plugins/removefailedpods,${PRJ_PREFIX}/pkg/framework/plugins/nodeutilization,${PRJ_PREFIX}/pkg/framework/plugins/podlifetime,${PRJ_PREFIX}/pkg/framework/plugins/removeduplicates" \ --output-file-base zz_generated.conversion diff --git a/hack/update-generated-deep-copies.sh b/hack/update-generated-deep-copies.sh index 7c0f60ad4..aeb3ca3b2 100755 --- a/hack/update-generated-deep-copies.sh +++ b/hack/update-generated-deep-copies.sh @@ -5,6 +5,6 @@ go build -o "${OS_OUTPUT_BINPATH}/deepcopy-gen" "k8s.io/code-generator/cmd/deepc ${OS_OUTPUT_BINPATH}/deepcopy-gen \ --go-header-file "hack/boilerplate/boilerplate.go.txt" \ - --input-dirs "${PRJ_PREFIX}/pkg/apis/componentconfig,${PRJ_PREFIX}/pkg/apis/componentconfig/v1alpha1,${PRJ_PREFIX}/pkg/api,${PRJ_PREFIX}/pkg/api/v1alpha1,${PRJ_PREFIX}/pkg/framework/plugins/defaultevictor/,${PRJ_PREFIX}/pkg/framework/plugins/removefailedpods,${PRJ_PREFIX}/pkg/framework/plugins/nodeutilization,${PRJ_PREFIX}/pkg/framework/plugins/podlifetime" \ + --input-dirs "${PRJ_PREFIX}/pkg/apis/componentconfig,${PRJ_PREFIX}/pkg/apis/componentconfig/v1alpha1,${PRJ_PREFIX}/pkg/api,${PRJ_PREFIX}/pkg/api/v1alpha1,${PRJ_PREFIX}/pkg/framework/plugins/defaultevictor/,${PRJ_PREFIX}/pkg/framework/plugins/removefailedpods,${PRJ_PREFIX}/pkg/framework/plugins/nodeutilization,${PRJ_PREFIX}/pkg/framework/plugins/podlifetime,${PRJ_PREFIX}/pkg/framework/plugins/removeduplicates" \ --output-file-base zz_generated.deepcopy diff --git a/pkg/apis/componentconfig/types_pluginargs.go b/pkg/apis/componentconfig/types_pluginargs.go index 1fcfe4e87..788d3d4dc 100644 --- a/pkg/apis/componentconfig/types_pluginargs.go +++ b/pkg/apis/componentconfig/types_pluginargs.go @@ -58,15 +58,6 @@ type RemovePodsHavingTooManyRestartsArgs struct { // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type RemoveDuplicatesArgs struct { - metav1.TypeMeta - - Namespaces *api.Namespaces - ExcludeOwnerKinds []string -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - // RemovePodsViolatingTopologySpreadConstraintArgs holds arguments used to configure RemovePodsViolatingTopologySpreadConstraint plugin. type RemovePodsViolatingTopologySpreadConstraintArgs struct { metav1.TypeMeta diff --git a/pkg/apis/componentconfig/validation/validation_pluginargs.go b/pkg/apis/componentconfig/validation/validation_pluginargs.go index cf84aeac0..88f5562f2 100644 --- a/pkg/apis/componentconfig/validation/validation_pluginargs.go +++ b/pkg/apis/componentconfig/validation/validation_pluginargs.go @@ -63,10 +63,6 @@ func ValidateRemovePodsViolatingNodeAffinityArgs(args *componentconfig.RemovePod ) } -func ValidateRemoveDuplicatesArgs(args *componentconfig.RemoveDuplicatesArgs) error { - return validateNamespaceArgs(args.Namespaces) -} - // ValidateRemovePodsViolatingTopologySpreadConstraintArgs validates RemovePodsViolatingTopologySpreadConstraint arguments func ValidateRemovePodsViolatingTopologySpreadConstraintArgs(args *componentconfig.RemovePodsViolatingTopologySpreadConstraintArgs) error { return errorsAggregate( diff --git a/pkg/apis/componentconfig/zz_generated.deepcopy.go b/pkg/apis/componentconfig/zz_generated.deepcopy.go index 458191d47..b0b94a7f8 100644 --- a/pkg/apis/componentconfig/zz_generated.deepcopy.go +++ b/pkg/apis/componentconfig/zz_generated.deepcopy.go @@ -54,41 +54,6 @@ func (in *DeschedulerConfiguration) DeepCopyObject() runtime.Object { return nil } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *RemoveDuplicatesArgs) DeepCopyInto(out *RemoveDuplicatesArgs) { - *out = *in - out.TypeMeta = in.TypeMeta - if in.Namespaces != nil { - in, out := &in.Namespaces, &out.Namespaces - *out = new(api.Namespaces) - (*in).DeepCopyInto(*out) - } - if in.ExcludeOwnerKinds != nil { - in, out := &in.ExcludeOwnerKinds, &out.ExcludeOwnerKinds - *out = make([]string, len(*in)) - copy(*out, *in) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RemoveDuplicatesArgs. -func (in *RemoveDuplicatesArgs) DeepCopy() *RemoveDuplicatesArgs { - if in == nil { - return nil - } - out := new(RemoveDuplicatesArgs) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *RemoveDuplicatesArgs) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *RemovePodsHavingTooManyRestartsArgs) DeepCopyInto(out *RemovePodsHavingTooManyRestartsArgs) { *out = *in diff --git a/pkg/descheduler/strategy_migration.go b/pkg/descheduler/strategy_migration.go index b79e42a01..c122558e8 100644 --- a/pkg/descheduler/strategy_migration.go +++ b/pkg/descheduler/strategy_migration.go @@ -188,13 +188,13 @@ var pluginsMap = map[string]func(ctx context.Context, nodes []*v1.Node, params * } }, "RemoveDuplicates": func(ctx context.Context, nodes []*v1.Node, params *api.StrategyParameters, handle *handleImpl) { - args := &componentconfig.RemoveDuplicatesArgs{ + args := &removeduplicates.RemoveDuplicatesArgs{ Namespaces: params.Namespaces, } if params.RemoveDuplicates != nil { args.ExcludeOwnerKinds = params.RemoveDuplicates.ExcludeOwnerKinds } - if err := validation.ValidateRemoveDuplicatesArgs(args); err != nil { + if err := removeduplicates.ValidateRemoveDuplicatesArgs(args); err != nil { klog.V(1).ErrorS(err, "unable to validate plugin arguments", "pluginName", removeduplicates.PluginName) return } diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates.go b/pkg/framework/plugins/removeduplicates/removeduplicates.go index b808bebaf..afe2f5f03 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates.go @@ -32,7 +32,6 @@ import ( "k8s.io/apimachinery/pkg/util/sets" "k8s.io/klog/v2" - "sigs.k8s.io/descheduler/pkg/apis/componentconfig" "sigs.k8s.io/descheduler/pkg/descheduler/evictions" podutil "sigs.k8s.io/descheduler/pkg/descheduler/pod" "sigs.k8s.io/descheduler/pkg/framework" @@ -47,7 +46,7 @@ const PluginName = "RemoveDuplicates" type RemoveDuplicates struct { handle framework.Handle - args *componentconfig.RemoveDuplicatesArgs + args *RemoveDuplicatesArgs podFilter podutil.FilterFunc } @@ -60,7 +59,7 @@ type podOwner struct { // New builds plugin from its arguments while passing a handle func New(args runtime.Object, handle framework.Handle) (framework.Plugin, error) { - removeDuplicatesArgs, ok := args.(*componentconfig.RemoveDuplicatesArgs) + removeDuplicatesArgs, ok := args.(*RemoveDuplicatesArgs) if !ok { return nil, fmt.Errorf("want args to be of type RemoveDuplicatesArgs, got %T", args) } diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 1c25b82d0..8a73d9687 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -21,7 +21,6 @@ import ( "testing" "k8s.io/client-go/tools/events" - "sigs.k8s.io/descheduler/pkg/apis/componentconfig" "sigs.k8s.io/descheduler/pkg/framework" frameworkfake "sigs.k8s.io/descheduler/pkg/framework/fake" "sigs.k8s.io/descheduler/pkg/framework/plugins/defaultevictor" @@ -351,7 +350,7 @@ func TestFindDuplicatePods(t *testing.T) { SharedInformerFactoryImpl: sharedInformerFactory, } - plugin, err := New(&componentconfig.RemoveDuplicatesArgs{ + plugin, err := New(&RemoveDuplicatesArgs{ ExcludeOwnerKinds: testCase.excludeOwnerKinds, }, handle, @@ -802,7 +801,7 @@ func TestRemoveDuplicatesUniformly(t *testing.T) { SharedInformerFactoryImpl: sharedInformerFactory, } - plugin, err := New(&componentconfig.RemoveDuplicatesArgs{}, + plugin, err := New(&RemoveDuplicatesArgs{}, handle, ) if err != nil { diff --git a/pkg/framework/plugins/removeduplicates/types.go b/pkg/framework/plugins/removeduplicates/types.go new file mode 100644 index 000000000..981ddba0e --- /dev/null +++ b/pkg/framework/plugins/removeduplicates/types.go @@ -0,0 +1,29 @@ +/* +Copyright 2022 The Kubernetes Authors. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package removeduplicates + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/descheduler/pkg/api" +) + +// +k8s:deepcopy-gen=true +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +type RemoveDuplicatesArgs struct { + metav1.TypeMeta + + Namespaces *api.Namespaces + ExcludeOwnerKinds []string +} diff --git a/pkg/framework/plugins/removeduplicates/validation.go b/pkg/framework/plugins/removeduplicates/validation.go new file mode 100644 index 000000000..240bd36e9 --- /dev/null +++ b/pkg/framework/plugins/removeduplicates/validation.go @@ -0,0 +1,27 @@ +/* +Copyright 2022 The Kubernetes Authors. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package removeduplicates + +import ( + "fmt" +) + +func ValidateRemoveDuplicatesArgs(args *RemoveDuplicatesArgs) error { + // At most one of include/exclude can be set + if args.Namespaces != nil && len(args.Namespaces.Include) > 0 && len(args.Namespaces.Exclude) > 0 { + return fmt.Errorf("only one of Include/Exclude namespaces can be set") + } + + return nil +} diff --git a/pkg/framework/plugins/removeduplicates/zz_generated.deepcopy.go b/pkg/framework/plugins/removeduplicates/zz_generated.deepcopy.go new file mode 100644 index 000000000..bc3652f1d --- /dev/null +++ b/pkg/framework/plugins/removeduplicates/zz_generated.deepcopy.go @@ -0,0 +1,62 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright 2022 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. + +package removeduplicates + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" + api "sigs.k8s.io/descheduler/pkg/api" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RemoveDuplicatesArgs) DeepCopyInto(out *RemoveDuplicatesArgs) { + *out = *in + out.TypeMeta = in.TypeMeta + if in.Namespaces != nil { + in, out := &in.Namespaces, &out.Namespaces + *out = new(api.Namespaces) + (*in).DeepCopyInto(*out) + } + if in.ExcludeOwnerKinds != nil { + in, out := &in.ExcludeOwnerKinds, &out.ExcludeOwnerKinds + *out = make([]string, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RemoveDuplicatesArgs. +func (in *RemoveDuplicatesArgs) DeepCopy() *RemoveDuplicatesArgs { + if in == nil { + return nil + } + out := new(RemoveDuplicatesArgs) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *RemoveDuplicatesArgs) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} diff --git a/test/e2e/e2e_duplicatepods_test.go b/test/e2e/e2e_duplicatepods_test.go index f7554f7a1..8bf97811e 100644 --- a/test/e2e/e2e_duplicatepods_test.go +++ b/test/e2e/e2e_duplicatepods_test.go @@ -21,7 +21,6 @@ import ( "strings" "testing" - "sigs.k8s.io/descheduler/pkg/apis/componentconfig" "sigs.k8s.io/descheduler/pkg/framework" frameworkfake "sigs.k8s.io/descheduler/pkg/framework/fake" "sigs.k8s.io/descheduler/pkg/framework/plugins/defaultevictor" @@ -186,7 +185,7 @@ func TestRemoveDuplicates(t *testing.T) { SharedInformerFactoryImpl: sharedInformerFactory, } - plugin, err := removeduplicates.New(&componentconfig.RemoveDuplicatesArgs{}, + plugin, err := removeduplicates.New(&removeduplicates.RemoveDuplicatesArgs{}, handle, ) if err != nil {