From c4d20ca8a8d577ad11b1f7440d3896a17458074d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Wicha?= Date: Wed, 26 Feb 2020 18:38:06 +0000 Subject: [PATCH] Add types for Scheduler plugin args to kube-scheduler.config.k8s.io --- api/api-rules/violation_exceptions.list | 4 + cmd/kube-scheduler/app/options/deprecated.go | 4 +- pkg/scheduler/BUILD | 2 +- pkg/scheduler/apis/config/BUILD | 1 + pkg/scheduler/apis/config/legacy_types.go | 16 -- pkg/scheduler/apis/config/register.go | 5 + pkg/scheduler/apis/config/types_pluginargs.go | 101 ++++++++ .../v1alpha2/zz_generated.conversion.go | 228 ++++++++++++++++++ .../apis/config/zz_generated.deepcopy.go | 170 +++++++++++++ pkg/scheduler/factory.go | 6 +- pkg/scheduler/framework/plugins/BUILD | 1 + .../framework/plugins/interpodaffinity/BUILD | 2 + .../plugins/interpodaffinity/plugin.go | 22 +- .../plugins/interpodaffinity/scoring.go | 4 +- .../plugins/interpodaffinity/scoring_test.go | 3 +- .../framework/plugins/legacy_registry.go | 41 +++- .../framework/plugins/nodelabel/BUILD | 1 + .../framework/plugins/nodelabel/node_label.go | 27 +-- .../framework/plugins/noderesources/BUILD | 2 + .../framework/plugins/noderesources/fit.go | 34 ++- .../requested_to_capacity_ratio.go | 8 +- .../requested_to_capacity_ratio_test.go | 47 ++++ .../framework/plugins/serviceaffinity/BUILD | 2 + .../serviceaffinity/service_affinity.go | 15 +- .../serviceaffinity/service_affinity_test.go | 7 +- .../kube-scheduler/config/v1alpha2/BUILD | 1 + .../config/v1alpha2/register.go | 5 + .../config/v1alpha2/types_pluginargs.go | 115 +++++++++ .../config/v1alpha2/zz_generated.deepcopy.go | 207 ++++++++++++++++ 29 files changed, 971 insertions(+), 110 deletions(-) create mode 100644 pkg/scheduler/apis/config/types_pluginargs.go create mode 100644 staging/src/k8s.io/kube-scheduler/config/v1alpha2/types_pluginargs.go diff --git a/api/api-rules/violation_exceptions.list b/api/api-rules/violation_exceptions.list index e8538bd2060..1bafd7cc76a 100644 --- a/api/api-rules/violation_exceptions.list +++ b/api/api-rules/violation_exceptions.list @@ -597,6 +597,10 @@ API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,V API rule violation: names_match,k8s.io/kube-controller-manager/config/v1alpha1,VolumeConfiguration,PersistentVolumeRecyclerConfiguration API rule violation: names_match,k8s.io/kube-proxy/config/v1alpha1,KubeProxyConfiguration,IPTables API rule violation: names_match,k8s.io/kube-scheduler/config/v1,Extender,EnableHTTPS +API rule violation: names_match,k8s.io/kube-scheduler/config/v1alpha2,ResourceSpec,Name +API rule violation: names_match,k8s.io/kube-scheduler/config/v1alpha2,ResourceSpec,Weight +API rule violation: names_match,k8s.io/kube-scheduler/config/v1alpha2,UtilizationShapePoint,Score +API rule violation: names_match,k8s.io/kube-scheduler/config/v1alpha2,UtilizationShapePoint,Utilization API rule violation: names_match,k8s.io/kubelet/config/v1beta1,KubeletConfiguration,IPTablesDropBit API rule violation: names_match,k8s.io/kubelet/config/v1beta1,KubeletConfiguration,IPTablesMasqueradeBit API rule violation: names_match,k8s.io/kubelet/config/v1beta1,KubeletConfiguration,ResolverConfig diff --git a/cmd/kube-scheduler/app/options/deprecated.go b/cmd/kube-scheduler/app/options/deprecated.go index badb7063194..2becd3c97a2 100644 --- a/cmd/kube-scheduler/app/options/deprecated.go +++ b/cmd/kube-scheduler/app/options/deprecated.go @@ -21,6 +21,7 @@ import ( "github.com/spf13/pflag" "k8s.io/apimachinery/pkg/util/validation/field" + kubeschedulerv1alpha2 "k8s.io/kube-scheduler/config/v1alpha2" "k8s.io/kubernetes/pkg/scheduler/algorithmprovider" kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config" "k8s.io/kubernetes/pkg/scheduler/framework/plugins" @@ -128,11 +129,10 @@ func (o *DeprecatedOptions) ApplyTo(cfg *kubeschedulerconfig.KubeSchedulerConfig profile.SchedulerName = o.SchedulerName } if o.HardPodAffinitySymmetricWeight != interpodaffinity.DefaultHardPodAffinityWeight { - args := interpodaffinity.Args{ + args := kubeschedulerv1alpha2.InterPodAffinityArgs{ HardPodAffinityWeight: &o.HardPodAffinitySymmetricWeight, } profile.PluginConfig = append(profile.PluginConfig, plugins.NewPluginConfig(interpodaffinity.Name, args)) } - return nil } diff --git a/pkg/scheduler/BUILD b/pkg/scheduler/BUILD index c202cb145aa..baf11c614e8 100644 --- a/pkg/scheduler/BUILD +++ b/pkg/scheduler/BUILD @@ -20,7 +20,6 @@ go_library( "//pkg/scheduler/core:go_default_library", "//pkg/scheduler/framework/plugins:go_default_library", "//pkg/scheduler/framework/plugins/defaultbinder:go_default_library", - "//pkg/scheduler/framework/plugins/interpodaffinity:go_default_library", "//pkg/scheduler/framework/plugins/noderesources:go_default_library", "//pkg/scheduler/framework/plugins/queuesort:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library", @@ -46,6 +45,7 @@ go_library( "//staging/src/k8s.io/client-go/listers/core/v1:go_default_library", "//staging/src/k8s.io/client-go/listers/policy/v1beta1:go_default_library", "//staging/src/k8s.io/client-go/tools/cache:go_default_library", + "//staging/src/k8s.io/kube-scheduler/config/v1alpha2:go_default_library", "//vendor/github.com/google/go-cmp/cmp:go_default_library", "//vendor/k8s.io/klog:go_default_library", ], diff --git a/pkg/scheduler/apis/config/BUILD b/pkg/scheduler/apis/config/BUILD index cc454ed08dc..24c1f3970cc 100644 --- a/pkg/scheduler/apis/config/BUILD +++ b/pkg/scheduler/apis/config/BUILD @@ -7,6 +7,7 @@ go_library( "legacy_types.go", "register.go", "types.go", + "types_pluginargs.go", "zz_generated.deepcopy.go", ], importpath = "k8s.io/kubernetes/pkg/scheduler/apis/config", diff --git a/pkg/scheduler/apis/config/legacy_types.go b/pkg/scheduler/apis/config/legacy_types.go index 79eb0daed7e..b1ada2b22e5 100644 --- a/pkg/scheduler/apis/config/legacy_types.go +++ b/pkg/scheduler/apis/config/legacy_types.go @@ -136,22 +136,6 @@ type RequestedToCapacityRatioArguments struct { Resources []ResourceSpec `json:"resources,omitempty"` } -// UtilizationShapePoint represents single point of priority function shape -type UtilizationShapePoint struct { - // Utilization (x axis). Valid values are 0 to 100. Fully utilized node maps to 100. - Utilization int32 - // Score assigned to given utilization (y axis). Valid values are 0 to 10. - Score int32 -} - -// ResourceSpec represents single resource for bin packing of priority RequestedToCapacityRatioArguments. -type ResourceSpec struct { - // Name of the resource to be managed by RequestedToCapacityRatio function. - Name string - // Weight of the resource. - Weight int64 -} - // ExtenderManagedResource describes the arguments of extended resources // managed by an extender. type ExtenderManagedResource struct { diff --git a/pkg/scheduler/apis/config/register.go b/pkg/scheduler/apis/config/register.go index bb67672faef..681777f691b 100644 --- a/pkg/scheduler/apis/config/register.go +++ b/pkg/scheduler/apis/config/register.go @@ -39,6 +39,11 @@ func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, &KubeSchedulerConfiguration{}, &Policy{}, + &InterPodAffinityArgs{}, + &NodeLabelArgs{}, + &NodeResourcesFitArgs{}, + &RequestedToCapacityRatioArgs{}, + &ServiceAffinityArgs{}, ) scheme.AddKnownTypes(schema.GroupVersion{Group: "", Version: runtime.APIVersionInternal}, &Policy{}) return nil diff --git a/pkg/scheduler/apis/config/types_pluginargs.go b/pkg/scheduler/apis/config/types_pluginargs.go new file mode 100644 index 00000000000..308119fbd48 --- /dev/null +++ b/pkg/scheduler/apis/config/types_pluginargs.go @@ -0,0 +1,101 @@ +/* +Copyright 2020 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 config + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// InterPodAffinityArgs holds arguments used to configure the InterPodAffinity plugin. +type InterPodAffinityArgs struct { + metav1.TypeMeta + + // HardPodAffinityWeight is the scoring weight for existing pods with a + // matching hard affinity to the incoming pod. + HardPodAffinityWeight int32 +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// NodeLabelArgs holds arguments that used to configure the NodeLabel plugin. +type NodeLabelArgs struct { + metav1.TypeMeta + + // PresentLabels should be present for the node to be considered a fit for hosting the pod + PresentLabels []string + // AbsentLabels should be absent for the node to be considered a fit for hosting the pod + AbsentLabels []string + // Nodes that have labels in the list will get a higher score. + PresentLabelsPreference []string + // Nodes that don't have labels in the list will get a higher score. + AbsentLabelsPreference []string +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// NodeResourcesFitArgs holds arguments used to configure the NodeResourcesFit plugin. +type NodeResourcesFitArgs struct { + metav1.TypeMeta + + // IgnoredResources is the list of resources that NodeResources fit filter + // should ignore. + IgnoredResources []string +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// RequestedToCapacityRatioArgs holds arguments used to configure RequestedToCapacityRatio plugin. +type RequestedToCapacityRatioArgs struct { + metav1.TypeMeta + + // Points defining priority function shape + Shape []UtilizationShapePoint + // Resources to be managed + Resources []ResourceSpec +} + +// UtilizationShapePoint represents a single point of a priority function shape. +type UtilizationShapePoint struct { + // Utilization (x axis). Valid values are 0 to 100. Fully utilized node maps to 100. + Utilization int32 + // Score assigned to a given utilization (y axis). Valid values are 0 to 10. + Score int32 +} + +// ResourceSpec represents single resource for bin packing of priority RequestedToCapacityRatioArgs. +type ResourceSpec struct { + // Name of the resource to be managed by RequestedToCapacityRatio function. + Name string + // Weight of the resource. + Weight int64 +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// ServiceAffinityArgs holds arguments used to configure the ServiceAffinity plugin. +type ServiceAffinityArgs struct { + metav1.TypeMeta + + // AffinityLabels are homogeneous for pods that are scheduled to a node. + // (i.e. it returns true IFF this pod can be added to this node such that all other pods in + // the same service are running on nodes with the exact same values for Labels). + AffinityLabels []string + // AntiAffinityLabelsPreference are the labels to consider for service anti affinity scoring. + AntiAffinityLabelsPreference []string +} diff --git a/pkg/scheduler/apis/config/v1alpha2/zz_generated.conversion.go b/pkg/scheduler/apis/config/v1alpha2/zz_generated.conversion.go index d5c4ef58133..f21a6607caa 100644 --- a/pkg/scheduler/apis/config/v1alpha2/zz_generated.conversion.go +++ b/pkg/scheduler/apis/config/v1alpha2/zz_generated.conversion.go @@ -39,6 +39,16 @@ func init() { // RegisterConversions adds conversion functions to the given scheme. // Public to allow building arbitrary schemes. func RegisterConversions(s *runtime.Scheme) error { + if err := s.AddGeneratedConversionFunc((*v1alpha2.InterPodAffinityArgs)(nil), (*config.InterPodAffinityArgs)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha2_InterPodAffinityArgs_To_config_InterPodAffinityArgs(a.(*v1alpha2.InterPodAffinityArgs), b.(*config.InterPodAffinityArgs), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*config.InterPodAffinityArgs)(nil), (*v1alpha2.InterPodAffinityArgs)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_config_InterPodAffinityArgs_To_v1alpha2_InterPodAffinityArgs(a.(*config.InterPodAffinityArgs), b.(*v1alpha2.InterPodAffinityArgs), scope) + }); err != nil { + return err + } if err := s.AddGeneratedConversionFunc((*v1alpha2.KubeSchedulerLeaderElectionConfiguration)(nil), (*config.KubeSchedulerLeaderElectionConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha2_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration(a.(*v1alpha2.KubeSchedulerLeaderElectionConfiguration), b.(*config.KubeSchedulerLeaderElectionConfiguration), scope) }); err != nil { @@ -59,6 +69,26 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddGeneratedConversionFunc((*v1alpha2.NodeLabelArgs)(nil), (*config.NodeLabelArgs)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha2_NodeLabelArgs_To_config_NodeLabelArgs(a.(*v1alpha2.NodeLabelArgs), b.(*config.NodeLabelArgs), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*config.NodeLabelArgs)(nil), (*v1alpha2.NodeLabelArgs)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_config_NodeLabelArgs_To_v1alpha2_NodeLabelArgs(a.(*config.NodeLabelArgs), b.(*v1alpha2.NodeLabelArgs), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1alpha2.NodeResourcesFitArgs)(nil), (*config.NodeResourcesFitArgs)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha2_NodeResourcesFitArgs_To_config_NodeResourcesFitArgs(a.(*v1alpha2.NodeResourcesFitArgs), b.(*config.NodeResourcesFitArgs), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*config.NodeResourcesFitArgs)(nil), (*v1alpha2.NodeResourcesFitArgs)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_config_NodeResourcesFitArgs_To_v1alpha2_NodeResourcesFitArgs(a.(*config.NodeResourcesFitArgs), b.(*v1alpha2.NodeResourcesFitArgs), scope) + }); err != nil { + return err + } if err := s.AddGeneratedConversionFunc((*v1alpha2.Plugin)(nil), (*config.Plugin)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha2_Plugin_To_config_Plugin(a.(*v1alpha2.Plugin), b.(*config.Plugin), scope) }); err != nil { @@ -99,6 +129,46 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddGeneratedConversionFunc((*v1alpha2.RequestedToCapacityRatioArgs)(nil), (*config.RequestedToCapacityRatioArgs)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha2_RequestedToCapacityRatioArgs_To_config_RequestedToCapacityRatioArgs(a.(*v1alpha2.RequestedToCapacityRatioArgs), b.(*config.RequestedToCapacityRatioArgs), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*config.RequestedToCapacityRatioArgs)(nil), (*v1alpha2.RequestedToCapacityRatioArgs)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_config_RequestedToCapacityRatioArgs_To_v1alpha2_RequestedToCapacityRatioArgs(a.(*config.RequestedToCapacityRatioArgs), b.(*v1alpha2.RequestedToCapacityRatioArgs), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1alpha2.ResourceSpec)(nil), (*config.ResourceSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha2_ResourceSpec_To_config_ResourceSpec(a.(*v1alpha2.ResourceSpec), b.(*config.ResourceSpec), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*config.ResourceSpec)(nil), (*v1alpha2.ResourceSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_config_ResourceSpec_To_v1alpha2_ResourceSpec(a.(*config.ResourceSpec), b.(*v1alpha2.ResourceSpec), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1alpha2.ServiceAffinityArgs)(nil), (*config.ServiceAffinityArgs)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha2_ServiceAffinityArgs_To_config_ServiceAffinityArgs(a.(*v1alpha2.ServiceAffinityArgs), b.(*config.ServiceAffinityArgs), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*config.ServiceAffinityArgs)(nil), (*v1alpha2.ServiceAffinityArgs)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_config_ServiceAffinityArgs_To_v1alpha2_ServiceAffinityArgs(a.(*config.ServiceAffinityArgs), b.(*v1alpha2.ServiceAffinityArgs), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1alpha2.UtilizationShapePoint)(nil), (*config.UtilizationShapePoint)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha2_UtilizationShapePoint_To_config_UtilizationShapePoint(a.(*v1alpha2.UtilizationShapePoint), b.(*config.UtilizationShapePoint), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*config.UtilizationShapePoint)(nil), (*v1alpha2.UtilizationShapePoint)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_config_UtilizationShapePoint_To_v1alpha2_UtilizationShapePoint(a.(*config.UtilizationShapePoint), b.(*v1alpha2.UtilizationShapePoint), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*config.KubeSchedulerConfiguration)(nil), (*v1alpha2.KubeSchedulerConfiguration)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_config_KubeSchedulerConfiguration_To_v1alpha2_KubeSchedulerConfiguration(a.(*config.KubeSchedulerConfiguration), b.(*v1alpha2.KubeSchedulerConfiguration), scope) }); err != nil { @@ -112,6 +182,30 @@ func RegisterConversions(s *runtime.Scheme) error { return nil } +func autoConvert_v1alpha2_InterPodAffinityArgs_To_config_InterPodAffinityArgs(in *v1alpha2.InterPodAffinityArgs, out *config.InterPodAffinityArgs, s conversion.Scope) error { + if err := v1.Convert_Pointer_int32_To_int32(&in.HardPodAffinityWeight, &out.HardPodAffinityWeight, s); err != nil { + return err + } + return nil +} + +// Convert_v1alpha2_InterPodAffinityArgs_To_config_InterPodAffinityArgs is an autogenerated conversion function. +func Convert_v1alpha2_InterPodAffinityArgs_To_config_InterPodAffinityArgs(in *v1alpha2.InterPodAffinityArgs, out *config.InterPodAffinityArgs, s conversion.Scope) error { + return autoConvert_v1alpha2_InterPodAffinityArgs_To_config_InterPodAffinityArgs(in, out, s) +} + +func autoConvert_config_InterPodAffinityArgs_To_v1alpha2_InterPodAffinityArgs(in *config.InterPodAffinityArgs, out *v1alpha2.InterPodAffinityArgs, s conversion.Scope) error { + if err := v1.Convert_int32_To_Pointer_int32(&in.HardPodAffinityWeight, &out.HardPodAffinityWeight, s); err != nil { + return err + } + return nil +} + +// Convert_config_InterPodAffinityArgs_To_v1alpha2_InterPodAffinityArgs is an autogenerated conversion function. +func Convert_config_InterPodAffinityArgs_To_v1alpha2_InterPodAffinityArgs(in *config.InterPodAffinityArgs, out *v1alpha2.InterPodAffinityArgs, s conversion.Scope) error { + return autoConvert_config_InterPodAffinityArgs_To_v1alpha2_InterPodAffinityArgs(in, out, s) +} + func autoConvert_v1alpha2_KubeSchedulerConfiguration_To_config_KubeSchedulerConfiguration(in *v1alpha2.KubeSchedulerConfiguration, out *config.KubeSchedulerConfiguration, s conversion.Scope) error { if err := Convert_v1alpha2_KubeSchedulerLeaderElectionConfiguration_To_config_KubeSchedulerLeaderElectionConfiguration(&in.LeaderElection, &out.LeaderElection, s); err != nil { return err @@ -273,6 +367,52 @@ func Convert_config_KubeSchedulerProfile_To_v1alpha2_KubeSchedulerProfile(in *co return autoConvert_config_KubeSchedulerProfile_To_v1alpha2_KubeSchedulerProfile(in, out, s) } +func autoConvert_v1alpha2_NodeLabelArgs_To_config_NodeLabelArgs(in *v1alpha2.NodeLabelArgs, out *config.NodeLabelArgs, s conversion.Scope) error { + out.PresentLabels = *(*[]string)(unsafe.Pointer(&in.PresentLabels)) + out.AbsentLabels = *(*[]string)(unsafe.Pointer(&in.AbsentLabels)) + out.PresentLabelsPreference = *(*[]string)(unsafe.Pointer(&in.PresentLabelsPreference)) + out.AbsentLabelsPreference = *(*[]string)(unsafe.Pointer(&in.AbsentLabelsPreference)) + return nil +} + +// Convert_v1alpha2_NodeLabelArgs_To_config_NodeLabelArgs is an autogenerated conversion function. +func Convert_v1alpha2_NodeLabelArgs_To_config_NodeLabelArgs(in *v1alpha2.NodeLabelArgs, out *config.NodeLabelArgs, s conversion.Scope) error { + return autoConvert_v1alpha2_NodeLabelArgs_To_config_NodeLabelArgs(in, out, s) +} + +func autoConvert_config_NodeLabelArgs_To_v1alpha2_NodeLabelArgs(in *config.NodeLabelArgs, out *v1alpha2.NodeLabelArgs, s conversion.Scope) error { + out.PresentLabels = *(*[]string)(unsafe.Pointer(&in.PresentLabels)) + out.AbsentLabels = *(*[]string)(unsafe.Pointer(&in.AbsentLabels)) + out.PresentLabelsPreference = *(*[]string)(unsafe.Pointer(&in.PresentLabelsPreference)) + out.AbsentLabelsPreference = *(*[]string)(unsafe.Pointer(&in.AbsentLabelsPreference)) + return nil +} + +// Convert_config_NodeLabelArgs_To_v1alpha2_NodeLabelArgs is an autogenerated conversion function. +func Convert_config_NodeLabelArgs_To_v1alpha2_NodeLabelArgs(in *config.NodeLabelArgs, out *v1alpha2.NodeLabelArgs, s conversion.Scope) error { + return autoConvert_config_NodeLabelArgs_To_v1alpha2_NodeLabelArgs(in, out, s) +} + +func autoConvert_v1alpha2_NodeResourcesFitArgs_To_config_NodeResourcesFitArgs(in *v1alpha2.NodeResourcesFitArgs, out *config.NodeResourcesFitArgs, s conversion.Scope) error { + out.IgnoredResources = *(*[]string)(unsafe.Pointer(&in.IgnoredResources)) + return nil +} + +// Convert_v1alpha2_NodeResourcesFitArgs_To_config_NodeResourcesFitArgs is an autogenerated conversion function. +func Convert_v1alpha2_NodeResourcesFitArgs_To_config_NodeResourcesFitArgs(in *v1alpha2.NodeResourcesFitArgs, out *config.NodeResourcesFitArgs, s conversion.Scope) error { + return autoConvert_v1alpha2_NodeResourcesFitArgs_To_config_NodeResourcesFitArgs(in, out, s) +} + +func autoConvert_config_NodeResourcesFitArgs_To_v1alpha2_NodeResourcesFitArgs(in *config.NodeResourcesFitArgs, out *v1alpha2.NodeResourcesFitArgs, s conversion.Scope) error { + out.IgnoredResources = *(*[]string)(unsafe.Pointer(&in.IgnoredResources)) + return nil +} + +// Convert_config_NodeResourcesFitArgs_To_v1alpha2_NodeResourcesFitArgs is an autogenerated conversion function. +func Convert_config_NodeResourcesFitArgs_To_v1alpha2_NodeResourcesFitArgs(in *config.NodeResourcesFitArgs, out *v1alpha2.NodeResourcesFitArgs, s conversion.Scope) error { + return autoConvert_config_NodeResourcesFitArgs_To_v1alpha2_NodeResourcesFitArgs(in, out, s) +} + func autoConvert_v1alpha2_Plugin_To_config_Plugin(in *v1alpha2.Plugin, out *config.Plugin, s conversion.Scope) error { out.Name = in.Name if err := v1.Convert_Pointer_int32_To_int32(&in.Weight, &out.Weight, s); err != nil { @@ -598,3 +738,91 @@ func autoConvert_config_Plugins_To_v1alpha2_Plugins(in *config.Plugins, out *v1a func Convert_config_Plugins_To_v1alpha2_Plugins(in *config.Plugins, out *v1alpha2.Plugins, s conversion.Scope) error { return autoConvert_config_Plugins_To_v1alpha2_Plugins(in, out, s) } + +func autoConvert_v1alpha2_RequestedToCapacityRatioArgs_To_config_RequestedToCapacityRatioArgs(in *v1alpha2.RequestedToCapacityRatioArgs, out *config.RequestedToCapacityRatioArgs, s conversion.Scope) error { + out.Shape = *(*[]config.UtilizationShapePoint)(unsafe.Pointer(&in.Shape)) + out.Resources = *(*[]config.ResourceSpec)(unsafe.Pointer(&in.Resources)) + return nil +} + +// Convert_v1alpha2_RequestedToCapacityRatioArgs_To_config_RequestedToCapacityRatioArgs is an autogenerated conversion function. +func Convert_v1alpha2_RequestedToCapacityRatioArgs_To_config_RequestedToCapacityRatioArgs(in *v1alpha2.RequestedToCapacityRatioArgs, out *config.RequestedToCapacityRatioArgs, s conversion.Scope) error { + return autoConvert_v1alpha2_RequestedToCapacityRatioArgs_To_config_RequestedToCapacityRatioArgs(in, out, s) +} + +func autoConvert_config_RequestedToCapacityRatioArgs_To_v1alpha2_RequestedToCapacityRatioArgs(in *config.RequestedToCapacityRatioArgs, out *v1alpha2.RequestedToCapacityRatioArgs, s conversion.Scope) error { + out.Shape = *(*[]v1alpha2.UtilizationShapePoint)(unsafe.Pointer(&in.Shape)) + out.Resources = *(*[]v1alpha2.ResourceSpec)(unsafe.Pointer(&in.Resources)) + return nil +} + +// Convert_config_RequestedToCapacityRatioArgs_To_v1alpha2_RequestedToCapacityRatioArgs is an autogenerated conversion function. +func Convert_config_RequestedToCapacityRatioArgs_To_v1alpha2_RequestedToCapacityRatioArgs(in *config.RequestedToCapacityRatioArgs, out *v1alpha2.RequestedToCapacityRatioArgs, s conversion.Scope) error { + return autoConvert_config_RequestedToCapacityRatioArgs_To_v1alpha2_RequestedToCapacityRatioArgs(in, out, s) +} + +func autoConvert_v1alpha2_ResourceSpec_To_config_ResourceSpec(in *v1alpha2.ResourceSpec, out *config.ResourceSpec, s conversion.Scope) error { + out.Name = in.Name + out.Weight = in.Weight + return nil +} + +// Convert_v1alpha2_ResourceSpec_To_config_ResourceSpec is an autogenerated conversion function. +func Convert_v1alpha2_ResourceSpec_To_config_ResourceSpec(in *v1alpha2.ResourceSpec, out *config.ResourceSpec, s conversion.Scope) error { + return autoConvert_v1alpha2_ResourceSpec_To_config_ResourceSpec(in, out, s) +} + +func autoConvert_config_ResourceSpec_To_v1alpha2_ResourceSpec(in *config.ResourceSpec, out *v1alpha2.ResourceSpec, s conversion.Scope) error { + out.Name = in.Name + out.Weight = in.Weight + return nil +} + +// Convert_config_ResourceSpec_To_v1alpha2_ResourceSpec is an autogenerated conversion function. +func Convert_config_ResourceSpec_To_v1alpha2_ResourceSpec(in *config.ResourceSpec, out *v1alpha2.ResourceSpec, s conversion.Scope) error { + return autoConvert_config_ResourceSpec_To_v1alpha2_ResourceSpec(in, out, s) +} + +func autoConvert_v1alpha2_ServiceAffinityArgs_To_config_ServiceAffinityArgs(in *v1alpha2.ServiceAffinityArgs, out *config.ServiceAffinityArgs, s conversion.Scope) error { + out.AffinityLabels = *(*[]string)(unsafe.Pointer(&in.AffinityLabels)) + out.AntiAffinityLabelsPreference = *(*[]string)(unsafe.Pointer(&in.AntiAffinityLabelsPreference)) + return nil +} + +// Convert_v1alpha2_ServiceAffinityArgs_To_config_ServiceAffinityArgs is an autogenerated conversion function. +func Convert_v1alpha2_ServiceAffinityArgs_To_config_ServiceAffinityArgs(in *v1alpha2.ServiceAffinityArgs, out *config.ServiceAffinityArgs, s conversion.Scope) error { + return autoConvert_v1alpha2_ServiceAffinityArgs_To_config_ServiceAffinityArgs(in, out, s) +} + +func autoConvert_config_ServiceAffinityArgs_To_v1alpha2_ServiceAffinityArgs(in *config.ServiceAffinityArgs, out *v1alpha2.ServiceAffinityArgs, s conversion.Scope) error { + out.AffinityLabels = *(*[]string)(unsafe.Pointer(&in.AffinityLabels)) + out.AntiAffinityLabelsPreference = *(*[]string)(unsafe.Pointer(&in.AntiAffinityLabelsPreference)) + return nil +} + +// Convert_config_ServiceAffinityArgs_To_v1alpha2_ServiceAffinityArgs is an autogenerated conversion function. +func Convert_config_ServiceAffinityArgs_To_v1alpha2_ServiceAffinityArgs(in *config.ServiceAffinityArgs, out *v1alpha2.ServiceAffinityArgs, s conversion.Scope) error { + return autoConvert_config_ServiceAffinityArgs_To_v1alpha2_ServiceAffinityArgs(in, out, s) +} + +func autoConvert_v1alpha2_UtilizationShapePoint_To_config_UtilizationShapePoint(in *v1alpha2.UtilizationShapePoint, out *config.UtilizationShapePoint, s conversion.Scope) error { + out.Utilization = in.Utilization + out.Score = in.Score + return nil +} + +// Convert_v1alpha2_UtilizationShapePoint_To_config_UtilizationShapePoint is an autogenerated conversion function. +func Convert_v1alpha2_UtilizationShapePoint_To_config_UtilizationShapePoint(in *v1alpha2.UtilizationShapePoint, out *config.UtilizationShapePoint, s conversion.Scope) error { + return autoConvert_v1alpha2_UtilizationShapePoint_To_config_UtilizationShapePoint(in, out, s) +} + +func autoConvert_config_UtilizationShapePoint_To_v1alpha2_UtilizationShapePoint(in *config.UtilizationShapePoint, out *v1alpha2.UtilizationShapePoint, s conversion.Scope) error { + out.Utilization = in.Utilization + out.Score = in.Score + return nil +} + +// Convert_config_UtilizationShapePoint_To_v1alpha2_UtilizationShapePoint is an autogenerated conversion function. +func Convert_config_UtilizationShapePoint_To_v1alpha2_UtilizationShapePoint(in *config.UtilizationShapePoint, out *v1alpha2.UtilizationShapePoint, s conversion.Scope) error { + return autoConvert_config_UtilizationShapePoint_To_v1alpha2_UtilizationShapePoint(in, out, s) +} diff --git a/pkg/scheduler/apis/config/zz_generated.deepcopy.go b/pkg/scheduler/apis/config/zz_generated.deepcopy.go index 4b7c92369ca..918847eb93d 100644 --- a/pkg/scheduler/apis/config/zz_generated.deepcopy.go +++ b/pkg/scheduler/apis/config/zz_generated.deepcopy.go @@ -97,6 +97,31 @@ func (in *ExtenderTLSConfig) DeepCopy() *ExtenderTLSConfig { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *InterPodAffinityArgs) DeepCopyInto(out *InterPodAffinityArgs) { + *out = *in + out.TypeMeta = in.TypeMeta + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new InterPodAffinityArgs. +func (in *InterPodAffinityArgs) DeepCopy() *InterPodAffinityArgs { + if in == nil { + return nil + } + out := new(InterPodAffinityArgs) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *InterPodAffinityArgs) 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 *KubeSchedulerConfiguration) DeepCopyInto(out *KubeSchedulerConfiguration) { *out = *in @@ -222,6 +247,81 @@ func (in *LabelsPresence) DeepCopy() *LabelsPresence { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NodeLabelArgs) DeepCopyInto(out *NodeLabelArgs) { + *out = *in + out.TypeMeta = in.TypeMeta + if in.PresentLabels != nil { + in, out := &in.PresentLabels, &out.PresentLabels + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.AbsentLabels != nil { + in, out := &in.AbsentLabels, &out.AbsentLabels + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.PresentLabelsPreference != nil { + in, out := &in.PresentLabelsPreference, &out.PresentLabelsPreference + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.AbsentLabelsPreference != nil { + in, out := &in.AbsentLabelsPreference, &out.AbsentLabelsPreference + *out = make([]string, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeLabelArgs. +func (in *NodeLabelArgs) DeepCopy() *NodeLabelArgs { + if in == nil { + return nil + } + out := new(NodeLabelArgs) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *NodeLabelArgs) 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 *NodeResourcesFitArgs) DeepCopyInto(out *NodeResourcesFitArgs) { + *out = *in + out.TypeMeta = in.TypeMeta + if in.IgnoredResources != nil { + in, out := &in.IgnoredResources, &out.IgnoredResources + *out = make([]string, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeResourcesFitArgs. +func (in *NodeResourcesFitArgs) DeepCopy() *NodeResourcesFitArgs { + if in == nil { + return nil + } + out := new(NodeResourcesFitArgs) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *NodeResourcesFitArgs) 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 *Plugin) DeepCopyInto(out *Plugin) { *out = *in @@ -497,6 +597,41 @@ func (in *PriorityPolicy) DeepCopy() *PriorityPolicy { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RequestedToCapacityRatioArgs) DeepCopyInto(out *RequestedToCapacityRatioArgs) { + *out = *in + out.TypeMeta = in.TypeMeta + if in.Shape != nil { + in, out := &in.Shape, &out.Shape + *out = make([]UtilizationShapePoint, len(*in)) + copy(*out, *in) + } + if in.Resources != nil { + in, out := &in.Resources, &out.Resources + *out = make([]ResourceSpec, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RequestedToCapacityRatioArgs. +func (in *RequestedToCapacityRatioArgs) DeepCopy() *RequestedToCapacityRatioArgs { + if in == nil { + return nil + } + out := new(RequestedToCapacityRatioArgs) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *RequestedToCapacityRatioArgs) 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 *RequestedToCapacityRatioArguments) DeepCopyInto(out *RequestedToCapacityRatioArguments) { *out = *in @@ -644,6 +779,41 @@ func (in *ServiceAffinity) DeepCopy() *ServiceAffinity { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ServiceAffinityArgs) DeepCopyInto(out *ServiceAffinityArgs) { + *out = *in + out.TypeMeta = in.TypeMeta + if in.AffinityLabels != nil { + in, out := &in.AffinityLabels, &out.AffinityLabels + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.AntiAffinityLabelsPreference != nil { + in, out := &in.AntiAffinityLabelsPreference, &out.AntiAffinityLabelsPreference + *out = make([]string, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceAffinityArgs. +func (in *ServiceAffinityArgs) DeepCopy() *ServiceAffinityArgs { + if in == nil { + return nil + } + out := new(ServiceAffinityArgs) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ServiceAffinityArgs) 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 *ServiceAntiAffinity) DeepCopyInto(out *ServiceAntiAffinity) { *out = *in diff --git a/pkg/scheduler/factory.go b/pkg/scheduler/factory.go index 5ab9e918357..d5631a1e9a4 100644 --- a/pkg/scheduler/factory.go +++ b/pkg/scheduler/factory.go @@ -40,6 +40,7 @@ import ( policylisters "k8s.io/client-go/listers/policy/v1beta1" "k8s.io/client-go/tools/cache" "k8s.io/klog" + schedulerv1alpha2 "k8s.io/kube-scheduler/config/v1alpha2" "k8s.io/kubernetes/pkg/controller/volume/scheduling" kubefeatures "k8s.io/kubernetes/pkg/features" "k8s.io/kubernetes/pkg/scheduler/algorithmprovider" @@ -48,7 +49,6 @@ import ( "k8s.io/kubernetes/pkg/scheduler/core" frameworkplugins "k8s.io/kubernetes/pkg/scheduler/framework/plugins" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultbinder" - "k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/noderesources" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/queuesort" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" @@ -165,7 +165,7 @@ func (c *Configurator) create() (*Scheduler, error) { prof.PluginConfig = append(prof.PluginConfig, frameworkplugins.NewPluginConfig( noderesources.FitName, - noderesources.FitArgs{IgnoredResources: ignoredExtendedResources}, + schedulerv1alpha2.NodeResourcesFitArgs{IgnoredResources: ignoredExtendedResources}, ), ) } @@ -281,7 +281,7 @@ func (c *Configurator) createFromConfig(policy schedulerapi.Policy) (*Scheduler, // CLI configuration. if policy.HardPodAffinitySymmetricWeight != 0 { v := policy.HardPodAffinitySymmetricWeight - args.InterPodAffinityArgs = &interpodaffinity.Args{ + args.InterPodAffinityArgs = &schedulerv1alpha2.InterPodAffinityArgs{ HardPodAffinityWeight: &v, } } diff --git a/pkg/scheduler/framework/plugins/BUILD b/pkg/scheduler/framework/plugins/BUILD index 03dd18f3875..e1726f1f831 100644 --- a/pkg/scheduler/framework/plugins/BUILD +++ b/pkg/scheduler/framework/plugins/BUILD @@ -34,6 +34,7 @@ go_library( "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library", "//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library", + "//staging/src/k8s.io/kube-scheduler/config/v1alpha2:go_default_library", "//vendor/k8s.io/klog:go_default_library", ], ) diff --git a/pkg/scheduler/framework/plugins/interpodaffinity/BUILD b/pkg/scheduler/framework/plugins/interpodaffinity/BUILD index 7aa3ff0a393..93da955b783 100644 --- a/pkg/scheduler/framework/plugins/interpodaffinity/BUILD +++ b/pkg/scheduler/framework/plugins/interpodaffinity/BUILD @@ -19,6 +19,7 @@ go_library( "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library", + "//staging/src/k8s.io/kube-scheduler/config/v1alpha2:go_default_library", "//vendor/k8s.io/klog:go_default_library", "//vendor/k8s.io/utils/pointer:go_default_library", ], @@ -37,6 +38,7 @@ go_test( "//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", + "//staging/src/k8s.io/kube-scheduler/config/v1alpha2:go_default_library", "//vendor/k8s.io/utils/pointer:go_default_library", ], ) diff --git a/pkg/scheduler/framework/plugins/interpodaffinity/plugin.go b/pkg/scheduler/framework/plugins/interpodaffinity/plugin.go index ff8cb7f7a62..b97a56bfe5e 100644 --- a/pkg/scheduler/framework/plugins/interpodaffinity/plugin.go +++ b/pkg/scheduler/framework/plugins/interpodaffinity/plugin.go @@ -22,6 +22,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/validation/field" + schedulerv1alpha2 "k8s.io/kube-scheduler/config/v1alpha2" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" "k8s.io/utils/pointer" ) @@ -38,13 +39,6 @@ const ( MaxHardPodAffinityWeight int32 = 100 ) -// Args holds the args that are used to configure the plugin. -type Args struct { - // HardPodAffinityWeight is the scoring weight for existing pods with a - // matching hard affinity to the incoming pod. - HardPodAffinityWeight *int32 `json:"hardPodAffinityWeight,omitempty"` -} - var _ framework.PreFilterPlugin = &InterPodAffinity{} var _ framework.FilterPlugin = &InterPodAffinity{} var _ framework.PreScorePlugin = &InterPodAffinity{} @@ -52,7 +46,7 @@ var _ framework.ScorePlugin = &InterPodAffinity{} // InterPodAffinity is a plugin that checks inter pod affinity type InterPodAffinity struct { - Args + args schedulerv1alpha2.InterPodAffinityArgs sharedLister framework.SharedLister sync.Mutex } @@ -64,7 +58,7 @@ func (pl *InterPodAffinity) Name() string { // BuildArgs returns the args that were used to build the plugin. func (pl *InterPodAffinity) BuildArgs() interface{} { - return pl.Args + return pl.args } // New initializes a new plugin and returns it. @@ -75,19 +69,19 @@ func New(plArgs *runtime.Unknown, h framework.FrameworkHandle) (framework.Plugin pl := &InterPodAffinity{ sharedLister: h.SnapshotSharedLister(), } - if err := framework.DecodeInto(plArgs, &pl.Args); err != nil { + if err := framework.DecodeInto(plArgs, &pl.args); err != nil { return nil, err } - if err := validateArgs(&pl.Args); err != nil { + if err := validateArgs(&pl.args); err != nil { return nil, err } - if pl.HardPodAffinityWeight == nil { - pl.HardPodAffinityWeight = pointer.Int32Ptr(DefaultHardPodAffinityWeight) + if pl.args.HardPodAffinityWeight == nil { + pl.args.HardPodAffinityWeight = pointer.Int32Ptr(DefaultHardPodAffinityWeight) } return pl, nil } -func validateArgs(args *Args) error { +func validateArgs(args *schedulerv1alpha2.InterPodAffinityArgs) error { if args.HardPodAffinityWeight == nil { return nil } diff --git a/pkg/scheduler/framework/plugins/interpodaffinity/scoring.go b/pkg/scheduler/framework/plugins/interpodaffinity/scoring.go index 8578fb44dc0..34e4ae62167 100644 --- a/pkg/scheduler/framework/plugins/interpodaffinity/scoring.go +++ b/pkg/scheduler/framework/plugins/interpodaffinity/scoring.go @@ -137,7 +137,7 @@ func (pl *InterPodAffinity) processExistingPod(state *preScoreState, existingPod // For every hard pod affinity term of , if matches the term, // increment for every node in the cluster with the same // value as that of 's node by the constant - if *pl.HardPodAffinityWeight > 0 { + if *pl.args.HardPodAffinityWeight > 0 { terms := existingPodAffinity.PodAffinity.RequiredDuringSchedulingIgnoredDuringExecution // TODO: Uncomment this block when implement RequiredDuringSchedulingRequiredDuringExecution. //if len(existingPodAffinity.PodAffinity.RequiredDuringSchedulingRequiredDuringExecution) != 0 { @@ -145,7 +145,7 @@ func (pl *InterPodAffinity) processExistingPod(state *preScoreState, existingPod //} for i := range terms { term := &terms[i] - processedTerm, err := newWeightedAffinityTerm(existingPod, term, *pl.HardPodAffinityWeight) + processedTerm, err := newWeightedAffinityTerm(existingPod, term, *pl.args.HardPodAffinityWeight) if err != nil { return err } diff --git a/pkg/scheduler/framework/plugins/interpodaffinity/scoring_test.go b/pkg/scheduler/framework/plugins/interpodaffinity/scoring_test.go index 1faef9b01b2..f5552ead06a 100644 --- a/pkg/scheduler/framework/plugins/interpodaffinity/scoring_test.go +++ b/pkg/scheduler/framework/plugins/interpodaffinity/scoring_test.go @@ -25,6 +25,7 @@ import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + schedulerv1alpha2 "k8s.io/kube-scheduler/config/v1alpha2" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" "k8s.io/kubernetes/pkg/scheduler/internal/cache" "k8s.io/utils/pointer" @@ -520,7 +521,7 @@ func TestPreferredAffinity(t *testing.T) { state := framework.NewCycleState() snapshot := cache.NewSnapshot(test.pods, test.nodes) p := &InterPodAffinity{ - Args: Args{ + args: schedulerv1alpha2.InterPodAffinityArgs{ HardPodAffinityWeight: pointer.Int32Ptr(DefaultHardPodAffinityWeight), }, sharedLister: snapshot, diff --git a/pkg/scheduler/framework/plugins/legacy_registry.go b/pkg/scheduler/framework/plugins/legacy_registry.go index f70ec8db37c..3dee1d523c2 100644 --- a/pkg/scheduler/framework/plugins/legacy_registry.go +++ b/pkg/scheduler/framework/plugins/legacy_registry.go @@ -23,6 +23,7 @@ import ( "k8s.io/apimachinery/pkg/util/sets" utilfeature "k8s.io/apiserver/pkg/util/feature" "k8s.io/klog" + schedulerv1alpha2 "k8s.io/kube-scheduler/config/v1alpha2" "k8s.io/kubernetes/pkg/features" "k8s.io/kubernetes/pkg/scheduler/apis/config" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultpodtopologyspread" @@ -164,15 +165,15 @@ type ConfigProducerArgs struct { // Weight used for priority functions. Weight int32 // NodeLabelArgs is the args for the NodeLabel plugin. - NodeLabelArgs *nodelabel.Args + NodeLabelArgs *schedulerv1alpha2.NodeLabelArgs // RequestedToCapacityRatioArgs is the args for the RequestedToCapacityRatio plugin. - RequestedToCapacityRatioArgs *noderesources.RequestedToCapacityRatioArgs + RequestedToCapacityRatioArgs *schedulerv1alpha2.RequestedToCapacityRatioArgs // ServiceAffinityArgs is the args for the ServiceAffinity plugin. - ServiceAffinityArgs *serviceaffinity.Args + ServiceAffinityArgs *schedulerv1alpha2.ServiceAffinityArgs // NodeResourcesFitArgs is the args for the NodeResources fit filter. - NodeResourcesFitArgs *noderesources.FitArgs + NodeResourcesFitArgs *schedulerv1alpha2.NodeResourcesFitArgs // InterPodAffinityArgs is the args for InterPodAffinity plugin - InterPodAffinityArgs *interpodaffinity.Args + InterPodAffinityArgs *schedulerv1alpha2.InterPodAffinityArgs } // ConfigProducer returns the set of plugins and their configuration for a @@ -525,7 +526,7 @@ func (lr *LegacyRegistry) ProcessPredicatePolicy(policy config.PredicatePolicy, if policy.Argument.ServiceAffinity != nil { // map LabelsPresence policy to ConfigProducerArgs that's used to configure the ServiceAffinity plugin. if pluginArgs.ServiceAffinityArgs == nil { - pluginArgs.ServiceAffinityArgs = &serviceaffinity.Args{} + pluginArgs.ServiceAffinityArgs = &schedulerv1alpha2.ServiceAffinityArgs{} } pluginArgs.ServiceAffinityArgs.AffinityLabels = append(pluginArgs.ServiceAffinityArgs.AffinityLabels, policy.Argument.ServiceAffinity.Labels...) @@ -538,7 +539,7 @@ func (lr *LegacyRegistry) ProcessPredicatePolicy(policy config.PredicatePolicy, if policy.Argument.LabelsPresence != nil { // Map LabelPresence policy to ConfigProducerArgs that's used to configure the NodeLabel plugin. if pluginArgs.NodeLabelArgs == nil { - pluginArgs.NodeLabelArgs = &nodelabel.Args{} + pluginArgs.NodeLabelArgs = &schedulerv1alpha2.NodeLabelArgs{} } if policy.Argument.LabelsPresence.Presence { pluginArgs.NodeLabelArgs.PresentLabels = append(pluginArgs.NodeLabelArgs.PresentLabels, policy.Argument.LabelsPresence.Labels...) @@ -586,7 +587,7 @@ func (lr *LegacyRegistry) ProcessPriorityPolicy(policy config.PriorityPolicy, co // This name is then used to find the registered plugin and run the plugin instead of the priority. priorityName = serviceaffinity.Name if configProducerArgs.ServiceAffinityArgs == nil { - configProducerArgs.ServiceAffinityArgs = &serviceaffinity.Args{} + configProducerArgs.ServiceAffinityArgs = &schedulerv1alpha2.ServiceAffinityArgs{} } configProducerArgs.ServiceAffinityArgs.AntiAffinityLabelsPreference = append( configProducerArgs.ServiceAffinityArgs.AntiAffinityLabelsPreference, @@ -600,7 +601,7 @@ func (lr *LegacyRegistry) ProcessPriorityPolicy(policy config.PriorityPolicy, co // This name is then used to find the registered plugin and run the plugin instead of the priority. priorityName = nodelabel.Name if configProducerArgs.NodeLabelArgs == nil { - configProducerArgs.NodeLabelArgs = &nodelabel.Args{} + configProducerArgs.NodeLabelArgs = &schedulerv1alpha2.NodeLabelArgs{} } if policy.Argument.LabelPreference.Presence { configProducerArgs.NodeLabelArgs.PresentLabelsPreference = append( @@ -616,9 +617,27 @@ func (lr *LegacyRegistry) ProcessPriorityPolicy(policy config.PriorityPolicy, co } if policy.Argument.RequestedToCapacityRatioArguments != nil { - configProducerArgs.RequestedToCapacityRatioArgs = &noderesources.RequestedToCapacityRatioArgs{ - RequestedToCapacityRatioArguments: *policy.Argument.RequestedToCapacityRatioArguments, + policyArgs := policy.Argument.RequestedToCapacityRatioArguments + args := &schedulerv1alpha2.RequestedToCapacityRatioArgs{} + + args.Shape = make([]schedulerv1alpha2.UtilizationShapePoint, len(policyArgs.Shape)) + for i, s := range policyArgs.Shape { + args.Shape[i] = schedulerv1alpha2.UtilizationShapePoint{ + Utilization: s.Utilization, + Score: s.Score, + } } + + args.Resources = make([]schedulerv1alpha2.ResourceSpec, len(policyArgs.Resources)) + for i, r := range policyArgs.Resources { + args.Resources[i] = schedulerv1alpha2.ResourceSpec{ + Name: r.Name, + Weight: r.Weight, + } + } + + configProducerArgs.RequestedToCapacityRatioArgs = args + // We do not allow specifying the name for custom plugins, see #83472 priorityName = noderesources.RequestedToCapacityRatioName } diff --git a/pkg/scheduler/framework/plugins/nodelabel/BUILD b/pkg/scheduler/framework/plugins/nodelabel/BUILD index 02c13c001b8..1f7bbae2dd8 100644 --- a/pkg/scheduler/framework/plugins/nodelabel/BUILD +++ b/pkg/scheduler/framework/plugins/nodelabel/BUILD @@ -10,6 +10,7 @@ go_library( "//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", + "//staging/src/k8s.io/kube-scheduler/config/v1alpha2:go_default_library", ], ) diff --git a/pkg/scheduler/framework/plugins/nodelabel/node_label.go b/pkg/scheduler/framework/plugins/nodelabel/node_label.go index 1b6701d49ba..86c286be91e 100644 --- a/pkg/scheduler/framework/plugins/nodelabel/node_label.go +++ b/pkg/scheduler/framework/plugins/nodelabel/node_label.go @@ -23,6 +23,7 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" + schedulerv1alpha2 "k8s.io/kube-scheduler/config/v1alpha2" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" ) @@ -34,18 +35,6 @@ const ( ErrReasonPresenceViolated = "node(s) didn't have the requested labels" ) -// Args holds the args that are used to configure the plugin. -type Args struct { - // PresentLabels should be present for the node to be considered a fit for hosting the pod - PresentLabels []string `json:"presentLabels,omitempty"` - // AbsentLabels should be absent for the node to be considered a fit for hosting the pod - AbsentLabels []string `json:"absentLabels,omitempty"` - // Nodes that have labels in the list will get a higher score. - PresentLabelsPreference []string `json:"presentLabelsPreference,omitempty"` - // Nodes that don't have labels in the list will get a higher score. - AbsentLabelsPreference []string `json:"absentLabelsPreference,omitempty"` -} - // validateArgs validates that presentLabels and absentLabels do not conflict. func validateNoConflict(presentLabels []string, absentLabels []string) error { m := make(map[string]struct{}, len(presentLabels)) @@ -62,7 +51,7 @@ func validateNoConflict(presentLabels []string, absentLabels []string) error { // New initializes a new plugin and returns it. func New(plArgs *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) { - args := Args{} + args := schedulerv1alpha2.NodeLabelArgs{} if err := framework.DecodeInto(plArgs, &args); err != nil { return nil, err } @@ -74,14 +63,14 @@ func New(plArgs *runtime.Unknown, handle framework.FrameworkHandle) (framework.P } return &NodeLabel{ handle: handle, - Args: args, + args: args, }, nil } // NodeLabel checks whether a pod can fit based on the node labels which match a filter that it requests. type NodeLabel struct { handle framework.FrameworkHandle - Args + args schedulerv1alpha2.NodeLabelArgs } var _ framework.FilterPlugin = &NodeLabel{} @@ -116,7 +105,7 @@ func (pl *NodeLabel) Filter(ctx context.Context, _ *framework.CycleState, pod *v } return true } - if check(pl.PresentLabels, true) && check(pl.AbsentLabels, false) { + if check(pl.args.PresentLabels, true) && check(pl.args.AbsentLabels, false) { return nil } @@ -132,18 +121,18 @@ func (pl *NodeLabel) Score(ctx context.Context, state *framework.CycleState, pod node := nodeInfo.Node() score := int64(0) - for _, label := range pl.PresentLabelsPreference { + for _, label := range pl.args.PresentLabelsPreference { if labels.Set(node.Labels).Has(label) { score += framework.MaxNodeScore } } - for _, label := range pl.AbsentLabelsPreference { + for _, label := range pl.args.AbsentLabelsPreference { if !labels.Set(node.Labels).Has(label) { score += framework.MaxNodeScore } } // Take average score for each label to ensure the score doesn't exceed MaxNodeScore. - score /= int64(len(pl.PresentLabelsPreference) + len(pl.AbsentLabelsPreference)) + score /= int64(len(pl.args.PresentLabelsPreference) + len(pl.args.AbsentLabelsPreference)) return score, nil } diff --git a/pkg/scheduler/framework/plugins/noderesources/BUILD b/pkg/scheduler/framework/plugins/noderesources/BUILD index be939f5da06..3cb56da1c7d 100644 --- a/pkg/scheduler/framework/plugins/noderesources/BUILD +++ b/pkg/scheduler/framework/plugins/noderesources/BUILD @@ -26,6 +26,7 @@ go_library( "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library", "//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library", + "//staging/src/k8s.io/kube-scheduler/config/v1alpha2:go_default_library", "//vendor/k8s.io/klog:go_default_library", ], ) @@ -66,6 +67,7 @@ go_test( "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", "//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library", "//staging/src/k8s.io/component-base/featuregate/testing:go_default_library", + "//staging/src/k8s.io/kube-scheduler/config/v1alpha2:go_default_library", "//vendor/github.com/stretchr/testify/assert:go_default_library", ], ) diff --git a/pkg/scheduler/framework/plugins/noderesources/fit.go b/pkg/scheduler/framework/plugins/noderesources/fit.go index 22215e6521c..6227ea73705 100644 --- a/pkg/scheduler/framework/plugins/noderesources/fit.go +++ b/pkg/scheduler/framework/plugins/noderesources/fit.go @@ -20,10 +20,11 @@ import ( "context" "fmt" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/sets" utilfeature "k8s.io/apiserver/pkg/util/feature" + schedulerv1alpha2 "k8s.io/kube-scheduler/config/v1alpha2" v1helper "k8s.io/kubernetes/pkg/apis/core/v1/helper" "k8s.io/kubernetes/pkg/features" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" @@ -46,13 +47,6 @@ type Fit struct { ignoredResources sets.String } -// FitArgs holds the args that are used to configure the plugin. -type FitArgs struct { - // IgnoredResources is the list of resources that NodeResources fit filter - // should ignore. - IgnoredResources []string `json:"ignoredResources,omitempty"` -} - // preFilterState computed at PreFilter and used at Filter. type preFilterState struct { framework.Resource @@ -68,6 +62,18 @@ func (f *Fit) Name() string { return FitName } +// NewFit initializes a new plugin and returns it. +func NewFit(plArgs *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { + args := &schedulerv1alpha2.NodeResourcesFitArgs{} + if err := framework.DecodeInto(plArgs, args); err != nil { + return nil, err + } + + fit := &Fit{} + fit.ignoredResources = sets.NewString(args.IgnoredResources...) + return fit, nil +} + // computePodResourceRequest returns a framework.Resource that covers the largest // width in each resource dimension. Because init-containers run sequentially, we collect // the max in each dimension iteratively. In contrast, we sum the resource vectors for @@ -252,15 +258,3 @@ func fitsRequest(podRequest *preFilterState, nodeInfo *framework.NodeInfo, ignor return insufficientResources } - -// NewFit initializes a new plugin and returns it. -func NewFit(plArgs *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { - args := &FitArgs{} - if err := framework.DecodeInto(plArgs, args); err != nil { - return nil, err - } - - fit := &Fit{} - fit.ignoredResources = sets.NewString(args.IgnoredResources...) - return fit, nil -} diff --git a/pkg/scheduler/framework/plugins/noderesources/requested_to_capacity_ratio.go b/pkg/scheduler/framework/plugins/noderesources/requested_to_capacity_ratio.go index 43f1c917e3d..9dc5d293505 100644 --- a/pkg/scheduler/framework/plugins/noderesources/requested_to_capacity_ratio.go +++ b/pkg/scheduler/framework/plugins/noderesources/requested_to_capacity_ratio.go @@ -24,6 +24,7 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/klog" + schedulerv1alpha2 "k8s.io/kube-scheduler/config/v1alpha2" "k8s.io/kubernetes/pkg/scheduler/apis/config" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" ) @@ -37,11 +38,6 @@ const ( maxScore = framework.MaxNodeScore ) -// RequestedToCapacityRatioArgs holds the args that are used to configure the plugin. -type RequestedToCapacityRatioArgs struct { - config.RequestedToCapacityRatioArguments -} - type functionShape []functionShapePoint type functionShapePoint struct { @@ -53,7 +49,7 @@ type functionShapePoint struct { // NewRequestedToCapacityRatio initializes a new plugin and returns it. func NewRequestedToCapacityRatio(plArgs *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) { - args := &config.RequestedToCapacityRatioArguments{} + args := &schedulerv1alpha2.RequestedToCapacityRatioArgs{} if err := framework.DecodeInto(plArgs, args); err != nil { return nil, err } diff --git a/pkg/scheduler/framework/plugins/noderesources/requested_to_capacity_ratio_test.go b/pkg/scheduler/framework/plugins/noderesources/requested_to_capacity_ratio_test.go index f386f1ce153..29abbe58154 100644 --- a/pkg/scheduler/framework/plugins/noderesources/requested_to_capacity_ratio_test.go +++ b/pkg/scheduler/framework/plugins/noderesources/requested_to_capacity_ratio_test.go @@ -25,6 +25,7 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/runtime" + schedulerv1alpha2 "k8s.io/kube-scheduler/config/v1alpha2" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" "k8s.io/kubernetes/pkg/scheduler/internal/cache" ) @@ -607,3 +608,49 @@ func TestResourceBinPackingMultipleExtended(t *testing.T) { }) } } + +// TODO compatibility test once the plugin args move to v1beta1. +// UtilizationShapePoint and ResourceSpec fields of the plugin args struct are not annotated +// with JSON tags in v1alpha2 to maintain backward compatibility with the args shipped with v1.18. +// See https://github.com/kubernetes/kubernetes/pull/88585#discussion_r405021905 + +func TestPluginArgsJSONEncodingIsCaseInsensitive(t *testing.T) { + rawArgs := &runtime.Unknown{Raw: []byte(` + { + "shape": [{"Utilization": 1, "Score": 1}, {"utilization": 2, "score": 2}], + "resources": [{"Name":"a","Weight":1},{"name":"b","weight":2}] + } +`)} + + args := &schedulerv1alpha2.RequestedToCapacityRatioArgs{} + if err := framework.DecodeInto(rawArgs, args); err != nil { + t.Fatalf("expected no error, got: %v", err) + } + + expectedArgs := &schedulerv1alpha2.RequestedToCapacityRatioArgs{ + Shape: []schedulerv1alpha2.UtilizationShapePoint{ + { + Utilization: 1, + Score: 1, + }, + { + Utilization: 2, + Score: 2, + }, + }, + Resources: []schedulerv1alpha2.ResourceSpec{ + { + Name: "a", + Weight: 1, + }, + { + Name: "b", + Weight: 2, + }, + }, + } + + if !reflect.DeepEqual(expectedArgs, args) { + t.Errorf("expected: \n\t%#v,\ngot: \n\t%#v", expectedArgs, args) + } +} diff --git a/pkg/scheduler/framework/plugins/serviceaffinity/BUILD b/pkg/scheduler/framework/plugins/serviceaffinity/BUILD index 64249e7e5d3..ba3f7b374ab 100644 --- a/pkg/scheduler/framework/plugins/serviceaffinity/BUILD +++ b/pkg/scheduler/framework/plugins/serviceaffinity/BUILD @@ -12,6 +12,7 @@ go_library( "//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", "//staging/src/k8s.io/client-go/listers/core/v1:go_default_library", + "//staging/src/k8s.io/kube-scheduler/config/v1alpha2:go_default_library", ], ) @@ -25,6 +26,7 @@ go_test( "//pkg/scheduler/internal/cache:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", + "//staging/src/k8s.io/kube-scheduler/config/v1alpha2:go_default_library", ], ) diff --git a/pkg/scheduler/framework/plugins/serviceaffinity/service_affinity.go b/pkg/scheduler/framework/plugins/serviceaffinity/service_affinity.go index 9bcf374adcb..77d766421d1 100644 --- a/pkg/scheduler/framework/plugins/serviceaffinity/service_affinity.go +++ b/pkg/scheduler/framework/plugins/serviceaffinity/service_affinity.go @@ -24,6 +24,7 @@ import ( "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" corelisters "k8s.io/client-go/listers/core/v1" + schedulerv1alpha2 "k8s.io/kube-scheduler/config/v1alpha2" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/helper" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" ) @@ -40,16 +41,6 @@ const ( ErrReason = "node(s) didn't match service affinity" ) -// Args holds the args that are used to configure the plugin. -type Args struct { - // Labels are homogeneous for pods that are scheduled to a node. - // (i.e. it returns true IFF this pod can be added to this node such that all other pods in - // the same service are running on nodes with the exact same values for Labels). - AffinityLabels []string `json:"affinityLabels,omitempty"` - // AntiAffinityLabelsPreference are the labels to consider for service anti affinity scoring. - AntiAffinityLabelsPreference []string `json:"antiAffinityLabelsPreference,omitempty"` -} - // preFilterState computed at PreFilter and used at Filter. type preFilterState struct { matchingPodList []*v1.Pod @@ -73,7 +64,7 @@ func (s *preFilterState) Clone() framework.StateData { // New initializes a new plugin and returns it. func New(plArgs *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) { - args := Args{} + args := schedulerv1alpha2.ServiceAffinityArgs{} if err := framework.DecodeInto(plArgs, &args); err != nil { return nil, err } @@ -89,7 +80,7 @@ func New(plArgs *runtime.Unknown, handle framework.FrameworkHandle) (framework.P // ServiceAffinity is a plugin that checks service affinity. type ServiceAffinity struct { - args Args + args schedulerv1alpha2.ServiceAffinityArgs sharedLister framework.SharedLister serviceLister corelisters.ServiceLister } diff --git a/pkg/scheduler/framework/plugins/serviceaffinity/service_affinity_test.go b/pkg/scheduler/framework/plugins/serviceaffinity/service_affinity_test.go index 97c06985b16..a6809109fba 100644 --- a/pkg/scheduler/framework/plugins/serviceaffinity/service_affinity_test.go +++ b/pkg/scheduler/framework/plugins/serviceaffinity/service_affinity_test.go @@ -24,6 +24,7 @@ import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + schedulerv1alpha2 "k8s.io/kube-scheduler/config/v1alpha2" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" fakeframework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1/fake" "k8s.io/kubernetes/pkg/scheduler/internal/cache" @@ -164,7 +165,7 @@ func TestServiceAffinity(t *testing.T) { p := &ServiceAffinity{ sharedLister: snapshot, serviceLister: fakeframework.ServiceLister(test.services), - args: Args{ + args: schedulerv1alpha2.ServiceAffinityArgs{ AffinityLabels: test.labels, }, } @@ -388,7 +389,7 @@ func TestServiceAffinityScore(t *testing.T) { p := &ServiceAffinity{ sharedLister: snapshot, serviceLister: serviceLister, - args: Args{ + args: schedulerv1alpha2.ServiceAffinityArgs{ AntiAffinityLabelsPreference: test.labels, }, } @@ -605,7 +606,7 @@ func TestPreFilterDisabled(t *testing.T) { node := v1.Node{} nodeInfo.SetNode(&node) p := &ServiceAffinity{ - args: Args{ + args: schedulerv1alpha2.ServiceAffinityArgs{ AffinityLabels: []string{"region"}, }, } diff --git a/staging/src/k8s.io/kube-scheduler/config/v1alpha2/BUILD b/staging/src/k8s.io/kube-scheduler/config/v1alpha2/BUILD index 40f30aec12a..1d450e57236 100644 --- a/staging/src/k8s.io/kube-scheduler/config/v1alpha2/BUILD +++ b/staging/src/k8s.io/kube-scheduler/config/v1alpha2/BUILD @@ -6,6 +6,7 @@ go_library( "doc.go", "register.go", "types.go", + "types_pluginargs.go", "zz_generated.deepcopy.go", ], importmap = "k8s.io/kubernetes/vendor/k8s.io/kube-scheduler/config/v1alpha2", diff --git a/staging/src/k8s.io/kube-scheduler/config/v1alpha2/register.go b/staging/src/k8s.io/kube-scheduler/config/v1alpha2/register.go index d5715c4e43b..944d5d295db 100644 --- a/staging/src/k8s.io/kube-scheduler/config/v1alpha2/register.go +++ b/staging/src/k8s.io/kube-scheduler/config/v1alpha2/register.go @@ -38,6 +38,11 @@ var ( func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, &KubeSchedulerConfiguration{}, + &InterPodAffinityArgs{}, + &NodeLabelArgs{}, + &NodeResourcesFitArgs{}, + &RequestedToCapacityRatioArgs{}, + &ServiceAffinityArgs{}, ) return nil } diff --git a/staging/src/k8s.io/kube-scheduler/config/v1alpha2/types_pluginargs.go b/staging/src/k8s.io/kube-scheduler/config/v1alpha2/types_pluginargs.go new file mode 100644 index 00000000000..c36c1f37504 --- /dev/null +++ b/staging/src/k8s.io/kube-scheduler/config/v1alpha2/types_pluginargs.go @@ -0,0 +1,115 @@ +/* +Copyright 2020 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 v1alpha2 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// InterPodAffinityArgs holds arguments used to configure the InterPodAffinity plugin. +type InterPodAffinityArgs struct { + metav1.TypeMeta `json:",inline"` + + // HardPodAffinityWeight is the scoring weight for existing pods with a + // matching hard affinity to the incoming pod. + HardPodAffinityWeight *int32 `json:"hardPodAffinityWeight,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// NodeLabelArgs holds arguments that used to configure the NodeLabel plugin. +type NodeLabelArgs struct { + metav1.TypeMeta `json:",inline"` + + // PresentLabels should be present for the node to be considered a fit for hosting the pod + // +listType=atomic + PresentLabels []string `json:"presentLabels,omitempty"` + // AbsentLabels should be absent for the node to be considered a fit for hosting the pod + // +listType=atomic + AbsentLabels []string `json:"absentLabels,omitempty"` + // Nodes that have labels in the list will get a higher score. + // +listType=atomic + PresentLabelsPreference []string `json:"presentLabelsPreference,omitempty"` + // Nodes that don't have labels in the list will get a higher score. + // +listType=atomic + AbsentLabelsPreference []string `json:"absentLabelsPreference,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// NodeResourcesFitArgs holds arguments used to configure the NodeResourcesFit plugin. +type NodeResourcesFitArgs struct { + metav1.TypeMeta `json:",inline"` + + // IgnoredResources is the list of resources that NodeResources fit filter + // should ignore. + // +listType=atomic + IgnoredResources []string `json:"ignoredResources,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// RequestedToCapacityRatioArgs holds arguments used to configure RequestedToCapacityRatio plugin. +type RequestedToCapacityRatioArgs struct { + metav1.TypeMeta `json:",inline"` + + // Points defining priority function shape + // +listType=atomic + Shape []UtilizationShapePoint `json:"shape"` + // Resources to be managed + // +listType=atomic + Resources []ResourceSpec `json:"resources,omitempty"` +} + +// TODO add JSON tags and backward compatible conversion in v1beta1. +// UtilizationShapePoint and ResourceSpec fields are not annotated with JSON tags in v1alpha2 +// to maintain backward compatibility with the args shipped with v1.18. +// See https://github.com/kubernetes/kubernetes/pull/88585#discussion_r405021905 + +// UtilizationShapePoint represents single point of priority function shape. +type UtilizationShapePoint struct { + // Utilization (x axis). Valid values are 0 to 100. Fully utilized node maps to 100. + Utilization int32 + // Score assigned to given utilization (y axis). Valid values are 0 to 10. + Score int32 +} + +// ResourceSpec represents single resource and weight for bin packing of priority RequestedToCapacityRatioArguments. +type ResourceSpec struct { + // Name of the resource to be managed by RequestedToCapacityRatio function. + Name string + // Weight of the resource. + Weight int64 +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// ServiceAffinityArgs holds arguments used to configure the ServiceAffinity plugin. +type ServiceAffinityArgs struct { + metav1.TypeMeta `json:",inline"` + + // AffinityLabels are homogeneous for pods that are scheduled to a node. + // (i.e. it returns true IFF this pod can be added to this node such that all other pods in + // the same service are running on nodes with the exact same values for Labels). + // +listType=atomic + AffinityLabels []string `json:"affinityLabels,omitempty"` + // AntiAffinityLabelsPreference are the labels to consider for service anti affinity scoring. + // +listType=atomic + AntiAffinityLabelsPreference []string `json:"antiAffinityLabelsPreference,omitempty"` +} diff --git a/staging/src/k8s.io/kube-scheduler/config/v1alpha2/zz_generated.deepcopy.go b/staging/src/k8s.io/kube-scheduler/config/v1alpha2/zz_generated.deepcopy.go index afd67b9d390..f0189d8fdf4 100644 --- a/staging/src/k8s.io/kube-scheduler/config/v1alpha2/zz_generated.deepcopy.go +++ b/staging/src/k8s.io/kube-scheduler/config/v1alpha2/zz_generated.deepcopy.go @@ -25,6 +25,36 @@ import ( v1 "k8s.io/kube-scheduler/config/v1" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *InterPodAffinityArgs) DeepCopyInto(out *InterPodAffinityArgs) { + *out = *in + out.TypeMeta = in.TypeMeta + if in.HardPodAffinityWeight != nil { + in, out := &in.HardPodAffinityWeight, &out.HardPodAffinityWeight + *out = new(int32) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new InterPodAffinityArgs. +func (in *InterPodAffinityArgs) DeepCopy() *InterPodAffinityArgs { + if in == nil { + return nil + } + out := new(InterPodAffinityArgs) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *InterPodAffinityArgs) 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 *KubeSchedulerConfiguration) DeepCopyInto(out *KubeSchedulerConfiguration) { *out = *in @@ -152,6 +182,81 @@ func (in *KubeSchedulerProfile) DeepCopy() *KubeSchedulerProfile { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NodeLabelArgs) DeepCopyInto(out *NodeLabelArgs) { + *out = *in + out.TypeMeta = in.TypeMeta + if in.PresentLabels != nil { + in, out := &in.PresentLabels, &out.PresentLabels + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.AbsentLabels != nil { + in, out := &in.AbsentLabels, &out.AbsentLabels + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.PresentLabelsPreference != nil { + in, out := &in.PresentLabelsPreference, &out.PresentLabelsPreference + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.AbsentLabelsPreference != nil { + in, out := &in.AbsentLabelsPreference, &out.AbsentLabelsPreference + *out = make([]string, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeLabelArgs. +func (in *NodeLabelArgs) DeepCopy() *NodeLabelArgs { + if in == nil { + return nil + } + out := new(NodeLabelArgs) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *NodeLabelArgs) 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 *NodeResourcesFitArgs) DeepCopyInto(out *NodeResourcesFitArgs) { + *out = *in + out.TypeMeta = in.TypeMeta + if in.IgnoredResources != nil { + in, out := &in.IgnoredResources, &out.IgnoredResources + *out = make([]string, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeResourcesFitArgs. +func (in *NodeResourcesFitArgs) DeepCopy() *NodeResourcesFitArgs { + if in == nil { + return nil + } + out := new(NodeResourcesFitArgs) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *NodeResourcesFitArgs) 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 *Plugin) DeepCopyInto(out *Plugin) { *out = *in @@ -290,3 +395,105 @@ func (in *Plugins) DeepCopy() *Plugins { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RequestedToCapacityRatioArgs) DeepCopyInto(out *RequestedToCapacityRatioArgs) { + *out = *in + out.TypeMeta = in.TypeMeta + if in.Shape != nil { + in, out := &in.Shape, &out.Shape + *out = make([]UtilizationShapePoint, len(*in)) + copy(*out, *in) + } + if in.Resources != nil { + in, out := &in.Resources, &out.Resources + *out = make([]ResourceSpec, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RequestedToCapacityRatioArgs. +func (in *RequestedToCapacityRatioArgs) DeepCopy() *RequestedToCapacityRatioArgs { + if in == nil { + return nil + } + out := new(RequestedToCapacityRatioArgs) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *RequestedToCapacityRatioArgs) 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 *ResourceSpec) DeepCopyInto(out *ResourceSpec) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResourceSpec. +func (in *ResourceSpec) DeepCopy() *ResourceSpec { + if in == nil { + return nil + } + out := new(ResourceSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ServiceAffinityArgs) DeepCopyInto(out *ServiceAffinityArgs) { + *out = *in + out.TypeMeta = in.TypeMeta + if in.AffinityLabels != nil { + in, out := &in.AffinityLabels, &out.AffinityLabels + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.AntiAffinityLabelsPreference != nil { + in, out := &in.AntiAffinityLabelsPreference, &out.AntiAffinityLabelsPreference + *out = make([]string, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceAffinityArgs. +func (in *ServiceAffinityArgs) DeepCopy() *ServiceAffinityArgs { + if in == nil { + return nil + } + out := new(ServiceAffinityArgs) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ServiceAffinityArgs) 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 *UtilizationShapePoint) DeepCopyInto(out *UtilizationShapePoint) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UtilizationShapePoint. +func (in *UtilizationShapePoint) DeepCopy() *UtilizationShapePoint { + if in == nil { + return nil + } + out := new(UtilizationShapePoint) + in.DeepCopyInto(out) + return out +}