Skip to content

Commit

Permalink
Merge pull request kubernetes#83650 from wgliang/scheduler-v2/pod-fit…
Browse files Browse the repository at this point in the history
…s-resources

[migration phase 1] PodFitsResources as framework plugin
  • Loading branch information
k8s-ci-robot authored Oct 13, 2019
2 parents ceceaca + 4ca3d9c commit a783404
Show file tree
Hide file tree
Showing 7 changed files with 607 additions and 13 deletions.
27 changes: 14 additions & 13 deletions pkg/scheduler/api/compatibility/compatibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
]
}`,
wantPredicates: sets.NewString(
"PodFitsResources",
"PodFitsPorts",
"TestServiceAffinity",
"TestLabelsPresence",
Expand All @@ -79,6 +78,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
"FilterPlugin": {
{Name: "NodeAffinity"},
{Name: "NodeResources"},
{Name: "VolumeRestrictions"},
},
},
Expand Down Expand Up @@ -109,7 +109,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
}`,
wantPredicates: sets.NewString(
"PodFitsHostPorts",
"PodFitsResources",
"TestServiceAffinity",
"TestLabelsPresence",
),
Expand All @@ -125,6 +124,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"FilterPlugin": {
{Name: "NodeName"},
{Name: "NodeAffinity"},
{Name: "NodeResources"},
{Name: "VolumeRestrictions"},
},
},
Expand Down Expand Up @@ -160,7 +160,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
]
}`,
wantPredicates: sets.NewString(
"PodFitsResources",
"PodFitsHostPorts",
"NoVolumeZoneConflict",
"MaxEBSVolumeCount",
Expand All @@ -183,6 +182,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"FilterPlugin": {
{Name: "NodeName"},
{Name: "NodeAffinity"},
{Name: "NodeResources"},
{Name: "VolumeRestrictions"},
},
},
Expand Down Expand Up @@ -222,7 +222,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
]
}`,
wantPredicates: sets.NewString(
"PodFitsResources",
"PodFitsHostPorts",
"NoVolumeZoneConflict",
"CheckNodeMemoryPressure",
Expand All @@ -247,6 +246,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"FilterPlugin": {
{Name: "NodeName"},
{Name: "NodeAffinity"},
{Name: "NodeResources"},
{Name: "VolumeRestrictions"},
{Name: "TaintToleration"},
},
Expand Down Expand Up @@ -291,7 +291,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
]
}`,
wantPredicates: sets.NewString(
"PodFitsResources",
"PodFitsHostPorts",
"NoVolumeZoneConflict",
"CheckNodeMemoryPressure",
Expand Down Expand Up @@ -319,6 +318,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"FilterPlugin": {
{Name: "NodeName"},
{Name: "NodeAffinity"},
{Name: "NodeResources"},
{Name: "VolumeRestrictions"},
{Name: "TaintToleration"},
},
Expand Down Expand Up @@ -372,7 +372,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
}]
}`,
wantPredicates: sets.NewString(
"PodFitsResources",
"PodFitsHostPorts",
"NoVolumeZoneConflict",
"CheckNodeMemoryPressure",
Expand Down Expand Up @@ -400,6 +399,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"FilterPlugin": {
{Name: "NodeName"},
{Name: "NodeAffinity"},
{Name: "NodeResources"},
{Name: "VolumeRestrictions"},
{Name: "TaintToleration"},
},
Expand Down Expand Up @@ -465,7 +465,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
}]
}`,
wantPredicates: sets.NewString(
"PodFitsResources",
"PodFitsHostPorts",
"NoVolumeZoneConflict",
"CheckNodeMemoryPressure",
Expand Down Expand Up @@ -494,6 +493,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"FilterPlugin": {
{Name: "NodeName"},
{Name: "NodeAffinity"},
{Name: "NodeResources"},
{Name: "VolumeRestrictions"},
{Name: "TaintToleration"},
},
Expand Down Expand Up @@ -560,7 +560,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
}]
}`,
wantPredicates: sets.NewString(
"PodFitsResources",
"PodFitsHostPorts",
"NoVolumeZoneConflict",
"CheckNodeMemoryPressure",
Expand Down Expand Up @@ -589,6 +588,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"FilterPlugin": {
{Name: "NodeName"},
{Name: "NodeAffinity"},
{Name: "NodeResources"},
{Name: "VolumeRestrictions"},
{Name: "TaintToleration"},
{Name: "VolumeBinding"},
Expand Down Expand Up @@ -660,7 +660,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
}]
}`,
wantPredicates: sets.NewString(
"PodFitsResources",
"PodFitsHostPorts",
"NoVolumeZoneConflict",
"CheckNodeMemoryPressure",
Expand Down Expand Up @@ -690,6 +689,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"FilterPlugin": {
{Name: "NodeName"},
{Name: "NodeAffinity"},
{Name: "NodeResources"},
{Name: "VolumeRestrictions"},
{Name: "TaintToleration"},
{Name: "VolumeBinding"},
Expand Down Expand Up @@ -773,7 +773,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
}]
}`,
wantPredicates: sets.NewString(
"PodFitsResources",
"PodFitsHostPorts",
"NoVolumeZoneConflict",
"CheckNodeMemoryPressure",
Expand Down Expand Up @@ -804,6 +803,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"FilterPlugin": {
{Name: "NodeName"},
{Name: "NodeAffinity"},
{Name: "NodeResources"},
{Name: "VolumeRestrictions"},
{Name: "TaintToleration"},
{Name: "VolumeBinding"},
Expand Down Expand Up @@ -888,7 +888,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
}]
}`,
wantPredicates: sets.NewString(
"PodFitsResources",
"PodFitsHostPorts",
"NoVolumeZoneConflict",
"CheckNodeMemoryPressure",
Expand Down Expand Up @@ -920,6 +919,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"FilterPlugin": {
{Name: "NodeName"},
{Name: "NodeAffinity"},
{Name: "NodeResources"},
{Name: "VolumeRestrictions"},
{Name: "TaintToleration"},
{Name: "VolumeBinding"},
Expand Down Expand Up @@ -1003,7 +1003,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
}]
}`,
wantPredicates: sets.NewString(
"PodFitsResources",
"PodFitsHostPorts",
"NoVolumeZoneConflict",
"CheckNodeMemoryPressure",
Expand Down Expand Up @@ -1036,6 +1035,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"FilterPlugin": {
{Name: "NodeName"},
{Name: "NodeAffinity"},
{Name: "NodeResources"},
{Name: "VolumeRestrictions"},
{Name: "TaintToleration"},
{Name: "VolumeBinding"},
Expand Down Expand Up @@ -1123,7 +1123,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
}]
}`,
wantPredicates: sets.NewString(
"PodFitsResources",
"PodFitsHostPorts",
"NoVolumeZoneConflict",
"CheckNodeMemoryPressure",
Expand Down Expand Up @@ -1156,6 +1155,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"FilterPlugin": {
{Name: "NodeName"},
{Name: "NodeAffinity"},
{Name: "NodeResources"},
{Name: "VolumeRestrictions"},
{Name: "TaintToleration"},
{Name: "VolumeBinding"},
Expand Down Expand Up @@ -1185,6 +1185,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
filterToPredicateMap := map[string]string{
"TaintToleration": "PodToleratesNodeTaints",
"NodeName": "HostName",
"NodeResources": "PodFitsResources",
"NodeAffinity": "MatchNodeSelector",
"VolumeBinding": "CheckVolumeBinding",
"VolumeRestrictions": "NoDiskConflict",
Expand Down
2 changes: 2 additions & 0 deletions pkg/scheduler/framework/plugins/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ go_library(
"//pkg/scheduler/apis/config:go_default_library",
"//pkg/scheduler/framework/plugins/nodeaffinity:go_default_library",
"//pkg/scheduler/framework/plugins/nodename:go_default_library",
"//pkg/scheduler/framework/plugins/noderesources:go_default_library",
"//pkg/scheduler/framework/plugins/tainttoleration:go_default_library",
"//pkg/scheduler/framework/plugins/volumebinding:go_default_library",
"//pkg/scheduler/framework/plugins/volumerestrictions:go_default_library",
Expand Down Expand Up @@ -39,6 +40,7 @@ filegroup(
"//pkg/scheduler/framework/plugins/migration:all-srcs",
"//pkg/scheduler/framework/plugins/nodeaffinity:all-srcs",
"//pkg/scheduler/framework/plugins/nodename:all-srcs",
"//pkg/scheduler/framework/plugins/noderesources:all-srcs",
"//pkg/scheduler/framework/plugins/tainttoleration:all-srcs",
"//pkg/scheduler/framework/plugins/volumebinding:all-srcs",
"//pkg/scheduler/framework/plugins/volumerestrictions:all-srcs",
Expand Down
7 changes: 7 additions & 0 deletions pkg/scheduler/framework/plugins/default_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"k8s.io/kubernetes/pkg/scheduler/apis/config"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeaffinity"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodename"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/noderesources"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/tainttoleration"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumebinding"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumerestrictions"
Expand Down Expand Up @@ -56,6 +57,7 @@ type RegistryArgs struct {
func NewDefaultRegistry(args *RegistryArgs) framework.Registry {
return framework.Registry{
tainttoleration.Name: tainttoleration.New,
noderesources.Name: noderesources.New,
nodename.Name: nodename.New,
nodeaffinity.Name: nodeaffinity.New,
volumebinding.Name: func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
Expand Down Expand Up @@ -94,6 +96,11 @@ func NewDefaultConfigProducerRegistry() *ConfigProducerRegistry {
plugins.Filter = appendToPluginSet(plugins.Filter, tainttoleration.Name, nil)
return
})
registry.RegisterPredicate(predicates.PodFitsResourcesPred,
func(_ ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {
plugins.Filter = appendToPluginSet(plugins.Filter, noderesources.Name, nil)
return
})
registry.RegisterPredicate(predicates.HostNamePred,
func(_ ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {
plugins.Filter = appendToPluginSet(plugins.Filter, nodename.Name, nil)
Expand Down
15 changes: 15 additions & 0 deletions pkg/scheduler/framework/plugins/migration/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,18 @@ func PriorityMetadata(state *framework.CycleState) interface{} {
}
return meta
}

// PredicateMetadata returns predicate metadata stored in CycleState.
func PredicateMetadata(state *framework.CycleState) interface{} {
if state == nil {
return nil
}

var meta interface{}
if s, err := state.Read(PredicatesStateKey); err == nil {
meta = s.(*PredicatesStateData).Reference
} else {
klog.Errorf("reading key %q from CycleState, continuing without metadata: %v", PredicatesStateKey, err)
}
return meta
}
49 changes: 49 additions & 0 deletions pkg/scheduler/framework/plugins/noderesources/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "go_default_library",
srcs = ["node_resources.go"],
importpath = "k8s.io/kubernetes/pkg/scheduler/framework/plugins/noderesources",
visibility = ["//visibility:public"],
deps = [
"//pkg/scheduler/algorithm/predicates:go_default_library",
"//pkg/scheduler/framework/plugins/migration:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/scheduler/nodeinfo:go_default_library",
"//staging/src/k8s.io/api/core/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"],
)

go_test(
name = "go_default_test",
srcs = ["node_resources_test.go"],
embed = [":go_default_library"],
deps = [
"//pkg/apis/core/v1/helper:go_default_library",
"//pkg/features:go_default_library",
"//pkg/scheduler/algorithm/predicates:go_default_library",
"//pkg/scheduler/framework/plugins/migration:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/scheduler/nodeinfo: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/util/sets: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",
],
)
56 changes: 56 additions & 0 deletions pkg/scheduler/framework/plugins/noderesources/node_resources.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
Copyright 2019 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 noderesources

import (
"fmt"

"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/migration"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
"k8s.io/kubernetes/pkg/scheduler/nodeinfo"
)

// NodeResources is a plugin that checks if a node has sufficient resources.
type NodeResources struct{}

var _ = framework.FilterPlugin(&NodeResources{})

// Name is the name of the plugin used in the plugin registry and configurations.
const Name = "NodeResources"

// Name returns name of the plugin. It is used in logs, etc.
func (pl *NodeResources) Name() string {
return Name
}

// Filter invoked at the filter extension point.
func (pl *NodeResources) Filter(cycleState *framework.CycleState, pod *v1.Pod, nodeInfo *nodeinfo.NodeInfo) *framework.Status {
meta, ok := migration.PredicateMetadata(cycleState).(predicates.PredicateMetadata)
if !ok {
return migration.ErrorToFrameworkStatus(fmt.Errorf("%+v convert to predicates.PredicateMetadata error", cycleState))
}
_, reasons, err := predicates.PodFitsResources(pod, meta, nodeInfo)
return migration.PredicateResultToFrameworkStatus(reasons, err)
}

// New initializes a new plugin and returns it.
func New(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
return &NodeResources{}, nil
}
Loading

0 comments on commit a783404

Please sign in to comment.