Skip to content

Commit 5a427e8

Browse files
authored
Merge pull request kubernetes#83659 from wgliang/scheduler-v2/pod-fits-host-ports
[migration phase 1] PodFitsHostPorts as filter plugin
2 parents f0e1d39 + 78be6a6 commit 5a427e8

File tree

6 files changed

+272
-12
lines changed

6 files changed

+272
-12
lines changed

pkg/scheduler/api/compatibility/compatibility_test.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
108108
]
109109
}`,
110110
wantPredicates: sets.NewString(
111-
"PodFitsHostPorts",
112111
"TestServiceAffinity",
113112
"TestLabelsPresence",
114113
),
@@ -123,6 +122,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
123122
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
124123
"FilterPlugin": {
125124
{Name: "NodeName"},
125+
{Name: "NodePorts"},
126126
{Name: "NodeAffinity"},
127127
{Name: "NodeResources"},
128128
{Name: "VolumeRestrictions"},
@@ -160,7 +160,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
160160
]
161161
}`,
162162
wantPredicates: sets.NewString(
163-
"PodFitsHostPorts",
164163
"NoVolumeZoneConflict",
165164
"MaxEBSVolumeCount",
166165
"MaxGCEPDVolumeCount",
@@ -180,6 +179,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
180179
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
181180
"FilterPlugin": {
182181
{Name: "NodeName"},
182+
{Name: "NodePorts"},
183183
{Name: "NodeAffinity"},
184184
{Name: "NodeResources"},
185185
{Name: "VolumeRestrictions"},
@@ -224,7 +224,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
224224
]
225225
}`,
226226
wantPredicates: sets.NewString(
227-
"PodFitsHostPorts",
228227
"NoVolumeZoneConflict",
229228
"CheckNodeMemoryPressure",
230229
"MaxEBSVolumeCount",
@@ -246,6 +245,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
246245
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
247246
"FilterPlugin": {
248247
{Name: "NodeName"},
248+
{Name: "NodePorts"},
249249
{Name: "NodeAffinity"},
250250
{Name: "NodeResources"},
251251
{Name: "VolumeRestrictions"},
@@ -295,7 +295,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
295295
]
296296
}`,
297297
wantPredicates: sets.NewString(
298-
"PodFitsHostPorts",
299298
"NoVolumeZoneConflict",
300299
"CheckNodeMemoryPressure",
301300
"CheckNodeDiskPressure",
@@ -320,6 +319,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
320319
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
321320
"FilterPlugin": {
322321
{Name: "NodeName"},
322+
{Name: "NodePorts"},
323323
{Name: "NodeAffinity"},
324324
{Name: "NodeResources"},
325325
{Name: "VolumeRestrictions"},
@@ -378,7 +378,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
378378
}]
379379
}`,
380380
wantPredicates: sets.NewString(
381-
"PodFitsHostPorts",
382381
"NoVolumeZoneConflict",
383382
"CheckNodeMemoryPressure",
384383
"CheckNodeDiskPressure",
@@ -403,6 +402,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
403402
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
404403
"FilterPlugin": {
405404
{Name: "NodeName"},
405+
{Name: "NodePorts"},
406406
{Name: "NodeAffinity"},
407407
{Name: "NodeResources"},
408408
{Name: "VolumeRestrictions"},
@@ -473,7 +473,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
473473
}]
474474
}`,
475475
wantPredicates: sets.NewString(
476-
"PodFitsHostPorts",
477476
"NoVolumeZoneConflict",
478477
"CheckNodeMemoryPressure",
479478
"CheckNodeDiskPressure",
@@ -499,6 +498,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
499498
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
500499
"FilterPlugin": {
501500
{Name: "NodeName"},
501+
{Name: "NodePorts"},
502502
{Name: "NodeAffinity"},
503503
{Name: "NodeResources"},
504504
{Name: "VolumeRestrictions"},
@@ -570,7 +570,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
570570
}]
571571
}`,
572572
wantPredicates: sets.NewString(
573-
"PodFitsHostPorts",
574573
"NoVolumeZoneConflict",
575574
"CheckNodeMemoryPressure",
576575
"CheckNodeDiskPressure",
@@ -596,6 +595,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
596595
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
597596
"FilterPlugin": {
598597
{Name: "NodeName"},
598+
{Name: "NodePorts"},
599599
{Name: "NodeAffinity"},
600600
{Name: "NodeResources"},
601601
{Name: "VolumeRestrictions"},
@@ -672,7 +672,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
672672
}]
673673
}`,
674674
wantPredicates: sets.NewString(
675-
"PodFitsHostPorts",
676675
"NoVolumeZoneConflict",
677676
"CheckNodeMemoryPressure",
678677
"CheckNodeDiskPressure",
@@ -699,6 +698,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
699698
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
700699
"FilterPlugin": {
701700
{Name: "NodeName"},
701+
{Name: "NodePorts"},
702702
{Name: "NodeAffinity"},
703703
{Name: "NodeResources"},
704704
{Name: "VolumeRestrictions"},
@@ -787,7 +787,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
787787
}]
788788
}`,
789789
wantPredicates: sets.NewString(
790-
"PodFitsHostPorts",
791790
"NoVolumeZoneConflict",
792791
"CheckNodeMemoryPressure",
793792
"CheckNodeDiskPressure",
@@ -815,6 +814,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
815814
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
816815
"FilterPlugin": {
817816
{Name: "NodeName"},
817+
{Name: "NodePorts"},
818818
{Name: "NodeAffinity"},
819819
{Name: "NodeResources"},
820820
{Name: "VolumeRestrictions"},
@@ -904,7 +904,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
904904
}]
905905
}`,
906906
wantPredicates: sets.NewString(
907-
"PodFitsHostPorts",
908907
"NoVolumeZoneConflict",
909908
"CheckNodeMemoryPressure",
910909
"CheckNodeDiskPressure",
@@ -933,6 +932,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
933932
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
934933
"FilterPlugin": {
935934
{Name: "NodeName"},
935+
{Name: "NodePorts"},
936936
{Name: "NodeAffinity"},
937937
{Name: "NodeResources"},
938938
{Name: "VolumeRestrictions"},
@@ -1021,7 +1021,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
10211021
}]
10221022
}`,
10231023
wantPredicates: sets.NewString(
1024-
"PodFitsHostPorts",
10251024
"NoVolumeZoneConflict",
10261025
"CheckNodeMemoryPressure",
10271026
"CheckNodeDiskPressure",
@@ -1051,6 +1050,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
10511050
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
10521051
"FilterPlugin": {
10531052
{Name: "NodeName"},
1053+
{Name: "NodePorts"},
10541054
{Name: "NodeAffinity"},
10551055
{Name: "NodeResources"},
10561056
{Name: "VolumeRestrictions"},
@@ -1143,7 +1143,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
11431143
}]
11441144
}`,
11451145
wantPredicates: sets.NewString(
1146-
"PodFitsHostPorts",
11471146
"NoVolumeZoneConflict",
11481147
"CheckNodeMemoryPressure",
11491148
"CheckNodeDiskPressure",
@@ -1173,6 +1172,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
11731172
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
11741173
"FilterPlugin": {
11751174
{Name: "NodeName"},
1175+
{Name: "NodePorts"},
11761176
{Name: "NodeAffinity"},
11771177
{Name: "NodeResources"},
11781178
{Name: "VolumeRestrictions"},
@@ -1207,6 +1207,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
12071207
filterToPredicateMap := map[string]string{
12081208
"TaintToleration": "PodToleratesNodeTaints",
12091209
"NodeName": "HostName",
1210+
"NodePorts": "PodFitsHostPorts",
12101211
"NodeResources": "PodFitsResources",
12111212
"NodeAffinity": "MatchNodeSelector",
12121213
"VolumeBinding": "CheckVolumeBinding",

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/imagelocality:go_default_library",
1414
"//pkg/scheduler/framework/plugins/nodeaffinity:go_default_library",
1515
"//pkg/scheduler/framework/plugins/nodename:go_default_library",
16+
"//pkg/scheduler/framework/plugins/nodeports:go_default_library",
1617
"//pkg/scheduler/framework/plugins/noderesources:go_default_library",
1718
"//pkg/scheduler/framework/plugins/tainttoleration:go_default_library",
1819
"//pkg/scheduler/framework/plugins/volumebinding:go_default_library",
@@ -42,6 +43,7 @@ filegroup(
4243
"//pkg/scheduler/framework/plugins/migration:all-srcs",
4344
"//pkg/scheduler/framework/plugins/nodeaffinity:all-srcs",
4445
"//pkg/scheduler/framework/plugins/nodename:all-srcs",
46+
"//pkg/scheduler/framework/plugins/nodeports:all-srcs",
4547
"//pkg/scheduler/framework/plugins/noderesources:all-srcs",
4648
"//pkg/scheduler/framework/plugins/tainttoleration:all-srcs",
4749
"//pkg/scheduler/framework/plugins/volumebinding:all-srcs",

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/imagelocality"
3030
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeaffinity"
3131
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodename"
32+
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeports"
3233
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/noderesources"
3334
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/tainttoleration"
3435
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumebinding"
@@ -61,6 +62,7 @@ func NewDefaultRegistry(args *RegistryArgs) framework.Registry {
6162
tainttoleration.Name: tainttoleration.New,
6263
noderesources.Name: noderesources.New,
6364
nodename.Name: nodename.New,
65+
nodeports.Name: nodeports.New,
6466
nodeaffinity.Name: nodeaffinity.New,
6567
volumebinding.Name: func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
6668
return volumebinding.NewFromVolumeBinder(args.VolumeBinder), nil
@@ -108,6 +110,11 @@ func NewDefaultConfigProducerRegistry() *ConfigProducerRegistry {
108110
plugins.Filter = appendToPluginSet(plugins.Filter, nodename.Name, nil)
109111
return
110112
})
113+
registry.RegisterPredicate(predicates.PodFitsHostPortsPred,
114+
func(_ ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {
115+
plugins.Filter = appendToPluginSet(plugins.Filter, nodeports.Name, nil)
116+
return
117+
})
111118
registry.RegisterPredicate(predicates.MatchNodeSelectorPred,
112119
func(_ ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {
113120
plugins.Filter = appendToPluginSet(plugins.Filter, nodeaffinity.Name, nil)
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 = ["node_ports.go"],
6+
importpath = "k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeports",
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 = ["node_ports_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: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 nodeports
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+
// NodePorts is a plugin that checks if a node has free ports for the requested pod ports.
29+
type NodePorts struct{}
30+
31+
var _ = framework.FilterPlugin(&NodePorts{})
32+
33+
// Name is the name of the plugin used in the plugin registry and configurations.
34+
const Name = "NodePorts"
35+
36+
// Name returns name of the plugin. It is used in logs, etc.
37+
func (pl *NodePorts) Name() string {
38+
return Name
39+
}
40+
41+
// Filter invoked at the filter extension point.
42+
func (pl *NodePorts) Filter(_ *framework.CycleState, pod *v1.Pod, nodeInfo *nodeinfo.NodeInfo) *framework.Status {
43+
_, reasons, err := predicates.PodFitsHostPorts(pod, nil, nodeInfo)
44+
return migration.PredicateResultToFrameworkStatus(reasons, err)
45+
}
46+
47+
// New initializes a new plugin and returns it.
48+
func New(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
49+
return &NodePorts{}, nil
50+
}

0 commit comments

Comments
 (0)