Skip to content

Commit 9e426a6

Browse files
committed
[migration phase 1] NoDiskConflict as filter plugin
1 parent d6eba1d commit 9e426a6

File tree

7 files changed

+366
-22
lines changed

7 files changed

+366
-22
lines changed

pkg/scheduler/api/compatibility/compatibility_test.go

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
6969
"MatchNodeSelector",
7070
"PodFitsResources",
7171
"PodFitsPorts",
72-
"NoDiskConflict",
7372
"TestServiceAffinity",
7473
"TestLabelsPresence",
7574
),
@@ -79,6 +78,11 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
7978
"TestServiceAntiAffinity",
8079
"TestLabelPreference",
8180
),
81+
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
82+
"FilterPlugin": {
83+
{Name: "VolumeRestrictions"},
84+
},
85+
},
8286
},
8387

8488
// Do not change this JSON after the corresponding release has been tagged.
@@ -108,7 +112,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
108112
"MatchNodeSelector",
109113
"PodFitsHostPorts",
110114
"PodFitsResources",
111-
"NoDiskConflict",
112115
"TestServiceAffinity",
113116
"TestLabelsPresence",
114117
),
@@ -123,6 +126,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
123126
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
124127
"FilterPlugin": {
125128
{Name: "NodeName"},
129+
{Name: "VolumeRestrictions"},
126130
},
127131
},
128132
},
@@ -160,7 +164,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
160164
"MatchNodeSelector",
161165
"PodFitsResources",
162166
"PodFitsHostPorts",
163-
"NoDiskConflict",
164167
"NoVolumeZoneConflict",
165168
"MaxEBSVolumeCount",
166169
"MaxGCEPDVolumeCount",
@@ -181,6 +184,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
181184
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
182185
"FilterPlugin": {
183186
{Name: "NodeName"},
187+
{Name: "VolumeRestrictions"},
184188
},
185189
},
186190
},
@@ -222,7 +226,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
222226
"MatchNodeSelector",
223227
"PodFitsResources",
224228
"PodFitsHostPorts",
225-
"NoDiskConflict",
226229
"NoVolumeZoneConflict",
227230
"CheckNodeMemoryPressure",
228231
"MaxEBSVolumeCount",
@@ -245,6 +248,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
245248
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
246249
"FilterPlugin": {
247250
{Name: "NodeName"},
251+
{Name: "VolumeRestrictions"},
248252
{Name: "TaintToleration"},
249253
},
250254
"ScorePlugin": {{Name: "TaintToleration", Weight: 2}},
@@ -291,7 +295,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
291295
"MatchNodeSelector",
292296
"PodFitsResources",
293297
"PodFitsHostPorts",
294-
"NoDiskConflict",
295298
"NoVolumeZoneConflict",
296299
"CheckNodeMemoryPressure",
297300
"CheckNodeDiskPressure",
@@ -317,6 +320,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
317320
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
318321
"FilterPlugin": {
319322
{Name: "NodeName"},
323+
{Name: "VolumeRestrictions"},
320324
{Name: "TaintToleration"},
321325
},
322326
"ScorePlugin": {{Name: "TaintToleration", Weight: 2}},
@@ -372,7 +376,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
372376
"MatchNodeSelector",
373377
"PodFitsResources",
374378
"PodFitsHostPorts",
375-
"NoDiskConflict",
376379
"NoVolumeZoneConflict",
377380
"CheckNodeMemoryPressure",
378381
"CheckNodeDiskPressure",
@@ -398,6 +401,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
398401
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
399402
"FilterPlugin": {
400403
{Name: "NodeName"},
404+
{Name: "VolumeRestrictions"},
401405
{Name: "TaintToleration"},
402406
},
403407
"ScorePlugin": {{Name: "TaintToleration", Weight: 2}},
@@ -465,7 +469,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
465469
"MatchNodeSelector",
466470
"PodFitsResources",
467471
"PodFitsHostPorts",
468-
"NoDiskConflict",
469472
"NoVolumeZoneConflict",
470473
"CheckNodeMemoryPressure",
471474
"CheckNodeDiskPressure",
@@ -492,6 +495,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
492495
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
493496
"FilterPlugin": {
494497
{Name: "NodeName"},
498+
{Name: "VolumeRestrictions"},
495499
{Name: "TaintToleration"},
496500
},
497501
"ScorePlugin": {{Name: "TaintToleration", Weight: 2}},
@@ -560,7 +564,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
560564
"MatchNodeSelector",
561565
"PodFitsResources",
562566
"PodFitsHostPorts",
563-
"NoDiskConflict",
564567
"NoVolumeZoneConflict",
565568
"CheckNodeMemoryPressure",
566569
"CheckNodeDiskPressure",
@@ -587,6 +590,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
587590
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
588591
"FilterPlugin": {
589592
{Name: "NodeName"},
593+
{Name: "VolumeRestrictions"},
590594
{Name: "TaintToleration"},
591595
{Name: "VolumeBinding"},
592596
},
@@ -660,7 +664,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
660664
"MatchNodeSelector",
661665
"PodFitsResources",
662666
"PodFitsHostPorts",
663-
"NoDiskConflict",
664667
"NoVolumeZoneConflict",
665668
"CheckNodeMemoryPressure",
666669
"CheckNodeDiskPressure",
@@ -688,6 +691,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
688691
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
689692
"FilterPlugin": {
690693
{Name: "NodeName"},
694+
{Name: "VolumeRestrictions"},
691695
{Name: "TaintToleration"},
692696
{Name: "VolumeBinding"},
693697
},
@@ -773,7 +777,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
773777
"MatchNodeSelector",
774778
"PodFitsResources",
775779
"PodFitsHostPorts",
776-
"NoDiskConflict",
777780
"NoVolumeZoneConflict",
778781
"CheckNodeMemoryPressure",
779782
"CheckNodeDiskPressure",
@@ -802,6 +805,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
802805
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
803806
"FilterPlugin": {
804807
{Name: "NodeName"},
808+
{Name: "VolumeRestrictions"},
805809
{Name: "TaintToleration"},
806810
{Name: "VolumeBinding"},
807811
},
@@ -888,7 +892,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
888892
"MatchNodeSelector",
889893
"PodFitsResources",
890894
"PodFitsHostPorts",
891-
"NoDiskConflict",
892895
"NoVolumeZoneConflict",
893896
"CheckNodeMemoryPressure",
894897
"CheckNodeDiskPressure",
@@ -918,6 +921,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
918921
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
919922
"FilterPlugin": {
920923
{Name: "NodeName"},
924+
{Name: "VolumeRestrictions"},
921925
{Name: "TaintToleration"},
922926
{Name: "VolumeBinding"},
923927
},
@@ -1003,7 +1007,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
10031007
"MatchNodeSelector",
10041008
"PodFitsResources",
10051009
"PodFitsHostPorts",
1006-
"NoDiskConflict",
10071010
"NoVolumeZoneConflict",
10081011
"CheckNodeMemoryPressure",
10091012
"CheckNodeDiskPressure",
@@ -1034,6 +1037,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
10341037
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
10351038
"FilterPlugin": {
10361039
{Name: "NodeName"},
1040+
{Name: "VolumeRestrictions"},
10371041
{Name: "TaintToleration"},
10381042
{Name: "VolumeBinding"},
10391043
},
@@ -1123,7 +1127,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
11231127
"MatchNodeSelector",
11241128
"PodFitsResources",
11251129
"PodFitsHostPorts",
1126-
"NoDiskConflict",
11271130
"NoVolumeZoneConflict",
11281131
"CheckNodeMemoryPressure",
11291132
"CheckNodeDiskPressure",
@@ -1154,6 +1157,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
11541157
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
11551158
"FilterPlugin": {
11561159
{Name: "NodeName"},
1160+
{Name: "VolumeRestrictions"},
11571161
{Name: "TaintToleration"},
11581162
{Name: "VolumeBinding"},
11591163
},
@@ -1180,9 +1184,10 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
11801184
seenPriorities := sets.NewString()
11811185
mandatoryPredicates := sets.NewString("CheckNodeCondition")
11821186
filterToPredicateMap := map[string]string{
1183-
"TaintToleration": "PodToleratesNodeTaints",
1184-
"NodeName": "HostName",
1185-
"VolumeBinding": "CheckVolumeBinding",
1187+
"VolumeRestrictions": "NoDiskConflict",
1188+
"TaintToleration": "PodToleratesNodeTaints",
1189+
"NodeName": "HostName",
1190+
"VolumeBinding": "CheckVolumeBinding",
11861191
}
11871192
scoreToPriorityMap := map[string]string{
11881193
"TaintToleration": "TaintTolerationPriority",

pkg/scheduler/framework/plugins/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ go_library(
1313
"//pkg/scheduler/framework/plugins/nodename:go_default_library",
1414
"//pkg/scheduler/framework/plugins/tainttoleration:go_default_library",
1515
"//pkg/scheduler/framework/plugins/volumebinding:go_default_library",
16+
"//pkg/scheduler/framework/plugins/volumerestrictions:go_default_library",
1617
"//pkg/scheduler/framework/v1alpha1:go_default_library",
1718
"//pkg/scheduler/internal/cache:go_default_library",
1819
"//pkg/scheduler/volumebinder:go_default_library",
@@ -38,6 +39,7 @@ filegroup(
3839
"//pkg/scheduler/framework/plugins/nodename:all-srcs",
3940
"//pkg/scheduler/framework/plugins/tainttoleration:all-srcs",
4041
"//pkg/scheduler/framework/plugins/volumebinding:all-srcs",
42+
"//pkg/scheduler/framework/plugins/volumerestrictions:all-srcs",
4143
],
4244
tags = ["automanaged"],
4345
visibility = ["//visibility:public"],

pkg/scheduler/framework/plugins/default_registry.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodename"
3030
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/tainttoleration"
3131
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumebinding"
32+
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumerestrictions"
3233
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
3334
internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
3435
"k8s.io/kubernetes/pkg/scheduler/volumebinder"
@@ -58,6 +59,7 @@ func NewDefaultRegistry(args *RegistryArgs) framework.Registry {
5859
volumebinding.Name: func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
5960
return volumebinding.NewFromVolumeBinder(args.VolumeBinder), nil
6061
},
62+
volumerestrictions.Name: volumerestrictions.New,
6163
}
6264
}
6365

