From d8afb6f679b2fda760a51be668ece6533c8c097b Mon Sep 17 00:00:00 2001 From: Avesh Agarwal Date: Tue, 31 Oct 2017 15:44:27 -0400 Subject: [PATCH] UPSTREAM: 54812: Updated and added new unit tests. --- .../admission_test.go | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/vendor/k8s.io/kubernetes/plugin/pkg/admission/podtolerationrestriction/admission_test.go b/vendor/k8s.io/kubernetes/plugin/pkg/admission/podtolerationrestriction/admission_test.go index 53717f613485..2500b5a96c50 100644 --- a/vendor/k8s.io/kubernetes/plugin/pkg/admission/podtolerationrestriction/admission_test.go +++ b/vendor/k8s.io/kubernetes/plugin/pkg/admission/podtolerationrestriction/admission_test.go @@ -66,11 +66,11 @@ func TestPodAdmission(t *testing.T) { }{ { defaultClusterTolerations: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue", Effect: "NoSchedule", TolerationSeconds: nil}}, - namespaceTolerations: []api.Toleration{}, + namespaceTolerations: nil, podTolerations: []api.Toleration{}, mergedTolerations: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue", Effect: "NoSchedule", TolerationSeconds: nil}}, admit: true, - testName: "default cluster tolerations with empty pod tolerations", + testName: "default cluster tolerations with empty pod tolerations and nil namespace tolerations", }, { defaultClusterTolerations: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue", Effect: "NoSchedule", TolerationSeconds: nil}}, @@ -107,8 +107,9 @@ func TestPodAdmission(t *testing.T) { defaultClusterTolerations: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue2", Effect: "NoSchedule", TolerationSeconds: nil}}, namespaceTolerations: []api.Toleration{}, podTolerations: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue1", Effect: "NoSchedule", TolerationSeconds: nil}}, - admit: false, - testName: "conflicting pod and default cluster tolerations", + mergedTolerations: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue1", Effect: "NoSchedule", TolerationSeconds: nil}}, + admit: true, + testName: "conflicting pod and default cluster tolerations but overridden by empty namespace tolerations", }, { defaultClusterTolerations: []api.Toleration{}, @@ -119,6 +120,22 @@ func TestPodAdmission(t *testing.T) { admit: true, testName: "merged pod tolerations satisfy whitelist", }, + { + defaultClusterTolerations: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue", Effect: "NoSchedule", TolerationSeconds: nil}}, + namespaceTolerations: []api.Toleration{}, + podTolerations: []api.Toleration{}, + mergedTolerations: []api.Toleration{}, + admit: true, + testName: "Override default cluster toleration by empty namespace level toleration", + }, + { + whitelist: []api.Toleration{}, + clusterWhitelist: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue1", Effect: "NoSchedule", TolerationSeconds: nil}}, + podTolerations: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue", Effect: "NoSchedule", TolerationSeconds: nil}}, + mergedTolerations: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue", Effect: "NoSchedule", TolerationSeconds: nil}}, + admit: true, + testName: "pod toleration conflicts with default cluster white list which is overridden by empty namespace whitelist", + }, { defaultClusterTolerations: []api.Toleration{}, namespaceTolerations: []api.Toleration{{Key: "testKey", Operator: "Equal", Value: "testValue", Effect: "NoSchedule", TolerationSeconds: nil}}, @@ -129,7 +146,7 @@ func TestPodAdmission(t *testing.T) { }, } for _, test := range tests { - if len(test.namespaceTolerations) > 0 { + if test.namespaceTolerations != nil { tolerationStr, err := json.Marshal(test.namespaceTolerations) if err != nil { t.Errorf("error in marshalling namespace tolerations %v", test.namespaceTolerations) @@ -137,7 +154,7 @@ func TestPodAdmission(t *testing.T) { namespace.Annotations = map[string]string{NSDefaultTolerations: string(tolerationStr)} } - if len(test.whitelist) > 0 { + if test.whitelist != nil { tolerationStr, err := json.Marshal(test.whitelist) if err != nil { t.Errorf("error in marshalling namespace whitelist %v", test.whitelist)