Skip to content

Commit a0193ac

Browse files
authored
Merge pull request kubernetes#83843 from notpad/feature/migration_volumezone
[migration phase 1] VolumeZoneChecker as filter plugin
2 parents 2e55cf0 + 4ff7251 commit a0193ac

File tree

7 files changed

+475
-13
lines changed

7 files changed

+475
-13
lines changed

pkg/scheduler/api/compatibility/compatibility_test.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
160160
]
161161
}`,
162162
wantPredicates: sets.NewString(
163-
"NoVolumeZoneConflict",
164163
"MaxEBSVolumeCount",
165164
"MaxGCEPDVolumeCount",
166165
"MaxAzureDiskVolumeCount",
@@ -183,6 +182,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
183182
{Name: "NodeAffinity"},
184183
{Name: "NodeResources"},
185184
{Name: "VolumeRestrictions"},
185+
{Name: "VolumeZone"},
186186
},
187187
"ScorePlugin": {
188188
{Name: "ImageLocality", Weight: 2},
@@ -224,7 +224,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
224224
]
225225
}`,
226226
wantPredicates: sets.NewString(
227-
"NoVolumeZoneConflict",
228227
"CheckNodeMemoryPressure",
229228
"MaxEBSVolumeCount",
230229
"MaxGCEPDVolumeCount",
@@ -250,6 +249,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
250249
{Name: "NodeResources"},
251250
{Name: "VolumeRestrictions"},
252251
{Name: "TaintToleration"},
252+
{Name: "VolumeZone"},
253253
},
254254
"ScorePlugin": {
255255
{Name: "ImageLocality", Weight: 2},
@@ -295,7 +295,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
295295
]
296296
}`,
297297
wantPredicates: sets.NewString(
298-
"NoVolumeZoneConflict",
299298
"CheckNodeMemoryPressure",
300299
"CheckNodeDiskPressure",
301300
"MaxEBSVolumeCount",
@@ -324,6 +323,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
324323
{Name: "NodeResources"},
325324
{Name: "VolumeRestrictions"},
326325
{Name: "TaintToleration"},
326+
{Name: "VolumeZone"},
327327
},
328328
"ScorePlugin": {
329329
{Name: "ImageLocality", Weight: 2},
@@ -378,7 +378,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
378378
}]
379379
}`,
380380
wantPredicates: sets.NewString(
381-
"NoVolumeZoneConflict",
382381
"CheckNodeMemoryPressure",
383382
"CheckNodeDiskPressure",
384383
"MaxEBSVolumeCount",
@@ -407,6 +406,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
407406
{Name: "NodeResources"},
408407
{Name: "VolumeRestrictions"},
409408
{Name: "TaintToleration"},
409+
{Name: "VolumeZone"},
410410
},
411411
"ScorePlugin": {
412412
{Name: "ImageLocality", Weight: 2},
@@ -473,7 +473,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
473473
}]
474474
}`,
475475
wantPredicates: sets.NewString(
476-
"NoVolumeZoneConflict",
477476
"CheckNodeMemoryPressure",
478477
"CheckNodeDiskPressure",
479478
"CheckNodeCondition",
@@ -503,6 +502,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
503502
{Name: "NodeResources"},
504503
{Name: "VolumeRestrictions"},
505504
{Name: "TaintToleration"},
505+
{Name: "VolumeZone"},
506506
},
507507
"ScorePlugin": {
508508
{Name: "ImageLocality", Weight: 2},
@@ -570,7 +570,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
570570
}]
571571
}`,
572572
wantPredicates: sets.NewString(
573-
"NoVolumeZoneConflict",
574573
"CheckNodeMemoryPressure",
575574
"CheckNodeDiskPressure",
576575
"CheckNodeCondition",
@@ -601,6 +600,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
601600
{Name: "VolumeRestrictions"},
602601
{Name: "TaintToleration"},
603602
{Name: "VolumeBinding"},
603+
{Name: "VolumeZone"},
604604
},
605605
"ScorePlugin": {
606606
{Name: "ImageLocality", Weight: 2},
@@ -672,7 +672,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
672672
}]
673673
}`,
674674
wantPredicates: sets.NewString(
675-
"NoVolumeZoneConflict",
676675
"CheckNodeMemoryPressure",
677676
"CheckNodeDiskPressure",
678677
"CheckNodePIDPressure",
@@ -704,6 +703,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
704703
{Name: "VolumeRestrictions"},
705704
{Name: "TaintToleration"},
706705
{Name: "VolumeBinding"},
706+
{Name: "VolumeZone"},
707707
},
708708
"ScorePlugin": {
709709
{Name: "ImageLocality", Weight: 2},
@@ -787,7 +787,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
787787
}]
788788
}`,
789789
wantPredicates: sets.NewString(
790-
"NoVolumeZoneConflict",
791790
"CheckNodeMemoryPressure",
792791
"CheckNodeDiskPressure",
793792
"CheckNodePIDPressure",
@@ -820,6 +819,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
820819
{Name: "VolumeRestrictions"},
821820
{Name: "TaintToleration"},
822821
{Name: "VolumeBinding"},
822+
{Name: "VolumeZone"},
823823
},
824824
"ScorePlugin": {
825825
{Name: "ImageLocality", Weight: 2},
@@ -904,7 +904,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
904904
}]
905905
}`,
906906
wantPredicates: sets.NewString(
907-
"NoVolumeZoneConflict",
908907
"CheckNodeMemoryPressure",
909908
"CheckNodeDiskPressure",
910909
"CheckNodePIDPressure",
@@ -938,6 +937,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
938937
{Name: "VolumeRestrictions"},
939938
{Name: "TaintToleration"},
940939
{Name: "VolumeBinding"},
940+
{Name: "VolumeZone"},
941941
},
942942
"ScorePlugin": {
943943
{Name: "ImageLocality", Weight: 2},
@@ -1021,7 +1021,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
10211021
}]
10221022
}`,
10231023
wantPredicates: sets.NewString(
1024-
"NoVolumeZoneConflict",
10251024
"CheckNodeMemoryPressure",
10261025
"CheckNodeDiskPressure",
10271026
"CheckNodePIDPressure",
@@ -1056,6 +1055,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
10561055
{Name: "VolumeRestrictions"},
10571056
{Name: "TaintToleration"},
10581057
{Name: "VolumeBinding"},
1058+
{Name: "VolumeZone"},
10591059
},
10601060
"ScorePlugin": {
10611061
{Name: "ImageLocality", Weight: 2},
@@ -1143,7 +1143,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
11431143
}]
11441144
}`,
11451145
wantPredicates: sets.NewString(
1146-
"NoVolumeZoneConflict",
11471146
"CheckNodeMemoryPressure",
11481147
"CheckNodeDiskPressure",
11491148
"CheckNodePIDPressure",
@@ -1178,6 +1177,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
11781177
{Name: "VolumeRestrictions"},
11791178
{Name: "TaintToleration"},
11801179
{Name: "VolumeBinding"},
1180+
{Name: "VolumeZone"},
11811181
},
11821182
"ScorePlugin": {
11831183
{Name: "ImageLocality", Weight: 2},
@@ -1212,6 +1212,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
12121212
"NodeAffinity": "MatchNodeSelector",
12131213
"VolumeBinding": "CheckVolumeBinding",
12141214
"VolumeRestrictions": "NoDiskConflict",
1215+
"VolumeZone": "NoVolumeZoneConflict",
12151216
}
12161217
scoreToPriorityMap := map[string]string{
12171218
"TaintToleration": "TaintTolerationPriority",

pkg/scheduler/framework/plugins/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ go_library(
1818
"//pkg/scheduler/framework/plugins/tainttoleration:go_default_library",
1919
"//pkg/scheduler/framework/plugins/volumebinding:go_default_library",
2020
"//pkg/scheduler/framework/plugins/volumerestrictions:go_default_library",
21+
"//pkg/scheduler/framework/plugins/volumezone:go_default_library",
2122
"//pkg/scheduler/framework/v1alpha1:go_default_library",
2223
"//pkg/scheduler/internal/cache:go_default_library",
2324
"//pkg/scheduler/volumebinder:go_default_library",
@@ -48,6 +49,7 @@ filegroup(
4849
"//pkg/scheduler/framework/plugins/tainttoleration:all-srcs",
4950
"//pkg/scheduler/framework/plugins/volumebinding:all-srcs",
5051
"//pkg/scheduler/framework/plugins/volumerestrictions:all-srcs",
52+
"//pkg/scheduler/framework/plugins/volumezone:all-srcs",
5153
],
5254
tags = ["automanaged"],
5355
visibility = ["//visibility:public"],

pkg/scheduler/framework/plugins/default_registry.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/tainttoleration"
3535
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumebinding"
3636
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumerestrictions"
37+
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumezone"
3738
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
3839
internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
3940
"k8s.io/kubernetes/pkg/scheduler/volumebinder"
@@ -57,6 +58,10 @@ type RegistryArgs struct {
5758
// This is the registry that Kubernetes default scheduler uses. A scheduler that
5859
// runs custom plugins, can pass a different Registry when initializing the scheduler.
5960
func NewDefaultRegistry(args *RegistryArgs) framework.Registry {
61+
pvInfo := &predicates.CachedPersistentVolumeInfo{PersistentVolumeLister: args.PVLister}
62+
pvcInfo := &predicates.CachedPersistentVolumeClaimInfo{PersistentVolumeClaimLister: args.PVCLister}
63+
classInfo := &predicates.CachedStorageClassInfo{StorageClassLister: args.StorageClassLister}
64+
6065
return framework.Registry{
6166
imagelocality.Name: imagelocality.New,
6267
tainttoleration.Name: tainttoleration.New,
@@ -68,6 +73,9 @@ func NewDefaultRegistry(args *RegistryArgs) framework.Registry {
6873
return volumebinding.NewFromVolumeBinder(args.VolumeBinder), nil
6974
},
7075
volumerestrictions.Name: volumerestrictions.New,
76+
volumezone.Name: func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
77+
return volumezone.New(pvInfo, pvcInfo, classInfo), nil
78+
},
7179
}
7280
}
7381

@@ -130,6 +138,11 @@ func NewDefaultConfigProducerRegistry() *ConfigProducerRegistry {
130138
plugins.Filter = appendToPluginSet(plugins.Filter, volumerestrictions.Name, nil)
131139
return
132140
})
141+
registry.RegisterPredicate(predicates.NoVolumeZoneConflictPred,
142+
func(_ ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {
143+
plugins.Filter = appendToPluginSet(plugins.Filter, volumezone.Name, nil)
144+
return
145+
})
133146

134147
registry.RegisterPriority(priorities.TaintTolerationPriority,
135148
func(args ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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_zone.go"],
6+
importpath = "k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumezone",
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+
],
15+
)
16+
17+
go_test(
18+
name = "go_default_test",
19+
srcs = ["volume_zone_test.go"],
20+
embed = [":go_default_library"],
21+
deps = [
22+
"//pkg/scheduler/algorithm/predicates:go_default_library",
23+
"//pkg/scheduler/framework/v1alpha1:go_default_library",
24+
"//pkg/scheduler/nodeinfo:go_default_library",
25+
"//staging/src/k8s.io/api/core/v1:go_default_library",
26+
"//staging/src/k8s.io/api/storage/v1:go_default_library",
27+
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
28+
],
29+
)
30+
31+
filegroup(
32+
name = "package-srcs",
33+
srcs = glob(["**"]),
34+
tags = ["automanaged"],
35+
visibility = ["//visibility:private"],
36+
)
37+
38+
filegroup(
39+
name = "all-srcs",
40+
srcs = [":package-srcs"],
41+
tags = ["automanaged"],
42+
visibility = ["//visibility:public"],
43+
)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 volumezone
18+
19+
import (
20+
"k8s.io/api/core/v1"
21+
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
22+
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/migration"
23+
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
24+
"k8s.io/kubernetes/pkg/scheduler/nodeinfo"
25+
)
26+
27+
// VolumeZone is a plugin that checks volume zone
28+
type VolumeZone struct {
29+
predicate predicates.FitPredicate
30+
}
31+
32+
var _ = framework.FilterPlugin(&VolumeZone{})
33+
34+
// Name is the name of the plugin used in the plugin registry and configurations.
35+
const Name = "VolumeZone"
36+
37+
// Name returns name of the plugin. It is used in logs, etc.
38+
func (pl *VolumeZone) Name() string {
39+
return Name
40+
}
41+
42+
// Filter invoked at the filter extension point.
43+
func (pl *VolumeZone) Filter(_ *framework.CycleState, pod *v1.Pod, nodeInfo *nodeinfo.NodeInfo) *framework.Status {
44+
// metadata is not needed
45+
_, reasons, err := pl.predicate(pod, nil, nodeInfo)
46+
return migration.PredicateResultToFrameworkStatus(reasons, err)
47+
}
48+
49+
// New initializes a new plugin and returns it.
50+
func New(pvInfo predicates.PersistentVolumeInfo, pvcInfo predicates.PersistentVolumeClaimInfo, classInfo predicates.StorageClassInfo) framework.Plugin {
51+
return &VolumeZone{
52+
predicate: predicates.NewVolumeZonePredicate(pvInfo, pvcInfo, classInfo),
53+
}
54+
}

0 commit comments

Comments
 (0)