mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Merge pull request #86589 from notpad/feature/scheduler_mig2
Move RequestedToCapacityRatio to plugins/noderesources
This commit is contained in:
commit
c33bbbc40b
@ -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",
|
||||
|
@ -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)
|
||||
|
@ -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",
|
||||
|
@ -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 = [
|
||||
|
@ -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.
|
@ -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{
|
@ -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"
|
||||
@ -70,6 +69,7 @@ func NewInTreeRegistry(args *RegistryArgs) framework.Registry {
|
||||
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
|
||||
})
|
||||
|
||||
|
@ -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"],
|
||||
)
|
Loading…
Reference in New Issue
Block a user