From 9951a9c98e28a3495a7243a60b11be36f19e3d5e Mon Sep 17 00:00:00 2001 From: Caleb Woodbine Date: Sun, 5 Jan 2020 22:18:38 +0000 Subject: [PATCH] Add: namespace patch test --- test/e2e/apimachinery/namespace.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/e2e/apimachinery/namespace.go b/test/e2e/apimachinery/namespace.go index f77c2f1f47f..02c10b76550 100644 --- a/test/e2e/apimachinery/namespace.go +++ b/test/e2e/apimachinery/namespace.go @@ -30,8 +30,11 @@ import ( "k8s.io/kubernetes/test/e2e/framework" e2epod "k8s.io/kubernetes/test/e2e/framework/pod" imageutils "k8s.io/kubernetes/test/utils/image" + "k8s.io/apimachinery/pkg/util/uuid" "github.com/onsi/ginkgo" + "github.com/onsi/gomega" + "k8s.io/apimachinery/pkg/types" ) func extinguish(f *framework.Framework, totalNS int, maxAllowedAfterDel int, maxSeconds int) { @@ -246,4 +249,30 @@ var _ = SIGDescribe("Namespaces [Serial]", func() { ginkgo.It("should always delete fast (ALL of 100 namespaces in 150 seconds) [Feature:ComprehensiveNamespaceDraining]", func() { extinguish(f, 100, 0, 150) }) + ginkgo.It("should patch a Namespace", func() { + ginkgo.By("creating a Namespace") + namespaceName := "nspatchtest-" + string(uuid.NewUUID()) + _, err := f.ClientSet.CoreV1().Namespaces().Create(&v1.Namespace{ + ObjectMeta: metav1.ObjectMeta{ + Name: namespaceName, + }, + }) + framework.ExpectNoError(err, "failed creating Namespace") + + ginkgo.By("patching the Namespace") + nspatch := `{"metadata":{"labels":{"testLabel":"testValue"}}}` + _, err = f.ClientSet.CoreV1().Namespaces().Patch(namespaceName, types.StrategicMergePatchType, []byte(nspatch)) + framework.ExpectNoError(err, "failed to patch Namespace") + + ginkgo.By("get the Namespace and ensuring it has the label") + namespace, err := f.ClientSet.CoreV1().Namespaces().Get(namespaceName, metav1.GetOptions{}) + framework.ExpectNoError(err, "failed to get Namespace") + gomega.Expect(namespace.ObjectMeta.Labels["testLabel"]).To(gomega.Equal("testValue"), "namespace not patched") + + ginkgo.By("deleting the Namespace") + err = f.ClientSet.CoreV1().Namespaces().Delete(namespaceName, &metav1.DeleteOptions{}) + framework.ExpectNoError(err, "failed to delete the test Namespace") + }) + }) +