Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configurable weight on the CPU and memory #90544

Merged
merged 1 commit into from
May 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/scheduler/apis/config/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&RequestedToCapacityRatioArgs{},
&ServiceAffinityArgs{},
&VolumeBindingArgs{},
&NodeResourcesLeastAllocatedArgs{},
chendave marked this conversation as resolved.
Show resolved Hide resolved
&NodeResourcesMostAllocatedArgs{},
)
scheme.AddKnownTypes(schema.GroupVersion{Group: "", Version: runtime.APIVersionInternal}, &Policy{})
return nil
Expand Down
70 changes: 70 additions & 0 deletions pkg/scheduler/apis/config/scheme/scheme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ profiles:
- name: ServiceAffinity
args:
affinityLabels: ["bar"]
- name: NodeResourcesLeastAllocated
chendave marked this conversation as resolved.
Show resolved Hide resolved
args:
resources:
- name: cpu
weight: 2
- name: unknown
weight: 1
- name: NodeResourcesMostAllocated
args:
resources:
- name: memory
weight: 1
`),
wantProfiles: []config.KubeSchedulerProfile{
{
Expand Down Expand Up @@ -103,6 +115,18 @@ profiles:
AffinityLabels: []string{"bar"},
},
},
{
Name: "NodeResourcesLeastAllocated",
Args: &config.NodeResourcesLeastAllocatedArgs{
Resources: []config.ResourceSpec{{Name: "cpu", Weight: 2}, {Name: "unknown", Weight: 1}},
},
},
{
Name: "NodeResourcesMostAllocated",
Args: &config.NodeResourcesMostAllocatedArgs{
Resources: []config.ResourceSpec{{Name: "memory", Weight: 1}},
},
},
},
},
},
Expand Down Expand Up @@ -226,6 +250,10 @@ profiles:
- name: NodeResourcesFit
- name: OutOfTreePlugin
args:
- name: NodeResourcesLeastAllocated
args:
- name: NodeResourcesMostAllocated
args:
`),
wantProfiles: []config.KubeSchedulerProfile{
{
Expand All @@ -242,6 +270,18 @@ profiles:
Args: &config.NodeResourcesFitArgs{},
},
{Name: "OutOfTreePlugin"},
{
Name: "NodeResourcesLeastAllocated",
Args: &config.NodeResourcesLeastAllocatedArgs{
Resources: []config.ResourceSpec{{Name: "cpu", Weight: 1}, {Name: "memory", Weight: 1}},
},
},
{
Name: "NodeResourcesMostAllocated",
Args: &config.NodeResourcesMostAllocatedArgs{
Resources: []config.ResourceSpec{{Name: "cpu", Weight: 1}, {Name: "memory", Weight: 1}},
},
},
},
},
},
Expand Down Expand Up @@ -306,6 +346,16 @@ func TestCodecsEncodePluginConfig(t *testing.T) {
},
},
},
{
Name: "NodeResourcesLeastAllocated",
Args: runtime.RawExtension{
Object: &v1alpha2.NodeResourcesLeastAllocatedArgs{
Resources: []v1alpha2.ResourceSpec{
{Name: "mem", Weight: 2},
},
},
},
},
{
Name: "OutOfTreePlugin",
Args: runtime.RawExtension{
Expand Down Expand Up @@ -349,6 +399,13 @@ profiles:
- Score: 2
Utilization: 1
name: RequestedToCapacityRatio
- args:
apiVersion: kubescheduler.config.k8s.io/v1alpha2
kind: NodeResourcesLeastAllocatedArgs
resources:
- Name: mem
Weight: 2
name: NodeResourcesLeastAllocated
- args:
foo: bar
name: OutOfTreePlugin
Expand All @@ -367,6 +424,12 @@ profiles:
HardPodAffinityWeight: 5,
},
},
{
Name: "NodeResourcesMostAllocated",
Args: &config.NodeResourcesMostAllocatedArgs{
Resources: []config.ResourceSpec{{Name: "cpu", Weight: 1}},
},
},
{
Name: "OutOfTreePlugin",
Args: &runtime.Unknown{
Expand Down Expand Up @@ -409,6 +472,13 @@ profiles:
hardPodAffinityWeight: 5
kind: InterPodAffinityArgs
name: InterPodAffinity
- args:
apiVersion: kubescheduler.config.k8s.io/v1alpha2
kind: NodeResourcesMostAllocatedArgs
resources:
- Name: cpu
Weight: 1
name: NodeResourcesMostAllocated
- args:
foo: bar
name: OutOfTreePlugin
Expand Down
32 changes: 29 additions & 3 deletions pkg/scheduler/apis/config/types_pluginargs.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,33 @@ type RequestedToCapacityRatioArgs struct {

// Points defining priority function shape
Shape []UtilizationShapePoint
// Resources to be managed
// Resources to be considered when scoring.
// The default resource set includes "cpu" and "memory" with an equal weight.
// Allowed weights go from 1 to 100.
Resources []ResourceSpec
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// NodeResourcesLeastAllocatedArgs holds arguments used to configure NodeResourcesLeastAllocated plugin.
type NodeResourcesLeastAllocatedArgs struct {
chendave marked this conversation as resolved.
Show resolved Hide resolved
metav1.TypeMeta

// Resources to be considered when scoring.
// The default resource set includes "cpu" and "memory" with an equal weight.
// Allowed weights go from 1 to 100.
Resources []ResourceSpec
chendave marked this conversation as resolved.
Show resolved Hide resolved
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// NodeResourcesMostAllocatedArgs holds arguments used to configure NodeResourcesMostAllocated plugin.
type NodeResourcesMostAllocatedArgs struct {
metav1.TypeMeta

// Resources to be considered when scoring.
// The default resource set includes "cpu" and "memory" with an equal weight.
// Allowed weights go from 1 to 100.
Resources []ResourceSpec
}

Expand All @@ -94,9 +120,9 @@ type UtilizationShapePoint struct {
Score int32
}

// ResourceSpec represents single resource for bin packing of priority RequestedToCapacityRatioArgs.
// ResourceSpec represents single resource.
type ResourceSpec struct {
// Name of the resource to be managed by RequestedToCapacityRatio function.
// Name of the resource.
Name string
// Weight of the resource.
Weight int64
Expand Down
20 changes: 20 additions & 0 deletions pkg/scheduler/apis/config/v1alpha2/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"net"
"strconv"

v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
componentbaseconfigv1alpha1 "k8s.io/component-base/config/v1alpha1"
"k8s.io/kube-scheduler/config/v1alpha2"
Expand All @@ -30,6 +31,11 @@ import (
api "k8s.io/kubernetes/pkg/apis/core"
)

var defaultResourceSpec = []v1alpha2.ResourceSpec{
{Name: string(v1.ResourceCPU), Weight: 1},
{Name: string(v1.ResourceMemory), Weight: 1},
}

func addDefaultingFuncs(scheme *runtime.Scheme) error {
return RegisterDefaults(scheme)
}
Expand Down Expand Up @@ -165,3 +171,17 @@ func SetDefaults_InterPodAffinityArgs(obj *v1alpha2.InterPodAffinityArgs) {
obj.HardPodAffinityWeight = pointer.Int32Ptr(1)
}
}

func SetDefaults_NodeResourcesLeastAllocatedArgs(obj *v1alpha2.NodeResourcesLeastAllocatedArgs) {
if len(obj.Resources) == 0 {
// If no resources specified, used the default set.
obj.Resources = append(obj.Resources, defaultResourceSpec...)
}
}

func SetDefaults_NodeResourcesMostAllocatedArgs(obj *v1alpha2.NodeResourcesMostAllocatedArgs) {
if len(obj.Resources) == 0 {
// If no resources specified, used the default set.
obj.Resources = append(obj.Resources, defaultResourceSpec...)
}
}
46 changes: 46 additions & 0 deletions pkg/scheduler/apis/config/v1alpha2/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,52 @@ func TestPluginArgsDefaults(t *testing.T) {
HardPodAffinityWeight: pointer.Int32Ptr(5),
},
},
{
name: "NodeResourcesLeastAllocatedArgs resources empty",
in: &v1alpha2.NodeResourcesLeastAllocatedArgs{},
want: &v1alpha2.NodeResourcesLeastAllocatedArgs{
Resources: []v1alpha2.ResourceSpec{
{Name: "cpu", Weight: 1},
{Name: "memory", Weight: 1},
},
},
},
{
name: "NodeResourcesLeastAllocatedArgs resources with value",
in: &v1alpha2.NodeResourcesLeastAllocatedArgs{
Resources: []v1alpha2.ResourceSpec{
{Name: "resource", Weight: 2},
},
},
want: &v1alpha2.NodeResourcesLeastAllocatedArgs{
Resources: []v1alpha2.ResourceSpec{
{Name: "resource", Weight: 2},
},
},
},
{
name: "NodeResourcesMostAllocatedArgs resources empty",
in: &v1alpha2.NodeResourcesMostAllocatedArgs{},
want: &v1alpha2.NodeResourcesMostAllocatedArgs{
Resources: []v1alpha2.ResourceSpec{
{Name: "cpu", Weight: 1},
{Name: "memory", Weight: 1},
},
},
},
{
name: "NodeResourcesMostAllocatedArgs resources with value",
in: &v1alpha2.NodeResourcesMostAllocatedArgs{
Resources: []v1alpha2.ResourceSpec{
{Name: "resource", Weight: 2},
},
},
want: &v1alpha2.NodeResourcesMostAllocatedArgs{
Resources: []v1alpha2.ResourceSpec{
{Name: "resource", Weight: 2},
},
},
},
}
for _, tc := range tests {
scheme := runtime.NewScheme()
Expand Down
60 changes: 60 additions & 0 deletions pkg/scheduler/apis/config/v1alpha2/zz_generated.conversion.go

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

14 changes: 14 additions & 0 deletions pkg/scheduler/apis/config/v1alpha2/zz_generated.defaults.go

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

Loading