Skip to content

Commit 27c679b

Browse files
authored
Merge pull request kubernetes#83982 from lichuqiang/frame_mig1
[migration phase 1] MatchInterPodAffinity as filter plugin
2 parents 4222561 + 671f769 commit 27c679b

File tree

7 files changed

+1584
-12
lines changed

7 files changed

+1584
-12
lines changed

pkg/scheduler/api/compatibility/compatibility_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
251251
"MaxEBSVolumeCount",
252252
"MaxGCEPDVolumeCount",
253253
"MaxAzureDiskVolumeCount",
254-
"MatchInterPodAffinity",
255254
"TestServiceAffinity",
256255
"TestLabelsPresence",
257256
),
@@ -271,6 +270,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
271270
{Name: "VolumeRestrictions"},
272271
{Name: "TaintToleration"},
273272
{Name: "VolumeZone"},
273+
{Name: "InterPodAffinity"},
274274
},
275275
"ScorePlugin": {
276276
{Name: "ImageLocality", Weight: 2},
@@ -321,7 +321,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
321321
"MaxEBSVolumeCount",
322322
"MaxGCEPDVolumeCount",
323323
"MaxAzureDiskVolumeCount",
324-
"MatchInterPodAffinity",
325324
"TestServiceAffinity",
326325
"TestLabelsPresence",
327326
),
@@ -342,6 +341,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
342341
{Name: "VolumeRestrictions"},
343342
{Name: "TaintToleration"},
344343
{Name: "VolumeZone"},
344+
{Name: "InterPodAffinity"},
345345
},
346346
"ScorePlugin": {
347347
{Name: "ImageLocality", Weight: 2},
@@ -402,7 +402,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
402402
"MaxEBSVolumeCount",
403403
"MaxGCEPDVolumeCount",
404404
"MaxAzureDiskVolumeCount",
405-
"MatchInterPodAffinity",
406405
"TestServiceAffinity",
407406
"TestLabelsPresence",
408407
),
@@ -423,6 +422,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
423422
{Name: "VolumeRestrictions"},
424423
{Name: "TaintToleration"},
425424
{Name: "VolumeZone"},
425+
{Name: "InterPodAffinity"},
426426
},
427427
"ScorePlugin": {
428428
{Name: "ImageLocality", Weight: 2},
@@ -496,7 +496,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
496496
"MaxEBSVolumeCount",
497497
"MaxGCEPDVolumeCount",
498498
"MaxAzureDiskVolumeCount",
499-
"MatchInterPodAffinity",
500499
"TestServiceAffinity",
501500
"TestLabelsPresence",
502501
),
@@ -517,6 +516,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
517516
{Name: "VolumeRestrictions"},
518517
{Name: "TaintToleration"},
519518
{Name: "VolumeZone"},
519+
{Name: "InterPodAffinity"},
520520
},
521521
"ScorePlugin": {
522522
{Name: "ImageLocality", Weight: 2},
@@ -591,7 +591,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
591591
"MaxEBSVolumeCount",
592592
"MaxGCEPDVolumeCount",
593593
"MaxAzureDiskVolumeCount",
594-
"MatchInterPodAffinity",
595594
"TestServiceAffinity",
596595
"TestLabelsPresence",
597596
),
@@ -613,6 +612,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
613612
{Name: "TaintToleration"},
614613
{Name: "VolumeBinding"},
615614
{Name: "VolumeZone"},
615+
{Name: "InterPodAffinity"},
616616
},
617617
"ScorePlugin": {
618618
{Name: "ImageLocality", Weight: 2},
@@ -692,7 +692,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
692692
"MaxEBSVolumeCount",
693693
"MaxGCEPDVolumeCount",
694694
"MaxAzureDiskVolumeCount",
695-
"MatchInterPodAffinity",
696695
"TestServiceAffinity",
697696
"TestLabelsPresence",
698697
),
@@ -714,6 +713,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
714713
{Name: "TaintToleration"},
715714
{Name: "VolumeBinding"},
716715
{Name: "VolumeZone"},
716+
{Name: "InterPodAffinity"},
717717
},
718718
"ScorePlugin": {
719719
{Name: "ImageLocality", Weight: 2},
@@ -805,7 +805,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
805805
"MaxEBSVolumeCount",
806806
"MaxGCEPDVolumeCount",
807807
"MaxAzureDiskVolumeCount",
808-
"MatchInterPodAffinity",
809808
"TestServiceAffinity",
810809
"TestLabelsPresence",
811810
),
@@ -828,6 +827,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
828827
{Name: "TaintToleration"},
829828
{Name: "VolumeBinding"},
830829
{Name: "VolumeZone"},
830+
{Name: "InterPodAffinity"},
831831
},
832832
"ScorePlugin": {
833833
{Name: "ImageLocality", Weight: 2},
@@ -920,7 +920,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
920920
"MaxEBSVolumeCount",
921921
"MaxGCEPDVolumeCount",
922922
"MaxAzureDiskVolumeCount",
923-
"MatchInterPodAffinity",
924923
"TestServiceAffinity",
925924
"TestLabelsPresence",
926925
),
@@ -944,6 +943,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
944943
{Name: "NodeVolumeLimits"},
945944
{Name: "VolumeBinding"},
946945
{Name: "VolumeZone"},
946+
{Name: "InterPodAffinity"},
947947
},
948948
"ScorePlugin": {
949949
{Name: "ImageLocality", Weight: 2},
@@ -1036,7 +1036,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
10361036
"MaxGCEPDVolumeCount",
10371037
"MaxAzureDiskVolumeCount",
10381038
"MaxCinderVolumeCount",
1039-
"MatchInterPodAffinity",
10401039
"TestServiceAffinity",
10411040
"TestLabelsPresence",
10421041
),
@@ -1060,6 +1059,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
10601059
{Name: "NodeVolumeLimits"},
10611060
{Name: "VolumeBinding"},
10621061
{Name: "VolumeZone"},
1062+
{Name: "InterPodAffinity"},
10631063
},
10641064
"ScorePlugin": {
10651065
{Name: "ImageLocality", Weight: 2},
@@ -1156,7 +1156,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
11561156
"MaxGCEPDVolumeCount",
11571157
"MaxAzureDiskVolumeCount",
11581158
"MaxCinderVolumeCount",
1159-
"MatchInterPodAffinity",
11601159
"TestServiceAffinity",
11611160
"TestLabelsPresence",
11621161
),
@@ -1180,6 +1179,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
11801179
{Name: "NodeVolumeLimits"},
11811180
{Name: "VolumeBinding"},
11821181
{Name: "VolumeZone"},
1182+
{Name: "InterPodAffinity"},
11831183
},
11841184
"ScorePlugin": {
11851185
{Name: "ImageLocality", Weight: 2},
@@ -1219,6 +1219,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
12191219
"VolumeRestrictions": "NoDiskConflict",
12201220
"VolumeZone": "NoVolumeZoneConflict",
12211221
"NodeVolumeLimits": "MaxCSIVolumeCountPred",
1222+
"InterPodAffinity": "MatchInterPodAffinity",
12221223
}
12231224
scoreToPriorityMap := map[string]string{
12241225
"ImageLocality": "ImageLocalityPriority",

pkg/scheduler/framework/plugins/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ go_library(
1111
"//pkg/scheduler/algorithm/priorities:go_default_library",
1212
"//pkg/scheduler/apis/config:go_default_library",
1313
"//pkg/scheduler/framework/plugins/imagelocality:go_default_library",
14+
"//pkg/scheduler/framework/plugins/interpodaffinity:go_default_library",
1415
"//pkg/scheduler/framework/plugins/nodeaffinity:go_default_library",
1516
"//pkg/scheduler/framework/plugins/nodename:go_default_library",
1617
"//pkg/scheduler/framework/plugins/nodeports:go_default_library",
@@ -43,6 +44,7 @@ filegroup(
4344
":package-srcs",
4445
"//pkg/scheduler/framework/plugins/examples:all-srcs",
4546
"//pkg/scheduler/framework/plugins/imagelocality:all-srcs",
47+
"//pkg/scheduler/framework/plugins/interpodaffinity:all-srcs",
4648
"//pkg/scheduler/framework/plugins/migration:all-srcs",
4749
"//pkg/scheduler/framework/plugins/nodeaffinity:all-srcs",
4850
"//pkg/scheduler/framework/plugins/nodename:all-srcs",

pkg/scheduler/framework/plugins/default_registry.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"k8s.io/kubernetes/pkg/scheduler/algorithm/priorities"
2828
"k8s.io/kubernetes/pkg/scheduler/apis/config"
2929
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/imagelocality"
30+
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity"
3031
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeaffinity"
3132
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodename"
3233
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeports"
@@ -82,6 +83,9 @@ func NewDefaultRegistry(args *RegistryArgs) framework.Registry {
8283
nodevolumelimits.Name: func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
8384
return nodevolumelimits.New(args.SchedulerCache, pvInfo, pvcInfo, classInfo), nil
8485
},
86+
interpodaffinity.Name: func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
87+
return interpodaffinity.New(args.SchedulerCache, args.SchedulerCache), nil
88+
},
8589
}
8690
}
8791

