Skip to content

Commit 78be6a6

Browse files
committed
[migration phase 1] PodFitsHostPorts as filter plugin
1 parent a783404 commit 78be6a6

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",
@@ -181,6 +180,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
181180
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
182181
"FilterPlugin": {
183182
{Name: "NodeName"},
183+
{Name: "NodePorts"},
184184
{Name: "NodeAffinity"},
185185
{Name: "NodeResources"},
186186
{Name: "VolumeRestrictions"},
@@ -222,7 +222,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
222222
]
223223
}`,
224224
wantPredicates: sets.NewString(
225-
"PodFitsHostPorts",
226225
"NoVolumeZoneConflict",
227226
"CheckNodeMemoryPressure",
228227
"MaxEBSVolumeCount",
@@ -245,6 +244,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
245244
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
246245
"FilterPlugin": {
247246
{Name: "NodeName"},
247+
{Name: "NodePorts"},
248248
{Name: "NodeAffinity"},
249249
{Name: "NodeResources"},
250250
{Name: "VolumeRestrictions"},
@@ -291,7 +291,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
291291
]
292292
}`,
293293
wantPredicates: sets.NewString(
294-
"PodFitsHostPorts",
295294
"NoVolumeZoneConflict",
296295
"CheckNodeMemoryPressure",
297296
"CheckNodeDiskPressure",
@@ -317,6 +316,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
317316
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
318317
"FilterPlugin": {
319318
{Name: "NodeName"},
319+
{Name: "NodePorts"},
320320
{Name: "NodeAffinity"},
321321
{Name: "NodeResources"},
322322
{Name: "VolumeRestrictions"},
@@ -372,7 +372,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
372372
}]
373373
}`,
374374
wantPredicates: sets.NewString(
375-
"PodFitsHostPorts",
376375
"NoVolumeZoneConflict",
377376
"CheckNodeMemoryPressure",
378377
"CheckNodeDiskPressure",
@@ -398,6 +397,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
398397
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
399398
"FilterPlugin": {
400399
{Name: "NodeName"},
400+
{Name: "NodePorts"},
401401
{Name: "NodeAffinity"},
402402
{Name: "NodeResources"},
403403
{Name: "VolumeRestrictions"},
@@ -465,7 +465,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
465465
}]
466466
}`,
467467
wantPredicates: sets.NewString(
468-
"PodFitsHostPorts",
469468
"NoVolumeZoneConflict",
470469
"CheckNodeMemoryPressure",
471470
"CheckNodeDiskPressure",
@@ -492,6 +491,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
492491
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
493492
"FilterPlugin": {
494493
{Name: "NodeName"},
494+
{Name: "NodePorts"},
495495
{Name: "NodeAffinity"},
496496
{Name: "NodeResources"},
497497
{Name: "VolumeRestrictions"},
@@ -560,7 +560,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
560560
}]
561561
}`,
562562
wantPredicates: sets.NewString(
563-
"PodFitsHostPorts",
564563
"NoVolumeZoneConflict",
565564
"CheckNodeMemoryPressure",
566565
"CheckNodeDiskPressure",
@@ -587,6 +586,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
587586
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
588587
"FilterPlugin": {
589588
{Name: "NodeName"},
589+
{Name: "NodePorts"},
590590
{Name: "NodeAffinity"},
591591
{Name: "NodeResources"},
592592
{Name: "VolumeRestrictions"},
@@ -660,7 +660,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
660660
}]
661661
}`,
662662
wantPredicates: sets.NewString(
663-
"PodFitsHostPorts",
664663
"NoVolumeZoneConflict",
665664
"CheckNodeMemoryPressure",
666665
"CheckNodeDiskPressure",
@@ -688,6 +687,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
688687
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
689688
"FilterPlugin": {
690689
{Name: "NodeName"},
690+
{Name: "NodePorts"},
691691
{Name: "NodeAffinity"},
692692
{Name: "NodeResources"},
693693
{Name: "VolumeRestrictions"},
@@ -773,7 +773,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
773773
}]
774774
}`,
775775
wantPredicates: sets.NewString(
776-
"PodFitsHostPorts",
777776
"NoVolumeZoneConflict",
778777
"CheckNodeMemoryPressure",
779778
"CheckNodeDiskPressure",
@@ -802,6 +801,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
802801
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
803802
"FilterPlugin": {
804803
{Name: "NodeName"},
804+
{Name: "NodePorts"},
805805
{Name: "NodeAffinity"},
806806
{Name: "NodeResources"},
807807
{Name: "VolumeRestrictions"},
@@ -888,7 +888,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
888888
}]
889889
}`,
890890
wantPredicates: sets.NewString(
891-
"PodFitsHostPorts",
892891
"NoVolumeZoneConflict",
893892
"CheckNodeMemoryPressure",
894893
"CheckNodeDiskPressure",
@@ -918,6 +917,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
918917
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
919918
"FilterPlugin": {
920919
{Name: "NodeName"},
920+
{Name: "NodePorts"},
921921
{Name: "NodeAffinity"},
922922
{Name: "NodeResources"},
923923
{Name: "VolumeRestrictions"},
@@ -1003,7 +1003,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
10031003
}]
10041004
}`,
10051005
wantPredicates: sets.NewString(
1006-
"PodFitsHostPorts",
10071006
"NoVolumeZoneConflict",
10081007
"CheckNodeMemoryPressure",
10091008
"CheckNodeDiskPressure",
@@ -1034,6 +1033,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
10341033
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
10351034
"FilterPlugin": {
10361035
{Name: "NodeName"},
1036+
{Name: "NodePorts"},
10371037
{Name: "NodeAffinity"},
10381038
{Name: "NodeResources"},
10391039
{Name: "VolumeRestrictions"},
@@ -1123,7 +1123,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
11231123
}]
11241124
}`,
11251125
wantPredicates: sets.NewString(
1126-
"PodFitsHostPorts",
11271126
"NoVolumeZoneConflict",
11281127
"CheckNodeMemoryPressure",
11291128
"CheckNodeDiskPressure",
@@ -1154,6 +1153,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
11541153
wantPlugins: map[string][]kubeschedulerconfig.Plugin{
11551154
"FilterPlugin": {
11561155
{Name: "NodeName"},
1156+
{Name: "NodePorts"},
11571157
{Name: "NodeAffinity"},
11581158
{Name: "NodeResources"},
11591159
{Name: "VolumeRestrictions"},
@@ -1185,6 +1185,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
11851185
filterToPredicateMap := map[string]string{
11861186
"TaintToleration": "PodToleratesNodeTaints",
11871187
"NodeName": "HostName",
1188+
"NodePorts": "PodFitsHostPorts",
11881189
"NodeResources": "PodFitsResources",
11891190
"NodeAffinity": "MatchNodeSelector",
11901191
"VolumeBinding": "CheckVolumeBinding",

pkg/scheduler/framework/plugins/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ go_library(
1212
"//pkg/scheduler/apis/config:go_default_library",
1313
"//pkg/scheduler/framework/plugins/nodeaffinity:go_default_library",
1414
"//pkg/scheduler/framework/plugins/nodename:go_default_library",
15+
"//pkg/scheduler/framework/plugins/nodeports:go_default_library",
1516
"//pkg/scheduler/framework/plugins/noderesources:go_default_library",
1617
"//pkg/scheduler/framework/plugins/tainttoleration:go_default_library",
1718
"//pkg/scheduler/framework/plugins/volumebinding:go_default_library",
@@ -40,6 +41,7 @@ filegroup(
4041
"//pkg/scheduler/framework/plugins/migration:all-srcs",
4142
"//pkg/scheduler/framework/plugins/nodeaffinity:all-srcs",
4243
"//pkg/scheduler/framework/plugins/nodename:all-srcs",
44+
"//pkg/scheduler/framework/plugins/nodeports:all-srcs",
4345
"//pkg/scheduler/framework/plugins/noderesources:all-srcs",
4446
"//pkg/scheduler/framework/plugins/tainttoleration:all-srcs",
4547
"//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
@@ -28,6 +28,7 @@ import (
2828
"k8s.io/kubernetes/pkg/scheduler/apis/config"
2929
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeaffinity"
3030
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodename"
31+
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeports"
3132
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/noderesources"
3233
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/tainttoleration"
3334
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumebinding"
@@ -59,6 +60,7 @@ func NewDefaultRegistry(args *RegistryArgs) framework.Registry {
5960
tainttoleration.Name: tainttoleration.New,
6061
noderesources.Name: noderesources.New,
6162
nodename.Name: nodename.New,
63+
nodeports.Name: nodeports.New,
6264
nodeaffinity.Name: nodeaffinity.New,
6365
volumebinding.Name: func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
6466
return volumebinding.NewFromVolumeBinder(args.VolumeBinder), nil
@@ -106,6 +108,11 @@ func NewDefaultConfigProducerRegistry() *ConfigProducerRegistry {
106108
plugins.Filter = appendToPluginSet(plugins.Filter, nodename.Name, nil)
107109
return
108110
})
111+
registry.RegisterPredicate(predicates.PodFitsHostPortsPred,
112+
func(_ ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {
113+
plugins.Filter = appendToPluginSet(plugins.Filter, nodeports.Name, nil)
114+
return
115+
})
109116
registry.RegisterPredicate(predicates.MatchNodeSelectorPred,
110117
func(_ ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {
111118
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)