From 6f3c68bd5c8185873050e9a337117571eb0e47bf Mon Sep 17 00:00:00 2001 From: Abdullah Gharaibeh Date: Fri, 13 Dec 2019 10:39:13 -0500 Subject: [PATCH] compatibility tests for default provider and mandatory filters --- .../algorithmprovider/defaults/BUILD | 5 + .../defaults/defaults_test.go | 151 ++++++++++++++++++ .../apis/config/testing/compatibility_test.go | 18 +++ 3 files changed, 174 insertions(+) diff --git a/pkg/scheduler/algorithmprovider/defaults/BUILD b/pkg/scheduler/algorithmprovider/defaults/BUILD index d896c85f4bf..8d2f49a1555 100644 --- a/pkg/scheduler/algorithmprovider/defaults/BUILD +++ b/pkg/scheduler/algorithmprovider/defaults/BUILD @@ -32,9 +32,14 @@ go_test( srcs = ["defaults_test.go"], embed = [":go_default_library"], deps = [ + "//pkg/scheduler:go_default_library", "//pkg/scheduler/algorithm/predicates:go_default_library", "//pkg/scheduler/algorithm/priorities:go_default_library", + "//pkg/scheduler/apis/config:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library", + "//staging/src/k8s.io/client-go/informers:go_default_library", + "//staging/src/k8s.io/client-go/kubernetes/fake:go_default_library", + "//vendor/github.com/google/go-cmp/cmp:go_default_library", ], ) diff --git a/pkg/scheduler/algorithmprovider/defaults/defaults_test.go b/pkg/scheduler/algorithmprovider/defaults/defaults_test.go index 3feaf3a8cb1..66d1ef233c3 100644 --- a/pkg/scheduler/algorithmprovider/defaults/defaults_test.go +++ b/pkg/scheduler/algorithmprovider/defaults/defaults_test.go @@ -19,9 +19,14 @@ package defaults import ( "testing" + "github.com/google/go-cmp/cmp" "k8s.io/apimachinery/pkg/util/sets" + "k8s.io/client-go/informers" + "k8s.io/client-go/kubernetes/fake" + "k8s.io/kubernetes/pkg/scheduler" "k8s.io/kubernetes/pkg/scheduler/algorithm/predicates" "k8s.io/kubernetes/pkg/scheduler/algorithm/priorities" + "k8s.io/kubernetes/pkg/scheduler/apis/config" ) func TestCopyAndReplace(t *testing.T) { @@ -87,3 +92,149 @@ func TestDefaultPredicates(t *testing.T) { t.Errorf("expected %v got %v", expected, result) } } + +func TestCompatibility(t *testing.T) { + // Add serialized versions of scheduler config that exercise available options to ensure compatibility between releases + testcases := []struct { + name string + provider string + wantPlugins map[string][]config.Plugin + }{ + { + name: "No Provider specified", + wantPlugins: map[string][]config.Plugin{ + "PreFilterPlugin": { + {Name: "InterPodAffinity"}, + }, + "FilterPlugin": { + {Name: "NodeUnschedulable"}, + {Name: "NodeResourcesFit"}, + {Name: "NodeName"}, + {Name: "NodePorts"}, + {Name: "NodeAffinity"}, + {Name: "VolumeRestrictions"}, + {Name: "TaintToleration"}, + {Name: "EBSLimits"}, + {Name: "GCEPDLimits"}, + {Name: "NodeVolumeLimits"}, + {Name: "AzureDiskLimits"}, + {Name: "VolumeBinding"}, + {Name: "VolumeZone"}, + {Name: "InterPodAffinity"}, + }, + "ScorePlugin": { + {Name: "NodeResourcesBalancedAllocation", Weight: 1}, + {Name: "ImageLocality", Weight: 1}, + {Name: "InterPodAffinity", Weight: 1}, + {Name: "NodeResourcesLeastAllocated", Weight: 1}, + {Name: "NodeAffinity", Weight: 1}, + {Name: "NodePreferAvoidPods", Weight: 10000}, + {Name: "DefaultPodTopologySpread", Weight: 1}, + {Name: "TaintToleration", Weight: 1}, + }, + }, + }, + { + name: "DefaultProvider", + provider: config.SchedulerDefaultProviderName, + wantPlugins: map[string][]config.Plugin{ + "PreFilterPlugin": { + {Name: "InterPodAffinity"}, + }, + "FilterPlugin": { + {Name: "NodeUnschedulable"}, + {Name: "NodeResourcesFit"}, + {Name: "NodeName"}, + {Name: "NodePorts"}, + {Name: "NodeAffinity"}, + {Name: "VolumeRestrictions"}, + {Name: "TaintToleration"}, + {Name: "EBSLimits"}, + {Name: "GCEPDLimits"}, + {Name: "NodeVolumeLimits"}, + {Name: "AzureDiskLimits"}, + {Name: "VolumeBinding"}, + {Name: "VolumeZone"}, + {Name: "InterPodAffinity"}, + }, + "ScorePlugin": { + {Name: "NodeResourcesBalancedAllocation", Weight: 1}, + {Name: "ImageLocality", Weight: 1}, + {Name: "InterPodAffinity", Weight: 1}, + {Name: "NodeResourcesLeastAllocated", Weight: 1}, + {Name: "NodeAffinity", Weight: 1}, + {Name: "NodePreferAvoidPods", Weight: 10000}, + {Name: "DefaultPodTopologySpread", Weight: 1}, + {Name: "TaintToleration", Weight: 1}, + }, + }, + }, + { + name: "ClusterAutoscalerProvider", + provider: ClusterAutoscalerProvider, + wantPlugins: map[string][]config.Plugin{ + "PreFilterPlugin": { + {Name: "InterPodAffinity"}, + }, + "FilterPlugin": { + {Name: "NodeUnschedulable"}, + {Name: "NodeResourcesFit"}, + {Name: "NodeName"}, + {Name: "NodePorts"}, + {Name: "NodeAffinity"}, + {Name: "VolumeRestrictions"}, + {Name: "TaintToleration"}, + {Name: "EBSLimits"}, + {Name: "GCEPDLimits"}, + {Name: "NodeVolumeLimits"}, + {Name: "AzureDiskLimits"}, + {Name: "VolumeBinding"}, + {Name: "VolumeZone"}, + {Name: "InterPodAffinity"}, + }, + "ScorePlugin": { + {Name: "NodeResourcesBalancedAllocation", Weight: 1}, + {Name: "ImageLocality", Weight: 1}, + {Name: "InterPodAffinity", Weight: 1}, + {Name: "NodeResourcesMostAllocated", Weight: 1}, + {Name: "NodeAffinity", Weight: 1}, + {Name: "NodePreferAvoidPods", Weight: 10000}, + {Name: "DefaultPodTopologySpread", Weight: 1}, + {Name: "TaintToleration", Weight: 1}, + }, + }, + }, + } + for _, tc := range testcases { + t.Run(tc.name, func(t *testing.T) { + var opts []scheduler.Option + if len(tc.provider) != 0 { + opts = append(opts, scheduler.WithAlgorithmSource(config.SchedulerAlgorithmSource{ + Provider: &tc.provider, + })) + } + + client := fake.NewSimpleClientset() + informerFactory := informers.NewSharedInformerFactory(client, 0) + + sched, err := scheduler.New( + client, + informerFactory, + informerFactory.Core().V1().Pods(), + nil, + make(chan struct{}), + opts..., + ) + + if err != nil { + t.Fatalf("Error constructing: %v", err) + } + + gotPlugins := sched.Framework.ListPlugins() + if diff := cmp.Diff(tc.wantPlugins, gotPlugins); diff != "" { + t.Errorf("unexpected plugins diff (-want, +got): %s", diff) + } + }) + } + +} diff --git a/pkg/scheduler/apis/config/testing/compatibility_test.go b/pkg/scheduler/apis/config/testing/compatibility_test.go index 5afb4f35e13..739900a648f 100644 --- a/pkg/scheduler/apis/config/testing/compatibility_test.go +++ b/pkg/scheduler/apis/config/testing/compatibility_test.go @@ -74,6 +74,24 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { }, }, }, + // This is a special test for the case where a policy is specified without specifying any filters. + { + name: "MandatoryFilters", + JSON: `{ + "kind": "Policy", + "apiVersion": "v1", + "predicates": [ + ], + "priorities": [ + ] + }`, + wantPlugins: map[string][]config.Plugin{ + "FilterPlugin": { + {Name: "NodeUnschedulable"}, + {Name: "TaintToleration"}, + }, + }, + }, // Do not change this JSON after the corresponding release has been tagged. // A failure indicates backwards compatibility with the specified release was broken. {