From c33c4fffd1dce8fa994c4616fc72b8c864714400 Mon Sep 17 00:00:00 2001 From: notpad Date: Wed, 25 Dec 2019 12:18:32 +0800 Subject: [PATCH] Move RequestedToCapacityRatio to plugins/noderesources --- pkg/scheduler/BUILD | 1 - pkg/scheduler/algorithm_factory.go | 6 +-- pkg/scheduler/framework/plugins/BUILD | 2 - .../framework/plugins/noderesources/BUILD | 2 + .../requested_to_capacity_ratio.go | 18 ++++---- .../requested_to_capacity_ratio_test.go | 21 +-------- pkg/scheduler/framework/plugins/registry.go | 37 ++++++++-------- .../plugins/requestedtocapacityratio/BUILD | 43 ------------------- 8 files changed, 34 insertions(+), 96 deletions(-) rename pkg/scheduler/framework/plugins/{requestedtocapacityratio => noderesources}/requested_to_capacity_ratio.go (81%) rename pkg/scheduler/framework/plugins/{requestedtocapacityratio => noderesources}/requested_to_capacity_ratio_test.go (85%) delete mode 100644 pkg/scheduler/framework/plugins/requestedtocapacityratio/BUILD diff --git a/pkg/scheduler/BUILD b/pkg/scheduler/BUILD index 3ad9b9ae42b..c2538ecbacd 100644 --- a/pkg/scheduler/BUILD +++ b/pkg/scheduler/BUILD @@ -24,7 +24,6 @@ go_library( "//pkg/scheduler/framework/plugins/interpodaffinity:go_default_library", "//pkg/scheduler/framework/plugins/nodelabel:go_default_library", "//pkg/scheduler/framework/plugins/noderesources:go_default_library", - "//pkg/scheduler/framework/plugins/requestedtocapacityratio:go_default_library", "//pkg/scheduler/framework/plugins/serviceaffinity:go_default_library", "//pkg/scheduler/framework/v1alpha1:go_default_library", "//pkg/scheduler/internal/cache:go_default_library", diff --git a/pkg/scheduler/algorithm_factory.go b/pkg/scheduler/algorithm_factory.go index a3d99cbdd55..ac6a112f684 100644 --- a/pkg/scheduler/algorithm_factory.go +++ b/pkg/scheduler/algorithm_factory.go @@ -31,7 +31,7 @@ import ( schedulerapi "k8s.io/kubernetes/pkg/scheduler/apis/config" "k8s.io/kubernetes/pkg/scheduler/framework/plugins" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodelabel" - "k8s.io/kubernetes/pkg/scheduler/framework/plugins/requestedtocapacityratio" + "k8s.io/kubernetes/pkg/scheduler/framework/plugins/noderesources" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/serviceaffinity" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" schedulerlisters "k8s.io/kubernetes/pkg/scheduler/listers" @@ -402,7 +402,7 @@ func RegisterCustomPriorityFunction(policy schedulerapi.PriorityPolicy, configPr } } else if policy.Argument.RequestedToCapacityRatioArguments != nil { scoringFunctionShape, resources := buildScoringFunctionShapeFromRequestedToCapacityRatioArguments(policy.Argument.RequestedToCapacityRatioArguments) - configProducerArgs.RequestedToCapacityRatioArgs = &requestedtocapacityratio.Args{ + configProducerArgs.RequestedToCapacityRatioArgs = &noderesources.RequestedToCapacityRatioArgs{ FunctionShape: scoringFunctionShape, ResourceToWeightMap: resources, } @@ -414,7 +414,7 @@ func RegisterCustomPriorityFunction(policy schedulerapi.PriorityPolicy, configPr Weight: policy.Weight, } // We do not allow specifying the name for custom plugins, see #83472 - name = requestedtocapacityratio.Name + name = noderesources.RequestedToCapacityRatioName } } else if existingPcf, ok := priorityFunctionMap[name]; ok { klog.V(2).Infof("Priority type %s already registered, reusing.", name) diff --git a/pkg/scheduler/framework/plugins/BUILD b/pkg/scheduler/framework/plugins/BUILD index dd0c71fed44..79749b0d57a 100644 --- a/pkg/scheduler/framework/plugins/BUILD +++ b/pkg/scheduler/framework/plugins/BUILD @@ -21,7 +21,6 @@ go_library( "//pkg/scheduler/framework/plugins/nodeunschedulable:go_default_library", "//pkg/scheduler/framework/plugins/nodevolumelimits:go_default_library", "//pkg/scheduler/framework/plugins/podtopologyspread:go_default_library", - "//pkg/scheduler/framework/plugins/requestedtocapacityratio:go_default_library", "//pkg/scheduler/framework/plugins/serviceaffinity:go_default_library", "//pkg/scheduler/framework/plugins/tainttoleration:go_default_library", "//pkg/scheduler/framework/plugins/volumebinding:go_default_library", @@ -59,7 +58,6 @@ filegroup( "//pkg/scheduler/framework/plugins/nodeunschedulable:all-srcs", "//pkg/scheduler/framework/plugins/nodevolumelimits:all-srcs", "//pkg/scheduler/framework/plugins/podtopologyspread:all-srcs", - "//pkg/scheduler/framework/plugins/requestedtocapacityratio:all-srcs", "//pkg/scheduler/framework/plugins/serviceaffinity:all-srcs", "//pkg/scheduler/framework/plugins/tainttoleration:all-srcs", "//pkg/scheduler/framework/plugins/volumebinding:all-srcs", diff --git a/pkg/scheduler/framework/plugins/noderesources/BUILD b/pkg/scheduler/framework/plugins/noderesources/BUILD index aecbcb1dc8b..8d5af0b1847 100644 --- a/pkg/scheduler/framework/plugins/noderesources/BUILD +++ b/pkg/scheduler/framework/plugins/noderesources/BUILD @@ -7,6 +7,7 @@ go_library( "fit.go", "least_allocated.go", "most_allocated.go", + "requested_to_capacity_ratio.go", "test_util.go", ], importpath = "k8s.io/kubernetes/pkg/scheduler/framework/plugins/noderesources", @@ -47,6 +48,7 @@ go_test( "fit_test.go", "least_allocated_test.go", "most_allocated_test.go", + "requested_to_capacity_ratio_test.go", ], embed = [":go_default_library"], deps = [ diff --git a/pkg/scheduler/framework/plugins/requestedtocapacityratio/requested_to_capacity_ratio.go b/pkg/scheduler/framework/plugins/noderesources/requested_to_capacity_ratio.go similarity index 81% rename from pkg/scheduler/framework/plugins/requestedtocapacityratio/requested_to_capacity_ratio.go rename to pkg/scheduler/framework/plugins/noderesources/requested_to_capacity_ratio.go index 35568aef442..33ef761af12 100644 --- a/pkg/scheduler/framework/plugins/requestedtocapacityratio/requested_to_capacity_ratio.go +++ b/pkg/scheduler/framework/plugins/noderesources/requested_to_capacity_ratio.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package requestedtocapacityratio +package noderesources import ( "context" @@ -27,18 +27,18 @@ import ( framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" ) -// Name of this plugin. -const Name = "RequestedToCapacityRatio" +// RequestedToCapacityRatioName is the name of this plugin. +const RequestedToCapacityRatioName = "RequestedToCapacityRatio" -// Args holds the args that are used to configure the plugin. -type Args struct { +// RequestedToCapacityRatioArgs holds the args that are used to configure the plugin. +type RequestedToCapacityRatioArgs struct { FunctionShape priorities.FunctionShape ResourceToWeightMap priorities.ResourceToWeightMap } -// New initializes a new plugin and returns it. -func New(plArgs *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) { - args := &Args{} +// NewRequestedToCapacityRatio initializes a new plugin and returns it. +func NewRequestedToCapacityRatio(plArgs *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) { + args := &RequestedToCapacityRatioArgs{} if err := framework.DecodeInto(plArgs, args); err != nil { return nil, err } @@ -60,7 +60,7 @@ var _ framework.ScorePlugin = &RequestedToCapacityRatio{} // Name returns name of the plugin. It is used in logs, etc. func (pl *RequestedToCapacityRatio) Name() string { - return Name + return RequestedToCapacityRatioName } // Score invoked at the score extension point. diff --git a/pkg/scheduler/framework/plugins/requestedtocapacityratio/requested_to_capacity_ratio_test.go b/pkg/scheduler/framework/plugins/noderesources/requested_to_capacity_ratio_test.go similarity index 85% rename from pkg/scheduler/framework/plugins/requestedtocapacityratio/requested_to_capacity_ratio_test.go rename to pkg/scheduler/framework/plugins/noderesources/requested_to_capacity_ratio_test.go index 300da199c78..96ed711dd0c 100644 --- a/pkg/scheduler/framework/plugins/requestedtocapacityratio/requested_to_capacity_ratio_test.go +++ b/pkg/scheduler/framework/plugins/noderesources/requested_to_capacity_ratio_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package requestedtocapacityratio +package noderesources import ( "context" @@ -23,7 +23,6 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1" nodeinfosnapshot "k8s.io/kubernetes/pkg/scheduler/nodeinfo/snapshot" @@ -68,7 +67,7 @@ func TestRequestedToCapacityRatio(t *testing.T) { snapshot := nodeinfosnapshot.NewSnapshot(nodeinfosnapshot.CreateNodeInfoMap(test.scheduledPods, test.nodes)) fh, _ := framework.NewFramework(nil, nil, nil, framework.WithSnapshotSharedLister(snapshot)) args := &runtime.Unknown{Raw: []byte(`{"FunctionShape" : [{"Utilization" : 0, "Score" : 100}, {"Utilization" : 100, "Score" : 0}], "ResourceToWeightMap" : {"memory" : 1, "cpu" : 1}}`)} - p, _ := New(args, fh) + p, _ := NewRequestedToCapacityRatio(args, fh) var gotPriorities framework.NodeScoreList for _, n := range test.nodes { @@ -86,22 +85,6 @@ func TestRequestedToCapacityRatio(t *testing.T) { } } -func makeNode(name string, milliCPU, memory int64) *v1.Node { - return &v1.Node{ - ObjectMeta: metav1.ObjectMeta{Name: name}, - Status: v1.NodeStatus{ - Capacity: v1.ResourceList{ - v1.ResourceCPU: *resource.NewMilliQuantity(milliCPU, resource.DecimalSI), - v1.ResourceMemory: *resource.NewQuantity(memory, resource.BinarySI), - }, - Allocatable: v1.ResourceList{ - v1.ResourceCPU: *resource.NewMilliQuantity(milliCPU, resource.DecimalSI), - v1.ResourceMemory: *resource.NewQuantity(memory, resource.BinarySI), - }, - }, - } -} - func makePod(node string, milliCPU, memory int64) *v1.Pod { return &v1.Pod{ Spec: v1.PodSpec{ diff --git a/pkg/scheduler/framework/plugins/registry.go b/pkg/scheduler/framework/plugins/registry.go index 4d9e2297f02..dbd172108a7 100644 --- a/pkg/scheduler/framework/plugins/registry.go +++ b/pkg/scheduler/framework/plugins/registry.go @@ -37,7 +37,6 @@ import ( "k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeunschedulable" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodevolumelimits" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/podtopologyspread" - "k8s.io/kubernetes/pkg/scheduler/framework/plugins/requestedtocapacityratio" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/serviceaffinity" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/tainttoleration" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumebinding" @@ -57,19 +56,20 @@ type RegistryArgs struct { // through the WithFrameworkOutOfTreeRegistry option. func NewInTreeRegistry(args *RegistryArgs) framework.Registry { return framework.Registry{ - defaultpodtopologyspread.Name: defaultpodtopologyspread.New, - imagelocality.Name: imagelocality.New, - tainttoleration.Name: tainttoleration.New, - nodename.Name: nodename.New, - nodeports.Name: nodeports.New, - nodepreferavoidpods.Name: nodepreferavoidpods.New, - nodeaffinity.Name: nodeaffinity.New, - podtopologyspread.Name: podtopologyspread.New, - nodeunschedulable.Name: nodeunschedulable.New, - noderesources.FitName: noderesources.NewFit, - noderesources.BalancedAllocationName: noderesources.NewBalancedAllocation, - noderesources.MostAllocatedName: noderesources.NewMostAllocated, - noderesources.LeastAllocatedName: noderesources.NewLeastAllocated, + defaultpodtopologyspread.Name: defaultpodtopologyspread.New, + imagelocality.Name: imagelocality.New, + tainttoleration.Name: tainttoleration.New, + nodename.Name: nodename.New, + nodeports.Name: nodeports.New, + nodepreferavoidpods.Name: nodepreferavoidpods.New, + nodeaffinity.Name: nodeaffinity.New, + podtopologyspread.Name: podtopologyspread.New, + nodeunschedulable.Name: nodeunschedulable.New, + noderesources.FitName: noderesources.NewFit, + noderesources.BalancedAllocationName: noderesources.NewBalancedAllocation, + noderesources.MostAllocatedName: noderesources.NewMostAllocated, + noderesources.LeastAllocatedName: noderesources.NewLeastAllocated, + noderesources.RequestedToCapacityRatioName: noderesources.NewRequestedToCapacityRatio, volumebinding.Name: func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) { return volumebinding.NewFromVolumeBinder(args.VolumeBinder), nil }, @@ -82,7 +82,6 @@ func NewInTreeRegistry(args *RegistryArgs) framework.Registry { nodevolumelimits.CinderName: nodevolumelimits.NewCinder, interpodaffinity.Name: interpodaffinity.New, nodelabel.Name: nodelabel.New, - requestedtocapacityratio.Name: requestedtocapacityratio.New, serviceaffinity.Name: serviceaffinity.New, } } @@ -96,7 +95,7 @@ type ConfigProducerArgs struct { // NodeLabelArgs is the args for the NodeLabel plugin. NodeLabelArgs *nodelabel.Args // RequestedToCapacityRatioArgs is the args for the RequestedToCapacityRatio plugin. - RequestedToCapacityRatioArgs *requestedtocapacityratio.Args + RequestedToCapacityRatioArgs *noderesources.RequestedToCapacityRatioArgs // ServiceAffinityArgs is the args for the ServiceAffinity plugin. ServiceAffinityArgs *serviceaffinity.Args // NodeResourcesFitArgs is the args for the NodeResources fit filter. @@ -287,10 +286,10 @@ func NewConfigProducerRegistry() *ConfigProducerRegistry { plugins.Score = appendToPluginSet(plugins.Score, podtopologyspread.Name, &args.Weight) return }) - registry.RegisterPriority(requestedtocapacityratio.Name, + registry.RegisterPriority(noderesources.RequestedToCapacityRatioName, func(args ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) { - plugins.Score = appendToPluginSet(plugins.Score, requestedtocapacityratio.Name, &args.Weight) - pluginConfig = append(pluginConfig, makePluginConfig(requestedtocapacityratio.Name, args.RequestedToCapacityRatioArgs)) + plugins.Score = appendToPluginSet(plugins.Score, noderesources.RequestedToCapacityRatioName, &args.Weight) + pluginConfig = append(pluginConfig, makePluginConfig(noderesources.RequestedToCapacityRatioName, args.RequestedToCapacityRatioArgs)) return }) diff --git a/pkg/scheduler/framework/plugins/requestedtocapacityratio/BUILD b/pkg/scheduler/framework/plugins/requestedtocapacityratio/BUILD deleted file mode 100644 index d4c9f2f8891..00000000000 --- a/pkg/scheduler/framework/plugins/requestedtocapacityratio/BUILD +++ /dev/null @@ -1,43 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") - -go_library( - name = "go_default_library", - srcs = ["requested_to_capacity_ratio.go"], - importpath = "k8s.io/kubernetes/pkg/scheduler/framework/plugins/requestedtocapacityratio", - visibility = ["//visibility:public"], - deps = [ - "//pkg/scheduler/algorithm/priorities:go_default_library", - "//pkg/scheduler/framework/plugins/migration:go_default_library", - "//pkg/scheduler/framework/v1alpha1:go_default_library", - "//staging/src/k8s.io/api/core/v1:go_default_library", - "//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library", - ], -) - -go_test( - name = "go_default_test", - srcs = ["requested_to_capacity_ratio_test.go"], - embed = [":go_default_library"], - deps = [ - "//pkg/scheduler/framework/v1alpha1:go_default_library", - "//pkg/scheduler/nodeinfo/snapshot:go_default_library", - "//staging/src/k8s.io/api/core/v1:go_default_library", - "//staging/src/k8s.io/apimachinery/pkg/api/resource: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", - ], -) - -filegroup( - name = "package-srcs", - srcs = glob(["**"]), - tags = ["automanaged"], - visibility = ["//visibility:private"], -) - -filegroup( - name = "all-srcs", - srcs = [":package-srcs"], - tags = ["automanaged"], - visibility = ["//visibility:public"], -)