From a139da6b04874c45a854ad05cd64360a7c7dc60a Mon Sep 17 00:00:00 2001 From: kerthcet Date: Wed, 27 Oct 2021 08:05:44 +0800 Subject: [PATCH] remove scheduler NodePreferAvoidPods plugin Signed-off-by: kerthcet --- .../apis/config/testing/defaults/defaults.go | 137 --------------- .../apis/config/validation/validation.go | 2 - .../apis/config/validation/validation_test.go | 4 +- .../framework/plugins/names/names.go | 1 - .../node_prefer_avoid_pods.go | 95 ---------- .../node_prefer_avoid_pods_test.go | 164 ------------------ pkg/scheduler/framework/plugins/registry.go | 2 - 7 files changed, 2 insertions(+), 403 deletions(-) delete mode 100644 pkg/scheduler/framework/plugins/nodepreferavoidpods/node_prefer_avoid_pods.go delete mode 100644 pkg/scheduler/framework/plugins/nodepreferavoidpods/node_prefer_avoid_pods_test.go diff --git a/pkg/scheduler/apis/config/testing/defaults/defaults.go b/pkg/scheduler/apis/config/testing/defaults/defaults.go index d5da971e977..b441b8a5c9f 100644 --- a/pkg/scheduler/apis/config/testing/defaults/defaults.go +++ b/pkg/scheduler/apis/config/testing/defaults/defaults.go @@ -21,143 +21,6 @@ import ( "k8s.io/kubernetes/pkg/scheduler/framework/plugins/names" ) -// PluginsV1beta1 default set of v1beta1 plugins. -var PluginsV1beta1 = &config.Plugins{ - QueueSort: config.PluginSet{ - Enabled: []config.Plugin{ - {Name: names.PrioritySort}, - }, - }, - PreFilter: config.PluginSet{ - Enabled: []config.Plugin{ - {Name: names.NodeResourcesFit}, - {Name: names.NodePorts}, - {Name: names.VolumeRestrictions}, - {Name: names.PodTopologySpread}, - {Name: names.InterPodAffinity}, - {Name: names.VolumeBinding}, - {Name: names.NodeAffinity}, - }, - }, - Filter: config.PluginSet{ - Enabled: []config.Plugin{ - {Name: names.NodeUnschedulable}, - {Name: names.NodeName}, - {Name: names.TaintToleration}, - {Name: names.NodeAffinity}, - {Name: names.NodePorts}, - {Name: names.NodeResourcesFit}, - {Name: names.VolumeRestrictions}, - {Name: names.EBSLimits}, - {Name: names.GCEPDLimits}, - {Name: names.NodeVolumeLimits}, - {Name: names.AzureDiskLimits}, - {Name: names.VolumeBinding}, - {Name: names.VolumeZone}, - {Name: names.PodTopologySpread}, - {Name: names.InterPodAffinity}, - }, - }, - PostFilter: config.PluginSet{ - Enabled: []config.Plugin{ - {Name: names.DefaultPreemption}, - }, - }, - PreScore: config.PluginSet{ - Enabled: []config.Plugin{ - {Name: names.InterPodAffinity}, - {Name: names.PodTopologySpread}, - {Name: names.TaintToleration}, - {Name: names.NodeAffinity}, - }, - }, - Score: config.PluginSet{ - Enabled: []config.Plugin{ - {Name: names.NodeResourcesBalancedAllocation, Weight: 1}, - {Name: names.ImageLocality, Weight: 1}, - {Name: names.InterPodAffinity, Weight: 1}, - {Name: names.NodeResourcesLeastAllocated, Weight: 1}, - {Name: names.NodeAffinity, Weight: 1}, - {Name: names.NodePreferAvoidPods, Weight: 10000}, - // Weight is doubled because: - // - This is a score coming from user preference. - // - It makes its signal comparable to NodeResourcesLeastAllocated. - {Name: names.PodTopologySpread, Weight: 2}, - {Name: names.TaintToleration, Weight: 1}, - }, - }, - Reserve: config.PluginSet{ - Enabled: []config.Plugin{ - {Name: names.VolumeBinding}, - }, - }, - PreBind: config.PluginSet{ - Enabled: []config.Plugin{ - {Name: names.VolumeBinding}, - }, - }, - Bind: config.PluginSet{ - Enabled: []config.Plugin{ - {Name: names.DefaultBinder}, - }, - }, -} - -// PluginConfigsV1beta1 default plugin configurations. This could get versioned, but since -// all available versions produce the same defaults, we just have one for now. -var PluginConfigsV1beta1 = []config.PluginConfig{ - { - Name: "DefaultPreemption", - Args: &config.DefaultPreemptionArgs{ - MinCandidateNodesPercentage: 10, - MinCandidateNodesAbsolute: 100, - }, - }, - { - Name: "InterPodAffinity", - Args: &config.InterPodAffinityArgs{ - HardPodAffinityWeight: 1, - }, - }, - { - Name: "NodeAffinity", - Args: &config.NodeAffinityArgs{}, - }, - { - Name: "NodeResourcesBalancedAllocation", - Args: &config.NodeResourcesBalancedAllocationArgs{ - Resources: []config.ResourceSpec{{Name: "cpu", Weight: 1}, {Name: "memory", Weight: 1}}, - }, - }, - { - Name: "NodeResourcesFit", - Args: &config.NodeResourcesFitArgs{ - ScoringStrategy: &config.ScoringStrategy{ - Type: config.LeastAllocated, - Resources: []config.ResourceSpec{{Name: "cpu", Weight: 1}, {Name: "memory", Weight: 1}}, - }, - }, - }, - { - Name: "NodeResourcesLeastAllocated", - Args: &config.NodeResourcesLeastAllocatedArgs{ - Resources: []config.ResourceSpec{{Name: "cpu", Weight: 1}, {Name: "memory", Weight: 1}}, - }, - }, - { - Name: "PodTopologySpread", - Args: &config.PodTopologySpreadArgs{ - DefaultingType: config.SystemDefaulting, - }, - }, - { - Name: "VolumeBinding", - Args: &config.VolumeBindingArgs{ - BindTimeoutSeconds: 600, - }, - }, -} - // PluginsV1beta2 default set of v1beta2 plugins. var PluginsV1beta2 = &config.Plugins{ QueueSort: config.PluginSet{ diff --git a/pkg/scheduler/apis/config/validation/validation.go b/pkg/scheduler/apis/config/validation/validation.go index bd347fd3972..5832924a686 100644 --- a/pkg/scheduler/apis/config/validation/validation.go +++ b/pkg/scheduler/apis/config/validation/validation.go @@ -130,8 +130,6 @@ var removedPluginsByVersion = []removedPlugins{ schemeGroupVersion: v1beta2.SchemeGroupVersion.String(), plugins: []string{ "NodeLabel", - "ServiceAffinity", - "NodePreferAvoidPods", "NodeResourcesLeastAllocated", "NodeResourcesMostAllocated", "RequestedToCapacityRatio", diff --git a/pkg/scheduler/apis/config/validation/validation_test.go b/pkg/scheduler/apis/config/validation/validation_test.go index bfb9f33bc6c..6342389cf60 100644 --- a/pkg/scheduler/apis/config/validation/validation_test.go +++ b/pkg/scheduler/apis/config/validation/validation_test.go @@ -199,7 +199,7 @@ func TestValidateKubeSchedulerConfigurationV1beta2(t *testing.T) { }) badRemovedPlugins1 := validConfig.DeepCopy() - badRemovedPlugins1.Profiles[0].Plugins.Score.Enabled = append(badRemovedPlugins1.Profiles[0].Plugins.Score.Enabled, config.Plugin{Name: "ServiceAffinity", Weight: 2}) + badRemovedPlugins1.Profiles[0].Plugins.Score.Enabled = append(badRemovedPlugins1.Profiles[0].Plugins.Score.Enabled, config.Plugin{Name: "NodeLabel", Weight: 2}) badRemovedPlugins3 := validConfig.DeepCopy() badRemovedPlugins3.Profiles[0].Plugins.Score.Enabled = append(badRemovedPlugins3.Profiles[0].Plugins.Score.Enabled, config.Plugin{Name: "NodeResourcesMostAllocated", Weight: 2}) @@ -498,7 +498,7 @@ func TestValidateKubeSchedulerConfigurationV1beta3(t *testing.T) { }) badRemovedPlugins1 := validConfig.DeepCopy() - badRemovedPlugins1.Profiles[0].Plugins.Score.Enabled = append(badRemovedPlugins1.Profiles[0].Plugins.Score.Enabled, config.Plugin{Name: "ServiceAffinity", Weight: 2}) + badRemovedPlugins1.Profiles[0].Plugins.Score.Enabled = append(badRemovedPlugins1.Profiles[0].Plugins.Score.Enabled, config.Plugin{Name: "NodeLabel", Weight: 2}) badRemovedPlugins2 := validConfig.DeepCopy() badRemovedPlugins2.Profiles[0].Plugins.Score.Enabled = append(badRemovedPlugins2.Profiles[0].Plugins.Score.Enabled, config.Plugin{Name: "RequestedToCapacityRatio", Weight: 2}) diff --git a/pkg/scheduler/framework/plugins/names/names.go b/pkg/scheduler/framework/plugins/names/names.go index 744662d0b28..8f3b7a3caf6 100644 --- a/pkg/scheduler/framework/plugins/names/names.go +++ b/pkg/scheduler/framework/plugins/names/names.go @@ -26,7 +26,6 @@ const ( NodeLabel = "NodeLabel" NodeName = "NodeName" NodePorts = "NodePorts" - NodePreferAvoidPods = "NodePreferAvoidPods" NodeResourcesBalancedAllocation = "NodeResourcesBalancedAllocation" NodeResourcesFit = "NodeResourcesFit" NodeResourcesLeastAllocated = "NodeResourcesLeastAllocated" diff --git a/pkg/scheduler/framework/plugins/nodepreferavoidpods/node_prefer_avoid_pods.go b/pkg/scheduler/framework/plugins/nodepreferavoidpods/node_prefer_avoid_pods.go deleted file mode 100644 index 84956d05f3d..00000000000 --- a/pkg/scheduler/framework/plugins/nodepreferavoidpods/node_prefer_avoid_pods.go +++ /dev/null @@ -1,95 +0,0 @@ -/* -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. -*/ - -// This plugin has been deprecated and is only configurable through the -// scheduler policy API and the v1beta1 component config API. It is recommended -// to use node taints instead. -package nodepreferavoidpods - -import ( - "context" - "fmt" - - v1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - v1helper "k8s.io/component-helpers/scheduling/corev1" - "k8s.io/klog/v2" - "k8s.io/kubernetes/pkg/scheduler/framework" - "k8s.io/kubernetes/pkg/scheduler/framework/plugins/names" -) - -// NodePreferAvoidPods is a plugin that priorities nodes according to the node annotation -// "scheduler.alpha.kubernetes.io/preferAvoidPods". -type NodePreferAvoidPods struct { - handle framework.Handle -} - -var _ framework.ScorePlugin = &NodePreferAvoidPods{} - -// Name is the name of the plugin used in the plugin registry and configurations. -const Name = names.NodePreferAvoidPods - -// Name returns name of the plugin. It is used in logs, etc. -func (pl *NodePreferAvoidPods) Name() string { - return Name -} - -// Score invoked at the score extension point. -func (pl *NodePreferAvoidPods) Score(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) (int64, *framework.Status) { - nodeInfo, err := pl.handle.SnapshotSharedLister().NodeInfos().Get(nodeName) - if err != nil { - return 0, framework.AsStatus(fmt.Errorf("getting node %q from Snapshot: %w", nodeName, err)) - } - - node := nodeInfo.Node() - - controllerRef := metav1.GetControllerOf(pod) - if controllerRef != nil { - // Ignore pods that are owned by other controller than ReplicationController - // or ReplicaSet. - if controllerRef.Kind != "ReplicationController" && controllerRef.Kind != "ReplicaSet" { - controllerRef = nil - } - } - if controllerRef == nil { - return framework.MaxNodeScore, nil - } - - avoids, err := v1helper.GetAvoidPodsFromNodeAnnotations(node.Annotations) - if err != nil { - // If we cannot get annotation, assume it's schedulable there. - return framework.MaxNodeScore, nil - } - for i := range avoids.PreferAvoidPods { - avoid := &avoids.PreferAvoidPods[i] - if avoid.PodSignature.PodController.Kind == controllerRef.Kind && avoid.PodSignature.PodController.UID == controllerRef.UID { - return 0, nil - } - } - return framework.MaxNodeScore, nil -} - -// ScoreExtensions of the Score plugin. -func (pl *NodePreferAvoidPods) ScoreExtensions() framework.ScoreExtensions { - return nil -} - -// New initializes a new plugin and returns it. -func New(_ runtime.Object, h framework.Handle) (framework.Plugin, error) { - klog.Warning("NodePreferAvoidPods plugin is deprecated and will be removed in a future version; use node taints instead") - return &NodePreferAvoidPods{handle: h}, nil -} diff --git a/pkg/scheduler/framework/plugins/nodepreferavoidpods/node_prefer_avoid_pods_test.go b/pkg/scheduler/framework/plugins/nodepreferavoidpods/node_prefer_avoid_pods_test.go deleted file mode 100644 index bd32e998adf..00000000000 --- a/pkg/scheduler/framework/plugins/nodepreferavoidpods/node_prefer_avoid_pods_test.go +++ /dev/null @@ -1,164 +0,0 @@ -/* -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 nodepreferavoidpods - -import ( - "context" - "reflect" - "testing" - - v1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/kubernetes/pkg/scheduler/framework" - "k8s.io/kubernetes/pkg/scheduler/framework/runtime" - "k8s.io/kubernetes/pkg/scheduler/internal/cache" -) - -func TestNodePreferAvoidPods(t *testing.T) { - annotations1 := map[string]string{ - v1.PreferAvoidPodsAnnotationKey: ` - { - "preferAvoidPods": [ - { - "podSignature": { - "podController": { - "apiVersion": "v1", - "kind": "ReplicationController", - "name": "foo", - "uid": "abcdef123456", - "controller": true - } - }, - "reason": "some reason", - "message": "some message" - } - ] - }`, - } - annotations2 := map[string]string{ - v1.PreferAvoidPodsAnnotationKey: ` - { - "preferAvoidPods": [ - { - "podSignature": { - "podController": { - "apiVersion": "v1", - "kind": "ReplicaSet", - "name": "foo", - "uid": "qwert12345", - "controller": true - } - }, - "reason": "some reason", - "message": "some message" - } - ] - }`, - } - testNodes := []*v1.Node{ - { - ObjectMeta: metav1.ObjectMeta{Name: "machine1", Annotations: annotations1}, - }, - { - ObjectMeta: metav1.ObjectMeta{Name: "machine2", Annotations: annotations2}, - }, - { - ObjectMeta: metav1.ObjectMeta{Name: "machine3"}, - }, - } - trueVar := true - tests := []struct { - pod *v1.Pod - nodes []*v1.Node - expectedList framework.NodeScoreList - name string - }{ - { - pod: &v1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "default", - OwnerReferences: []metav1.OwnerReference{ - {Kind: "ReplicationController", Name: "foo", UID: "abcdef123456", Controller: &trueVar}, - }, - }, - }, - nodes: testNodes, - expectedList: []framework.NodeScore{{Name: "machine1", Score: 0}, {Name: "machine2", Score: framework.MaxNodeScore}, {Name: "machine3", Score: framework.MaxNodeScore}}, - name: "pod managed by ReplicationController should avoid a node, this node get lowest priority score", - }, - { - pod: &v1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "default", - OwnerReferences: []metav1.OwnerReference{ - {Kind: "RandomController", Name: "foo", UID: "abcdef123456", Controller: &trueVar}, - }, - }, - }, - nodes: testNodes, - expectedList: []framework.NodeScore{{Name: "machine1", Score: framework.MaxNodeScore}, {Name: "machine2", Score: framework.MaxNodeScore}, {Name: "machine3", Score: framework.MaxNodeScore}}, - name: "ownership by random controller should be ignored", - }, - { - pod: &v1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "default", - OwnerReferences: []metav1.OwnerReference{ - {Kind: "ReplicationController", Name: "foo", UID: "abcdef123456"}, - }, - }, - }, - nodes: testNodes, - expectedList: []framework.NodeScore{{Name: "machine1", Score: framework.MaxNodeScore}, {Name: "machine2", Score: framework.MaxNodeScore}, {Name: "machine3", Score: framework.MaxNodeScore}}, - name: "owner without Controller field set should be ignored", - }, - { - pod: &v1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "default", - OwnerReferences: []metav1.OwnerReference{ - {Kind: "ReplicaSet", Name: "foo", UID: "qwert12345", Controller: &trueVar}, - }, - }, - }, - nodes: testNodes, - expectedList: []framework.NodeScore{{Name: "machine1", Score: framework.MaxNodeScore}, {Name: "machine2", Score: 0}, {Name: "machine3", Score: framework.MaxNodeScore}}, - name: "pod managed by ReplicaSet should avoid a node, this node get lowest priority score", - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - state := framework.NewCycleState() - fh, _ := runtime.NewFramework(nil, nil, runtime.WithSnapshotSharedLister(cache.NewSnapshot(nil, test.nodes))) - p, _ := New(nil, fh) - var gotList framework.NodeScoreList - for _, n := range test.nodes { - nodeName := n.ObjectMeta.Name - score, status := p.(framework.ScorePlugin).Score(context.Background(), state, test.pod, nodeName) - if !status.IsSuccess() { - t.Errorf("unexpected error: %v", status) - } - gotList = append(gotList, framework.NodeScore{Name: nodeName, Score: score}) - } - - if !reflect.DeepEqual(test.expectedList, gotList) { - t.Errorf("expected:\n\t%+v,\ngot:\n\t%+v", test.expectedList, gotList) - } - }) - } -} diff --git a/pkg/scheduler/framework/plugins/registry.go b/pkg/scheduler/framework/plugins/registry.go index 8f6e12f6015..bfdcf6e57b9 100644 --- a/pkg/scheduler/framework/plugins/registry.go +++ b/pkg/scheduler/framework/plugins/registry.go @@ -28,7 +28,6 @@ import ( "k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodelabel" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodename" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeports" - "k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodepreferavoidpods" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/noderesources" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeunschedulable" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodevolumelimits" @@ -62,7 +61,6 @@ func NewInTreeRegistry() runtime.Registry { tainttoleration.Name: tainttoleration.New, nodename.Name: nodename.New, nodeports.Name: nodeports.New, - nodepreferavoidpods.Name: nodepreferavoidpods.New, nodeaffinity.Name: nodeaffinity.New, podtopologyspread.Name: podtopologyspread.New, nodeunschedulable.Name: nodeunschedulable.New,