Merge pull request #83764 from cofyc/fix83635

[migration phase 1] Implement CheckVolumeBinding as a filter plugin
This commit is contained in:
Kubernetes Prow Robot 2019-10-11 09:29:52 -07:00 committed by GitHub
commit 77b86c4adf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 106 additions and 10 deletions

View File

@ -570,7 +570,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"MaxAzureDiskVolumeCount",
"MatchInterPodAffinity",
"GeneralPredicates",
"CheckVolumeBinding",
"TestServiceAffinity",
"TestLabelsPresence",
),
@ -589,6 +588,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"FilterPlugin": {
{Name: "NodeName"},
{Name: "TaintToleration"},
{Name: "VolumeBinding"},
},
"ScorePlugin": {{Name: "TaintToleration", Weight: 2}},
},
@ -671,7 +671,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"MaxAzureDiskVolumeCount",
"MatchInterPodAffinity",
"GeneralPredicates",
"CheckVolumeBinding",
"TestServiceAffinity",
"TestLabelsPresence",
),
@ -690,6 +689,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"FilterPlugin": {
{Name: "NodeName"},
{Name: "TaintToleration"},
{Name: "VolumeBinding"},
},
"ScorePlugin": {{Name: "TaintToleration", Weight: 2}},
},
@ -784,7 +784,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"MaxAzureDiskVolumeCount",
"MatchInterPodAffinity",
"GeneralPredicates",
"CheckVolumeBinding",
"TestServiceAffinity",
"TestLabelsPresence",
),
@ -804,6 +803,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"FilterPlugin": {
{Name: "NodeName"},
{Name: "TaintToleration"},
{Name: "VolumeBinding"},
},
"ScorePlugin": {{Name: "TaintToleration", Weight: 2}},
},
@ -900,7 +900,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"MaxCSIVolumeCountPred",
"MatchInterPodAffinity",
"GeneralPredicates",
"CheckVolumeBinding",
"TestServiceAffinity",
"TestLabelsPresence",
),
@ -920,6 +919,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"FilterPlugin": {
{Name: "NodeName"},
{Name: "TaintToleration"},
{Name: "VolumeBinding"},
},
"ScorePlugin": {{Name: "TaintToleration", Weight: 2}},
},
@ -1016,7 +1016,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"MaxCinderVolumeCount",
"MatchInterPodAffinity",
"GeneralPredicates",
"CheckVolumeBinding",
"TestServiceAffinity",
"TestLabelsPresence",
),
@ -1036,6 +1035,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"FilterPlugin": {
{Name: "NodeName"},
{Name: "TaintToleration"},
{Name: "VolumeBinding"},
},
"ScorePlugin": {{Name: "TaintToleration", Weight: 2}},
},
@ -1136,7 +1136,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"MaxCinderVolumeCount",
"MatchInterPodAffinity",
"GeneralPredicates",
"CheckVolumeBinding",
"TestServiceAffinity",
"TestLabelsPresence",
),
@ -1156,6 +1155,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"FilterPlugin": {
{Name: "NodeName"},
{Name: "TaintToleration"},
{Name: "VolumeBinding"},
},
"ScorePlugin": {{Name: "TaintToleration", Weight: 2}},
},
@ -1182,6 +1182,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
filterToPredicateMap := map[string]string{
"TaintToleration": "PodToleratesNodeTaints",
"NodeName": "HostName",
"VolumeBinding": "CheckVolumeBinding",
}
scoreToPriorityMap := map[string]string{
"TaintToleration": "TaintTolerationPriority",

View File

@ -12,9 +12,11 @@ go_library(
"//pkg/scheduler/apis/config:go_default_library",
"//pkg/scheduler/framework/plugins/nodename:go_default_library",
"//pkg/scheduler/framework/plugins/tainttoleration:go_default_library",
"//pkg/scheduler/framework/plugins/volumebinding:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/scheduler/internal/cache:go_default_library",
"//pkg/scheduler/volumebinder: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/client-go/listers/storage/v1:go_default_library",
],
@ -35,6 +37,7 @@ filegroup(
"//pkg/scheduler/framework/plugins/migration:all-srcs",
"//pkg/scheduler/framework/plugins/nodename:all-srcs",
"//pkg/scheduler/framework/plugins/tainttoleration:all-srcs",
"//pkg/scheduler/framework/plugins/volumebinding:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],

View File

@ -19,6 +19,7 @@ package plugins
import (
"fmt"
"k8s.io/apimachinery/pkg/runtime"
corelisters "k8s.io/client-go/listers/core/v1"
storagelistersv1 "k8s.io/client-go/listers/storage/v1"
"k8s.io/kubernetes/pkg/scheduler/algorithm"
@ -27,6 +28,7 @@ import (
"k8s.io/kubernetes/pkg/scheduler/apis/config"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodename"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/tainttoleration"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumebinding"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
"k8s.io/kubernetes/pkg/scheduler/volumebinder"
@ -53,6 +55,9 @@ func NewDefaultRegistry(args *RegistryArgs) framework.Registry {
return framework.Registry{
tainttoleration.Name: tainttoleration.New,
nodename.Name: nodename.New,
volumebinding.Name: func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
return volumebinding.NewFromVolumeBinder(args.VolumeBinder), nil
},
}
}
@ -90,6 +95,11 @@ func NewDefaultConfigProducerRegistry() *ConfigProducerRegistry {
plugins.Filter = appendToPluginSet(plugins.Filter, nodename.Name, nil)
return
})
registry.RegisterPredicate(predicates.CheckVolumeBindingPred,
func(args ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {
plugins.Filter = appendToPluginSet(plugins.Filter, volumebinding.Name, nil)
return
})
registry.RegisterPriority(priorities.TaintTolerationPriority,
func(args ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {

View File

@ -0,0 +1,30 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = ["volume_binding.go"],
importpath = "k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumebinding",
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",
"//pkg/scheduler/volumebinder:go_default_library",
"//staging/src/k8s.io/api/core/v1: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"],
)

View File

@ -0,0 +1,54 @@
/*
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 volumebinding
import (
v1 "k8s.io/api/core/v1"
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/migration"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
"k8s.io/kubernetes/pkg/scheduler/volumebinder"
)
// VolumeBinding is a plugin that binds pod volumes in scheduling.
type VolumeBinding struct {
predicate predicates.FitPredicate
}
var _ framework.FilterPlugin = &VolumeBinding{}
// Name is the name of the plugin used in Registry and configurations.
const Name = "VolumeBinding"
// Name returns name of the plugin. It is used in logs, etc.
func (pl *VolumeBinding) Name() string {
return Name
}
// Filter invoked at the filter extension point.
func (pl *VolumeBinding) Filter(cs *framework.CycleState, pod *v1.Pod, nodeInfo *schedulernodeinfo.NodeInfo) *framework.Status {
_, reasons, err := pl.predicate(pod, nil, nodeInfo)
return migration.PredicateResultToFrameworkStatus(reasons, err)
}
// NewFromVolumeBinder initializes a new plugin with volume binder and returns it.
func NewFromVolumeBinder(volumeBinder *volumebinder.VolumeBinder) framework.Plugin {
return &VolumeBinding{
predicate: predicates.NewVolumeBindingPredicate(volumeBinder),
}
}

View File

@ -130,7 +130,6 @@ func TestSchedulerCreationFromConfigMap(t *testing.T) {
"CheckNodeDiskPressure",
"CheckNodeMemoryPressure",
"CheckNodePIDPressure",
"CheckVolumeBinding",
"GeneralPredicates",
"MatchInterPodAffinity",
"MaxAzureDiskVolumeCount",
@ -150,7 +149,7 @@ func TestSchedulerCreationFromConfigMap(t *testing.T) {
"ImageLocalityPriority",
),
expectedPlugins: map[string][]kubeschedulerconfig.Plugin{
"FilterPlugin": {{Name: "TaintToleration"}},
"FilterPlugin": {{Name: "TaintToleration"}, {Name: "VolumeBinding"}},
"ScorePlugin": {{Name: "TaintToleration", Weight: 1}},
},
},
@ -197,7 +196,6 @@ kind: Policy
"CheckNodeDiskPressure",
"CheckNodeMemoryPressure",
"CheckNodePIDPressure",
"CheckVolumeBinding",
"GeneralPredicates",
"MatchInterPodAffinity",
"MaxAzureDiskVolumeCount",
@ -217,7 +215,7 @@ kind: Policy
"ImageLocalityPriority",
),
expectedPlugins: map[string][]kubeschedulerconfig.Plugin{
"FilterPlugin": {{Name: "TaintToleration"}},
"FilterPlugin": {{Name: "TaintToleration"}, {Name: "VolumeBinding"}},
"ScorePlugin": {{Name: "TaintToleration", Weight: 1}},
},
},