@@ -163,6 +167,11 @@ func NewDefaultConfigProducerRegistry() *ConfigProducerRegistry {
163167
plugins.Filter = appendToPluginSet(plugins.Filter, nodevolumelimits.Name, nil)
164168
return
165169
})
170+
registry.RegisterPredicate(predicates.MatchInterPodAffinityPred,
171+
func(_ ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {
172+
plugins.Filter = appendToPluginSet(plugins.Filter, interpodaffinity.Name, nil)
173+
return
174+
})
166175

167176
registry.RegisterPriority(priorities.TaintTolerationPriority,
168177
func(args ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
2+
3+
go_library(
4+
name = "go_default_library",
5+
srcs = ["interpod_affinity.go"],
6+
importpath = "k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity",
7+
visibility = ["//visibility:public"],
8+
deps = [
9+
"//pkg/scheduler/algorithm:go_default_library",
10+
"//pkg/scheduler/algorithm/predicates:go_default_library",
11+
"//pkg/scheduler/framework/plugins/migration:go_default_library",
12+
"//pkg/scheduler/framework/v1alpha1:go_default_library",
13+
"//pkg/scheduler/nodeinfo:go_default_library",
14+
"//staging/src/k8s.io/api/core/v1:go_default_library",
15+
],
16+
)
17+
18+
go_test(
19+
name = "go_default_test",
20+
srcs = ["interpod_affinity_test.go"],
21+
embed = [":go_default_library"],
22+
deps = [
23+
"//pkg/scheduler/algorithm/predicates:go_default_library",
24+
"//pkg/scheduler/framework/plugins/migration:go_default_library",
25+
"//pkg/scheduler/framework/v1alpha1:go_default_library",
26+
"//pkg/scheduler/nodeinfo:go_default_library",
27+
"//pkg/scheduler/testing:go_default_library",
28+
"//staging/src/k8s.io/api/core/v1:go_default_library",
29+
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
30+
],
31+
)
32+
33+
filegroup(
34+
name = "package-srcs",
35+
srcs = glob(["**"]),
36+
tags = ["automanaged"],
37+
visibility = ["//visibility:private"],
38+
)
39+
40+
filegroup(
41+
name = "all-srcs",
42+
srcs = [":package-srcs"],
43+
tags = ["automanaged"],
44+
visibility = ["//visibility:public"],
45+
)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 interpodaffinity
18+
19+
import (
20+
"context"
21+
"fmt"
22+
23+
"k8s.io/api/core/v1"
24+
"k8s.io/kubernetes/pkg/scheduler/algorithm"
25+
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
26+
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/migration"
27+
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
28+
"k8s.io/kubernetes/pkg/scheduler/nodeinfo"
29+
)
30+
31+
// InterPodAffinity is a plugin that checks inter pod affinity
32+
type InterPodAffinity struct {
33+
predicate predicates.FitPredicate
34+
}
35+
36+
var _ framework.FilterPlugin = &InterPodAffinity{}
37+
38+
// Name is the name of the plugin used in the plugin registry and configurations.
39+
const Name = "InterPodAffinity"
40+
41+
// Name returns name of the plugin. It is used in logs, etc.
42+
func (pl *InterPodAffinity) Name() string {
43+
return Name
44+
}
45+
46+
// Filter invoked at the filter extension point.
47+
func (pl *InterPodAffinity) Filter(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod, nodeInfo *nodeinfo.NodeInfo) *framework.Status {
48+
meta, ok := migration.PredicateMetadata(cycleState).(predicates.PredicateMetadata)
49+
if !ok {
50+
return migration.ErrorToFrameworkStatus(fmt.Errorf("%+v convert to predicates.PredicateMetadata error", cycleState))
51+
}
52+
_, reasons, err := pl.predicate(pod, meta, nodeInfo)
53+
return migration.PredicateResultToFrameworkStatus(reasons, err)
54+
}
55+
56+
// New initializes a new plugin and returns it.
57+
func New(nodeInfo predicates.NodeInfo, podLister algorithm.PodLister) framework.Plugin {
58+
return &InterPodAffinity{
59+
predicate: predicates.NewPodAffinityPredicate(nodeInfo, podLister),
60+
}
61+
}

0 commit comments

Comments
 (0)