Merge pull request #83982 from lichuqiang/frame_mig1

[migration phase 1] MatchInterPodAffinity as filter plugin
This commit is contained in:
Kubernetes Prow Robot 2019-10-18 09:23:58 -07:00 committed by GitHub
commit 27c679baca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 1584 additions and 12 deletions

View File

@ -251,7 +251,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"MaxEBSVolumeCount",
"MaxGCEPDVolumeCount",
"MaxAzureDiskVolumeCount",
"MatchInterPodAffinity",
"TestServiceAffinity",
"TestLabelsPresence",
),
@ -271,6 +270,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "VolumeRestrictions"},
{Name: "TaintToleration"},
{Name: "VolumeZone"},
{Name: "InterPodAffinity"},
},
"ScorePlugin": {
{Name: "ImageLocality", Weight: 2},
@ -321,7 +321,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"MaxEBSVolumeCount",
"MaxGCEPDVolumeCount",
"MaxAzureDiskVolumeCount",
"MatchInterPodAffinity",
"TestServiceAffinity",
"TestLabelsPresence",
),
@ -342,6 +341,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "VolumeRestrictions"},
{Name: "TaintToleration"},
{Name: "VolumeZone"},
{Name: "InterPodAffinity"},
},
"ScorePlugin": {
{Name: "ImageLocality", Weight: 2},
@ -402,7 +402,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"MaxEBSVolumeCount",
"MaxGCEPDVolumeCount",
"MaxAzureDiskVolumeCount",
"MatchInterPodAffinity",
"TestServiceAffinity",
"TestLabelsPresence",
),
@ -423,6 +422,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "VolumeRestrictions"},
{Name: "TaintToleration"},
{Name: "VolumeZone"},
{Name: "InterPodAffinity"},
},
"ScorePlugin": {
{Name: "ImageLocality", Weight: 2},
@ -496,7 +496,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"MaxEBSVolumeCount",
"MaxGCEPDVolumeCount",
"MaxAzureDiskVolumeCount",
"MatchInterPodAffinity",
"TestServiceAffinity",
"TestLabelsPresence",
),
@ -517,6 +516,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "VolumeRestrictions"},
{Name: "TaintToleration"},
{Name: "VolumeZone"},
{Name: "InterPodAffinity"},
},
"ScorePlugin": {
{Name: "ImageLocality", Weight: 2},
@ -591,7 +591,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"MaxEBSVolumeCount",
"MaxGCEPDVolumeCount",
"MaxAzureDiskVolumeCount",
"MatchInterPodAffinity",
"TestServiceAffinity",
"TestLabelsPresence",
),
@ -613,6 +612,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "TaintToleration"},
{Name: "VolumeBinding"},
{Name: "VolumeZone"},
{Name: "InterPodAffinity"},
},
"ScorePlugin": {
{Name: "ImageLocality", Weight: 2},
@ -692,7 +692,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"MaxEBSVolumeCount",
"MaxGCEPDVolumeCount",
"MaxAzureDiskVolumeCount",
"MatchInterPodAffinity",
"TestServiceAffinity",
"TestLabelsPresence",
),
@ -714,6 +713,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "TaintToleration"},
{Name: "VolumeBinding"},
{Name: "VolumeZone"},
{Name: "InterPodAffinity"},
},
"ScorePlugin": {
{Name: "ImageLocality", Weight: 2},
@ -805,7 +805,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"MaxEBSVolumeCount",
"MaxGCEPDVolumeCount",
"MaxAzureDiskVolumeCount",
"MatchInterPodAffinity",
"TestServiceAffinity",
"TestLabelsPresence",
),
@ -828,6 +827,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "TaintToleration"},
{Name: "VolumeBinding"},
{Name: "VolumeZone"},
{Name: "InterPodAffinity"},
},
"ScorePlugin": {
{Name: "ImageLocality", Weight: 2},
@ -920,7 +920,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"MaxEBSVolumeCount",
"MaxGCEPDVolumeCount",
"MaxAzureDiskVolumeCount",
"MatchInterPodAffinity",
"TestServiceAffinity",
"TestLabelsPresence",
),
@ -944,6 +943,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "NodeVolumeLimits"},
{Name: "VolumeBinding"},
{Name: "VolumeZone"},
{Name: "InterPodAffinity"},
},
"ScorePlugin": {
{Name: "ImageLocality", Weight: 2},
@ -1036,7 +1036,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"MaxGCEPDVolumeCount",
"MaxAzureDiskVolumeCount",
"MaxCinderVolumeCount",
"MatchInterPodAffinity",
"TestServiceAffinity",
"TestLabelsPresence",
),
@ -1060,6 +1059,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "NodeVolumeLimits"},
{Name: "VolumeBinding"},
{Name: "VolumeZone"},
{Name: "InterPodAffinity"},
},
"ScorePlugin": {
{Name: "ImageLocality", Weight: 2},
@ -1156,7 +1156,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"MaxGCEPDVolumeCount",
"MaxAzureDiskVolumeCount",
"MaxCinderVolumeCount",
"MatchInterPodAffinity",
"TestServiceAffinity",
"TestLabelsPresence",
),
@ -1180,6 +1179,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
{Name: "NodeVolumeLimits"},
{Name: "VolumeBinding"},
{Name: "VolumeZone"},
{Name: "InterPodAffinity"},
},
"ScorePlugin": {
{Name: "ImageLocality", Weight: 2},
@ -1219,6 +1219,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
"VolumeRestrictions": "NoDiskConflict",
"VolumeZone": "NoVolumeZoneConflict",
"NodeVolumeLimits": "MaxCSIVolumeCountPred",
"InterPodAffinity": "MatchInterPodAffinity",
}
scoreToPriorityMap := map[string]string{
"ImageLocality": "ImageLocalityPriority",

View File

@ -11,6 +11,7 @@ go_library(
"//pkg/scheduler/algorithm/priorities:go_default_library",
"//pkg/scheduler/apis/config:go_default_library",
"//pkg/scheduler/framework/plugins/imagelocality:go_default_library",
"//pkg/scheduler/framework/plugins/interpodaffinity:go_default_library",
"//pkg/scheduler/framework/plugins/nodeaffinity:go_default_library",
"//pkg/scheduler/framework/plugins/nodename:go_default_library",
"//pkg/scheduler/framework/plugins/nodeports:go_default_library",
@ -43,6 +44,7 @@ filegroup(
":package-srcs",
"//pkg/scheduler/framework/plugins/examples:all-srcs",
"//pkg/scheduler/framework/plugins/imagelocality:all-srcs",
"//pkg/scheduler/framework/plugins/interpodaffinity:all-srcs",
"//pkg/scheduler/framework/plugins/migration:all-srcs",
"//pkg/scheduler/framework/plugins/nodeaffinity:all-srcs",
"//pkg/scheduler/framework/plugins/nodename:all-srcs",

View File

@ -27,6 +27,7 @@ import (
"k8s.io/kubernetes/pkg/scheduler/algorithm/priorities"
"k8s.io/kubernetes/pkg/scheduler/apis/config"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/imagelocality"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeaffinity"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodename"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeports"
@ -82,6 +83,9 @@ func NewDefaultRegistry(args *RegistryArgs) framework.Registry {
nodevolumelimits.Name: func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
return nodevolumelimits.New(args.SchedulerCache, pvInfo, pvcInfo, classInfo), nil
},
interpodaffinity.Name: func(_ *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
return interpodaffinity.New(args.SchedulerCache, args.SchedulerCache), nil
},
}
}
@ -163,6 +167,11 @@ func NewDefaultConfigProducerRegistry() *ConfigProducerRegistry {
plugins.Filter = appendToPluginSet(plugins.Filter, nodevolumelimits.Name, nil)
return
})
registry.RegisterPredicate(predicates.MatchInterPodAffinityPred,
func(_ ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {
plugins.Filter = appendToPluginSet(plugins.Filter, interpodaffinity.Name, nil)
return
})
registry.RegisterPriority(priorities.TaintTolerationPriority,
func(args ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {

View File

@ -0,0 +1,45 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = ["interpod_affinity.go"],
importpath = "k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity",
visibility = ["//visibility:public"],
deps = [
"//pkg/scheduler/algorithm:go_default_library",
"//pkg/scheduler/algorithm/predicates:go_default_library",
"//pkg/scheduler/framework/plugins/migration:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/scheduler/nodeinfo:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
],
)
go_test(
name = "go_default_test",
srcs = ["interpod_affinity_test.go"],
embed = [":go_default_library"],
deps = [
"//pkg/scheduler/algorithm/predicates:go_default_library",
"//pkg/scheduler/framework/plugins/migration:go_default_library",
"//pkg/scheduler/framework/v1alpha1:go_default_library",
"//pkg/scheduler/nodeinfo:go_default_library",
"//pkg/scheduler/testing:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@ -0,0 +1,61 @@
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package interpodaffinity
import (
"context"
"fmt"
"k8s.io/api/core/v1"
"k8s.io/kubernetes/pkg/scheduler/algorithm"
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/migration"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
"k8s.io/kubernetes/pkg/scheduler/nodeinfo"
)
// InterPodAffinity is a plugin that checks inter pod affinity
type InterPodAffinity struct {
predicate predicates.FitPredicate
}
var _ framework.FilterPlugin = &InterPodAffinity{}
// Name is the name of the plugin used in the plugin registry and configurations.
const Name = "InterPodAffinity"
// Name returns name of the plugin. It is used in logs, etc.
func (pl *InterPodAffinity) Name() string {
return Name
}
// Filter invoked at the filter extension point.
func (pl *InterPodAffinity) Filter(ctx context.Context, cycleState *framework.CycleState, pod *v1.Pod, nodeInfo *nodeinfo.NodeInfo) *framework.Status {
meta, ok := migration.PredicateMetadata(cycleState).(predicates.PredicateMetadata)
if !ok {
return migration.ErrorToFrameworkStatus(fmt.Errorf("%+v convert to predicates.PredicateMetadata error", cycleState))
}
_, reasons, err := pl.predicate(pod, meta, nodeInfo)
return migration.PredicateResultToFrameworkStatus(reasons, err)
}
// New initializes a new plugin and returns it.
func New(nodeInfo predicates.NodeInfo, podLister algorithm.PodLister) framework.Plugin {
return &InterPodAffinity{
predicate: predicates.NewPodAffinityPredicate(nodeInfo, podLister),
}
}

File diff suppressed because it is too large Load Diff

View File

@ -129,7 +129,6 @@ func TestSchedulerCreationFromConfigMap(t *testing.T) {
"CheckNodeDiskPressure",
"CheckNodeMemoryPressure",
"CheckNodePIDPressure",
"MatchInterPodAffinity",
"MaxAzureDiskVolumeCount",
"MaxEBSVolumeCount",
"MaxGCEPDVolumeCount",
@ -151,6 +150,7 @@ func TestSchedulerCreationFromConfigMap(t *testing.T) {
{Name: "NodeVolumeLimits"},
{Name: "VolumeBinding"},
{Name: "VolumeZone"},
{Name: "InterPodAffinity"},
},
"ScorePlugin": {
{Name: "ImageLocality", Weight: 1},
@ -203,7 +203,6 @@ kind: Policy
"CheckNodeDiskPressure",
"CheckNodeMemoryPressure",
"CheckNodePIDPressure",
"MatchInterPodAffinity",
"MaxAzureDiskVolumeCount",
"MaxEBSVolumeCount",
"MaxGCEPDVolumeCount",
@ -225,6 +224,7 @@ kind: Policy
{Name: "NodeVolumeLimits"},
{Name: "VolumeBinding"},
{Name: "VolumeZone"},
{Name: "InterPodAffinity"},
},
"ScorePlugin": {
{Name: "ImageLocality", Weight: 1},