From 9951a9c98e28a3495a7243a60b11be36f19e3d5e Mon Sep 17 00:00:00 2001 From: Caleb Woodbine Date: Sun, 5 Jan 2020 22:18:38 +0000 Subject: [PATCH 1/6] 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") + }) + }) + From bd6550fb349df7679c7a6d025fefccfa1351acc6 Mon Sep 17 00:00:00 2001 From: Caleb Woodbine Date: Mon, 6 Jan 2020 22:18:29 +0000 Subject: [PATCH 2/6] Update: formatting, gomega Expect to framework ExpectEqual, framework creation to standard function --- test/e2e/apimachinery/namespace.go | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/test/e2e/apimachinery/namespace.go b/test/e2e/apimachinery/namespace.go index 02c10b76550..1dc52122a14 100644 --- a/test/e2e/apimachinery/namespace.go +++ b/test/e2e/apimachinery/namespace.go @@ -26,14 +26,13 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" + "k8s.io/apimachinery/pkg/util/uuid" "k8s.io/apimachinery/pkg/util/wait" "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" ) @@ -252,11 +251,8 @@ var _ = SIGDescribe("Namespaces [Serial]", func() { 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, - }, - }) + ns, err := f.CreateNamespace(namespaceName, nil) + namespaceName = ns.ObjectMeta.Name framework.ExpectNoError(err, "failed creating Namespace") ginkgo.By("patching the Namespace") @@ -267,12 +263,7 @@ var _ = SIGDescribe("Namespaces [Serial]", func() { 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") + framework.ExpectEqual(namespace.ObjectMeta.Labels["testLabel"], "testValue", "namespace not patched") }) }) - From 2754cc37ea569ce9478b9ffb1304cd9feeb1280e Mon Sep 17 00:00:00 2001 From: Caleb Woodbine Date: Mon, 6 Jan 2020 22:32:19 +0000 Subject: [PATCH 3/6] Update: namespaceName value updating order to prevent error expection --- test/e2e/apimachinery/namespace.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/apimachinery/namespace.go b/test/e2e/apimachinery/namespace.go index 1dc52122a14..597a6390ca4 100644 --- a/test/e2e/apimachinery/namespace.go +++ b/test/e2e/apimachinery/namespace.go @@ -252,8 +252,8 @@ var _ = SIGDescribe("Namespaces [Serial]", func() { ginkgo.By("creating a Namespace") namespaceName := "nspatchtest-" + string(uuid.NewUUID()) ns, err := f.CreateNamespace(namespaceName, nil) - namespaceName = ns.ObjectMeta.Name framework.ExpectNoError(err, "failed creating Namespace") + namespaceName = ns.ObjectMeta.Name ginkgo.By("patching the Namespace") nspatch := `{"metadata":{"labels":{"testLabel":"testValue"}}}` From 616003a8e960333b87eee11e8d0541424898a46f Mon Sep 17 00:00:00 2001 From: Caleb Woodbine Date: Tue, 7 Jan 2020 00:50:20 +0000 Subject: [PATCH 4/6] Add: OWNERS file - based off of staging/src/k8s.io/apimachinery/OWNERS --- test/e2e/apimachinery/OWNERS | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 test/e2e/apimachinery/OWNERS diff --git a/test/e2e/apimachinery/OWNERS b/test/e2e/apimachinery/OWNERS new file mode 100644 index 00000000000..aca480c9f5b --- /dev/null +++ b/test/e2e/apimachinery/OWNERS @@ -0,0 +1,27 @@ +# See the OWNERS docs at https://go.k8s.io/owners + +approvers: +- lavalamp +- smarterclayton +- deads2k +- sttts +- liggitt +- caesarxuchao +reviewers: +- thockin +- lavalamp +- smarterclayton +- wojtek-t +- deads2k +- derekwaynecarr +- caesarxuchao +- cheftako +- mikedanese +- liggitt +- gmarek +- sttts +- ncdc +- logicalhan +- tallclair +labels: +- sig/api-machinery \ No newline at end of file From 232da6043000410ce7e53e4f8f00a6169bae47fc Mon Sep 17 00:00:00 2001 From: Caleb Woodbine Date: Tue, 7 Jan 2020 20:50:16 +0000 Subject: [PATCH 5/6] Update: json patch generation --- test/e2e/apimachinery/namespace.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/e2e/apimachinery/namespace.go b/test/e2e/apimachinery/namespace.go index 597a6390ca4..3d5d4001627 100644 --- a/test/e2e/apimachinery/namespace.go +++ b/test/e2e/apimachinery/namespace.go @@ -21,6 +21,7 @@ import ( "strings" "sync" "time" + "encoding/json" "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -256,7 +257,11 @@ var _ = SIGDescribe("Namespaces [Serial]", func() { namespaceName = ns.ObjectMeta.Name ginkgo.By("patching the Namespace") - nspatch := `{"metadata":{"labels":{"testLabel":"testValue"}}}` + nspatch, err := json.Marshal(map[string]interface{}{ + "metadata": map[string]interface{}{ + "labels": map[string]string{"testLabel":"testValue"}, + }, + }) _, err = f.ClientSet.CoreV1().Namespaces().Patch(namespaceName, types.StrategicMergePatchType, []byte(nspatch)) framework.ExpectNoError(err, "failed to patch Namespace") From 9ed55bc52031ef5e386c82757138ae171746c999 Mon Sep 17 00:00:00 2001 From: Caleb Woodbine Date: Tue, 7 Jan 2020 22:02:41 +0000 Subject: [PATCH 6/6] Add: JSON marshal error failure checking; Fix: formatting --- test/e2e/apimachinery/namespace.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/e2e/apimachinery/namespace.go b/test/e2e/apimachinery/namespace.go index 3d5d4001627..ba66c385c0f 100644 --- a/test/e2e/apimachinery/namespace.go +++ b/test/e2e/apimachinery/namespace.go @@ -17,11 +17,11 @@ limitations under the License. package apimachinery import ( + "encoding/json" "fmt" "strings" "sync" "time" - "encoding/json" "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -259,9 +259,10 @@ var _ = SIGDescribe("Namespaces [Serial]", func() { ginkgo.By("patching the Namespace") nspatch, err := json.Marshal(map[string]interface{}{ "metadata": map[string]interface{}{ - "labels": map[string]string{"testLabel":"testValue"}, + "labels": map[string]string{"testLabel": "testValue"}, }, }) + framework.ExpectNoError(err, "failed to marshal JSON patch data") _, err = f.ClientSet.CoreV1().Namespaces().Patch(namespaceName, types.StrategicMergePatchType, []byte(nspatch)) framework.ExpectNoError(err, "failed to patch Namespace")