Move Scheduler plugin args validation to apis/config/validation

This commit is contained in:
Rafal Wicha
2020-05-18 21:06:38 +01:00
parent 4e8b56e667
commit 85be9c1673
12 changed files with 380 additions and 326 deletions

View File

@@ -27,67 +27,6 @@ import (
"k8s.io/kubernetes/pkg/scheduler/internal/cache"
)
func TestValidateNodeLabelArgs(t *testing.T) {
tests := []struct {
name string
args config.NodeLabelArgs
err bool
}{
{
name: "happy case",
args: config.NodeLabelArgs{
PresentLabels: []string{"foo", "bar"},
AbsentLabels: []string{"baz"},
PresentLabelsPreference: []string{"foo", "bar"},
AbsentLabelsPreference: []string{"baz"},
},
},
{
name: "label presence conflict",
// "bar" exists in both present and absent labels therefore validation should fail.
args: config.NodeLabelArgs{
PresentLabels: []string{"foo", "bar"},
AbsentLabels: []string{"bar", "baz"},
PresentLabelsPreference: []string{"foo", "bar"},
AbsentLabelsPreference: []string{"baz"},
},
err: true,
},
{
name: "label preference conflict",
// "bar" exists in both present and absent labels preferences therefore validation should fail.
args: config.NodeLabelArgs{
PresentLabels: []string{"foo", "bar"},
AbsentLabels: []string{"baz"},
PresentLabelsPreference: []string{"foo", "bar"},
AbsentLabelsPreference: []string{"bar", "baz"},
},
err: true,
},
{
name: "both label presence and preference conflict",
args: config.NodeLabelArgs{
PresentLabels: []string{"foo", "bar"},
AbsentLabels: []string{"bar", "baz"},
PresentLabelsPreference: []string{"foo", "bar"},
AbsentLabelsPreference: []string{"bar", "baz"},
},
err: true,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
_, err := New(&test.args, nil)
if test.err && err == nil {
t.Fatal("Plugin initialization should fail.")
}
if !test.err && err != nil {
t.Fatalf("Plugin initialization shouldn't fail: %v", err)
}
})
}
}
func TestNodeLabelFilter(t *testing.T) {
label := map[string]string{"foo": "any value", "bar": "any value"}
var pod *v1.Pod
@@ -341,5 +280,4 @@ func TestNodeLabelScoreWithoutNode(t *testing.T) {
t.Errorf("Status mismatch. got: %v, want: %v", status.Code(), framework.Error)
}
})
}