From e8795562f9454e720db50ae4666d136883b24d98 Mon Sep 17 00:00:00 2001 From: Yecheng Fu Date: Fri, 11 Oct 2019 15:46:15 +0800 Subject: [PATCH] [migration phase 1] Implement CheckVolumeBinding as a filter plugin --- .../api/compatibility/compatibility_test.go | 13 ++--- pkg/scheduler/framework/plugins/BUILD | 3 ++ .../framework/plugins/default_registry.go | 10 ++++ .../framework/plugins/volumebinding/BUILD | 30 +++++++++++ .../plugins/volumebinding/volume_binding.go | 54 +++++++++++++++++++ test/integration/scheduler/scheduler_test.go | 6 +-- 6 files changed, 106 insertions(+), 10 deletions(-) create mode 100644 pkg/scheduler/framework/plugins/volumebinding/BUILD create mode 100644 pkg/scheduler/framework/plugins/volumebinding/volume_binding.go diff --git a/pkg/scheduler/api/compatibility/compatibility_test.go b/pkg/scheduler/api/compatibility/compatibility_test.go index a7921b31b30..881d4670085 100644 --- a/pkg/scheduler/api/compatibility/compatibility_test.go +++ b/pkg/scheduler/api/compatibility/compatibility_test.go @@ -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", diff --git a/pkg/scheduler/framework/plugins/BUILD b/pkg/scheduler/framework/plugins/BUILD index db79debe551..3a59dc4e9f4 100644 --- a/pkg/scheduler/framework/plugins/BUILD +++ b/pkg/scheduler/framework/plugins/BUILD @@ -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"], diff --git a/pkg/scheduler/framework/plugins/default_registry.go b/pkg/scheduler/framework/plugins/default_registry.go index 43f392c53f5..0492e701c7e 100644 --- a/pkg/scheduler/framework/plugins/default_registry.go +++ b/pkg/scheduler/framework/plugins/default_registry.go @@ -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) { diff --git a/pkg/scheduler/framework/plugins/volumebinding/BUILD b/pkg/scheduler/framework/plugins/volumebinding/BUILD new file mode 100644 index 00000000000..a108c6b984f --- /dev/null +++ b/pkg/scheduler/framework/plugins/volumebinding/BUILD @@ -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"], +) diff --git a/pkg/scheduler/framework/plugins/volumebinding/volume_binding.go b/pkg/scheduler/framework/plugins/volumebinding/volume_binding.go new file mode 100644 index 00000000000..8bd9a70e669 --- /dev/null +++ b/pkg/scheduler/framework/plugins/volumebinding/volume_binding.go @@ -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), + } +} diff --git a/test/integration/scheduler/scheduler_test.go b/test/integration/scheduler/scheduler_test.go index 20db7d90157..eede122ebcd 100644 --- a/test/integration/scheduler/scheduler_test.go +++ b/test/integration/scheduler/scheduler_test.go @@ -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}}, }, },