@@ -100,6 +102,11 @@ func NewDefaultConfigProducerRegistry() *ConfigProducerRegistry {
100102
plugins.Filter = appendToPluginSet(plugins.Filter, volumebinding.Name, nil)
101103
return
102104
})
105+
registry.RegisterPredicate(predicates.NoDiskConflictPred,
106+
func(_ ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {
107+
plugins.Filter = appendToPluginSet(plugins.Filter, volumerestrictions.Name, nil)
108+
return
109+
})
103110

104111
registry.RegisterPriority(priorities.TaintTolerationPriority,
105112
func(args ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
2+
3+
go_library(
4+
name = "go_default_library",
5+
srcs = ["volume_restrictions.go"],
6+
importpath = "k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumerestrictions",
7+
visibility = ["//visibility:public"],
8+
deps = [
9+
"//pkg/scheduler/algorithm/predicates:go_default_library",
10+
"//pkg/scheduler/framework/plugins/migration:go_default_library",
11+
"//pkg/scheduler/framework/v1alpha1:go_default_library",
12+
"//pkg/scheduler/nodeinfo:go_default_library",
13+
"//staging/src/k8s.io/api/core/v1:go_default_library",
14+
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
15+
],
16+
)
17+
18+
filegroup(
19+
name = "package-srcs",
20+
srcs = glob(["**"]),
21+
tags = ["automanaged"],
22+
visibility = ["//visibility:private"],
23+
)
24+
25+
filegroup(
26+
name = "all-srcs",
27+
srcs = [":package-srcs"],
28+
tags = ["automanaged"],
29+
visibility = ["//visibility:public"],
30+
)
31+
32+
go_test(
33+
name = "go_default_test",
34+
srcs = ["volume_restrictions_test.go"],
35+
embed = [":go_default_library"],
36+
deps = [
37+
"//pkg/scheduler/algorithm/predicates:go_default_library",
38+
"//pkg/scheduler/framework/v1alpha1:go_default_library",
39+
"//pkg/scheduler/nodeinfo:go_default_library",
40+
"//staging/src/k8s.io/api/core/v1:go_default_library",
41+
],
42+
)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Copyright 2019 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package volumerestrictions
18+
19+
import (
20+
"k8s.io/api/core/v1"
21+
"k8s.io/apimachinery/pkg/runtime"
22+
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
23+
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/migration"
24+
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
25+
"k8s.io/kubernetes/pkg/scheduler/nodeinfo"
26+
)
27+
28+
// VolumeRestrictions is a plugin that checks volume restrictions
29+
type VolumeRestrictions struct{}
30+
31+
var _ = framework.FilterPlugin(&VolumeRestrictions{})
32+
33+
// Name is the name of the plugin used in the plugin registry and configurations.
34+
const Name = "VolumeRestrictions"
35+
36+
// Name returns name of the plugin. It is used in logs, etc.
37+
func (pl *VolumeRestrictions) Name() string {
38+
return Name
39+
}
40+
41+
// Filter invoked at the filter extension point.
42+
func (pl *VolumeRestrictions) Filter(_ *framework.CycleState, pod *v1.Pod, nodeInfo *nodeinfo.NodeInfo) *framework.Status {
43+
// metadata is not needed for NoDiskConflict
44+
_, reasons, err := predicates.NoDiskConflict(pod, nil, nodeInfo)
45+
return migration.PredicateResultToFrameworkStatus(reasons, err)
46+
}
47+
48+
// New initializes a new plugin and returns it.
49+
func New(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
50+
return &VolumeRestrictions{}, nil
51+
}

0 commit comments

Comments
 (0)