Deprecate scheduler predicate and priority factory registration
This commit is contained in:
@@ -23,7 +23,6 @@ import (
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
"k8s.io/client-go/informers"
|
||||
"k8s.io/client-go/kubernetes/fake"
|
||||
@@ -39,12 +38,11 @@ import (
|
||||
)
|
||||
|
||||
type testCase struct {
|
||||
name string
|
||||
JSON string
|
||||
featureGates map[featuregate.Feature]bool
|
||||
wantPredicates sets.String
|
||||
wantPlugins map[string][]config.Plugin
|
||||
wantExtenders []config.Extender
|
||||
name string
|
||||
JSON string
|
||||
featureGates map[featuregate.Feature]bool
|
||||
wantPlugins map[string][]config.Plugin
|
||||
wantExtenders []config.Extender
|
||||
}
|
||||
|
||||
func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
@@ -117,16 +115,15 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
{"name": "TestLabelPreference", "weight": 4, "argument": {"labelPreference": {"label": "bar", "presence":true}}}
|
||||
]
|
||||
}`,
|
||||
wantPredicates: sets.NewString(
|
||||
"PodFitsPorts",
|
||||
),
|
||||
wantPlugins: map[string][]config.Plugin{
|
||||
"PreFilterPlugin": {
|
||||
{Name: "NodePorts"},
|
||||
{Name: "NodeResourcesFit"},
|
||||
{Name: "ServiceAffinity"},
|
||||
},
|
||||
"FilterPlugin": {
|
||||
{Name: "NodeUnschedulable"},
|
||||
{Name: "NodePorts"},
|
||||
{Name: "NodeAffinity"},
|
||||
{Name: "NodeResourcesFit"},
|
||||
{Name: "VolumeRestrictions"},
|
||||
@@ -166,7 +163,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
{"name": "TestLabelPreference", "weight": 4, "argument": {"labelPreference": {"label": "bar", "presence":true}}}
|
||||
]
|
||||
}`,
|
||||
wantPredicates: sets.NewString(),
|
||||
wantPlugins: map[string][]config.Plugin{
|
||||
"PreFilterPlugin": {
|
||||
{Name: "NodePorts"},
|
||||
@@ -223,7 +219,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
{"name": "TestLabelPreference", "weight": 4, "argument": {"labelPreference": {"label": "bar", "presence":true}}}
|
||||
]
|
||||
}`,
|
||||
wantPredicates: sets.NewString(),
|
||||
wantPlugins: map[string][]config.Plugin{
|
||||
"PreFilterPlugin": {
|
||||
{Name: "NodePorts"},
|
||||
@@ -289,7 +284,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
{"name": "InterPodAffinityPriority", "weight": 2}
|
||||
]
|
||||
}`,
|
||||
wantPredicates: sets.NewString(),
|
||||
wantPlugins: map[string][]config.Plugin{
|
||||
"PreFilterPlugin": {
|
||||
{Name: "NodePorts"},
|
||||
@@ -363,7 +357,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
{"name": "MostRequestedPriority", "weight": 2}
|
||||
]
|
||||
}`,
|
||||
wantPredicates: sets.NewString(),
|
||||
wantPlugins: map[string][]config.Plugin{
|
||||
"PreFilterPlugin": {
|
||||
{Name: "NodePorts"},
|
||||
@@ -448,7 +441,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
"nodeCacheCapable": true
|
||||
}]
|
||||
}`,
|
||||
wantPredicates: sets.NewString(),
|
||||
wantPlugins: map[string][]config.Plugin{
|
||||
"PreFilterPlugin": {
|
||||
{Name: "NodePorts"},
|
||||
@@ -544,7 +536,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
"nodeCacheCapable": true
|
||||
}]
|
||||
}`,
|
||||
wantPredicates: sets.NewString(),
|
||||
wantPlugins: map[string][]config.Plugin{
|
||||
"PreFilterPlugin": {
|
||||
{Name: "NodePorts"},
|
||||
@@ -641,7 +632,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
"nodeCacheCapable": true
|
||||
}]
|
||||
}`,
|
||||
wantPredicates: sets.NewString(),
|
||||
wantPlugins: map[string][]config.Plugin{
|
||||
"PreFilterPlugin": {
|
||||
{Name: "NodePorts"},
|
||||
@@ -742,7 +732,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
"ignorable":true
|
||||
}]
|
||||
}`,
|
||||
wantPredicates: sets.NewString(),
|
||||
wantPlugins: map[string][]config.Plugin{
|
||||
"PreFilterPlugin": {
|
||||
{Name: "NodePorts"},
|
||||
@@ -855,7 +844,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
"ignorable":true
|
||||
}]
|
||||
}`,
|
||||
wantPredicates: sets.NewString(),
|
||||
wantPlugins: map[string][]config.Plugin{
|
||||
"PreFilterPlugin": {
|
||||
{Name: "NodePorts"},
|
||||
@@ -970,7 +958,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
"ignorable":true
|
||||
}]
|
||||
}`,
|
||||
wantPredicates: sets.NewString(),
|
||||
wantPlugins: map[string][]config.Plugin{
|
||||
"PreFilterPlugin": {
|
||||
{Name: "NodePorts"},
|
||||
@@ -1085,7 +1072,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
"ignorable":true
|
||||
}]
|
||||
}`,
|
||||
wantPredicates: sets.NewString(),
|
||||
wantPlugins: map[string][]config.Plugin{
|
||||
"PreFilterPlugin": {
|
||||
{Name: "NodePorts"},
|
||||
@@ -1205,7 +1191,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
"ignorable":true
|
||||
}]
|
||||
}`,
|
||||
wantPredicates: sets.NewString(),
|
||||
wantPlugins: map[string][]config.Plugin{
|
||||
"PreFilterPlugin": {
|
||||
{Name: "NodePorts"},
|
||||
@@ -1319,55 +1304,12 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
registeredPredicates := sets.NewString(scheduler.ListRegisteredFitPredicates()...)
|
||||
seenPredicates := sets.NewString()
|
||||
seenPriorities := sets.NewString()
|
||||
mandatoryPredicates := sets.NewString()
|
||||
generalPredicateFilters := []string{"NodeResourcesFit", "NodeName", "NodePorts", "NodeAffinity"}
|
||||
filterToPredicateMap := map[string]string{
|
||||
"NodeUnschedulable": "CheckNodeUnschedulable",
|
||||
"TaintToleration": "PodToleratesNodeTaints",
|
||||
"NodeName": "HostName",
|
||||
"NodePorts": "PodFitsHostPorts",
|
||||
"NodeResourcesFit": "PodFitsResources",
|
||||
"NodeAffinity": "MatchNodeSelector",
|
||||
"VolumeBinding": "CheckVolumeBinding",
|
||||
"VolumeRestrictions": "NoDiskConflict",
|
||||
"VolumeZone": "NoVolumeZoneConflict",
|
||||
"NodeVolumeLimits": "MaxCSIVolumeCountPred",
|
||||
"EBSLimits": "MaxEBSVolumeCount",
|
||||
"GCEPDLimits": "MaxGCEPDVolumeCount",
|
||||
"AzureDiskLimits": "MaxAzureDiskVolumeCount",
|
||||
"CinderLimits": "MaxCinderVolumeCount",
|
||||
"InterPodAffinity": "MatchInterPodAffinity",
|
||||
"PodTopologySpread": "EvenPodsSpread",
|
||||
}
|
||||
scoreToPriorityMap := map[string]string{
|
||||
"DefaultPodTopologySpread": "SelectorSpreadPriority",
|
||||
"ImageLocality": "ImageLocalityPriority",
|
||||
"InterPodAffinity": "InterPodAffinityPriority",
|
||||
"NodeAffinity": "NodeAffinityPriority",
|
||||
"NodePreferAvoidPods": "NodePreferAvoidPodsPriority",
|
||||
"TaintToleration": "TaintTolerationPriority",
|
||||
"NodeResourcesLeastAllocated": "LeastRequestedPriority",
|
||||
"NodeResourcesBalancedAllocation": "BalancedResourceAllocation",
|
||||
"NodeResourcesMostAllocated": "MostRequestedPriority",
|
||||
"RequestedToCapacityRatio": "RequestedToCapacityRatioPriority",
|
||||
"NodeLabel": "TestLabelPreference",
|
||||
"ServiceAffinity": "TestServiceAntiAffinity",
|
||||
"ResourceLimitsPriority": "NodeResourceLimits",
|
||||
}
|
||||
|
||||
for _, tc := range testcases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
for feature, value := range tc.featureGates {
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, feature, value)()
|
||||
}
|
||||
defer algorithmprovider.ApplyFeatureGates()()
|
||||
if len(tc.featureGates) > 0 {
|
||||
// The enabled featuregate can register more predicates
|
||||
registeredPredicates = registeredPredicates.Union(sets.NewString(scheduler.ListRegisteredFitPredicates()...))
|
||||
}
|
||||
policyConfigMap := v1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{Namespace: metav1.NamespaceSystem, Name: "scheduler-custom-policy-config"},
|
||||
Data: map[string]string{config.SchedulerPolicyConfigMapKey: tc.JSON},
|
||||
@@ -1395,28 +1337,8 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Error constructing: %v", err)
|
||||
}
|
||||
gotPredicates := sets.NewString()
|
||||
for p := range sched.Algorithm.Predicates() {
|
||||
gotPredicates.Insert(p)
|
||||
}
|
||||
wantPredicates := tc.wantPredicates.Union(mandatoryPredicates)
|
||||
if !gotPredicates.Equal(wantPredicates) {
|
||||
t.Errorf("Got predicates %v, want %v", gotPredicates, wantPredicates)
|
||||
}
|
||||
|
||||
gotPlugins := sched.Framework.ListPlugins()
|
||||
for _, p := range gotPlugins["FilterPlugin"] {
|
||||
seenPredicates.Insert(filterToPredicateMap[p.Name])
|
||||
|
||||
}
|
||||
if pluginsToStringSet(gotPlugins["FilterPlugin"]).HasAll(generalPredicateFilters...) {
|
||||
seenPredicates.Insert("GeneralPredicates")
|
||||
}
|
||||
for _, p := range gotPlugins["ScorePlugin"] {
|
||||
seenPriorities.Insert(scoreToPriorityMap[p.Name])
|
||||
|
||||
}
|
||||
|
||||
if diff := cmp.Diff(tc.wantPlugins, gotPlugins); diff != "" {
|
||||
t.Errorf("unexpected plugins diff (-want, +got): %s", diff)
|
||||
}
|
||||
@@ -1435,20 +1357,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||
t.Errorf("Got extender #%d %+v, want %+v", i, gotExtenders[i], wantExtenders[i])
|
||||
}
|
||||
}
|
||||
|
||||
seenPredicates = seenPredicates.Union(gotPredicates)
|
||||
})
|
||||
}
|
||||
|
||||
if !seenPredicates.HasAll(registeredPredicates.List()...) {
|
||||
t.Errorf("Registered predicates are missing from compatibility test (add to test stanza for version currently in development): %#v", registeredPredicates.Difference(seenPredicates).List())
|
||||
}
|
||||
}
|
||||
|
||||
func pluginsToStringSet(plugins []config.Plugin) sets.String {
|
||||
s := sets.NewString()
|
||||
for _, p := range plugins {
|
||||
s.Insert(p.Name)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
Reference in New Issue
Block a user