From 5a008786e213066a1712b5c2cc7a8aa243799d67 Mon Sep 17 00:00:00 2001 From: Caleb Woodbine Date: Wed, 15 Jan 2020 00:09:02 +0000 Subject: [PATCH 1/4] Add: PodTemplate lifecycle test --- test/e2e/common/podtemplates.go | 95 +++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 test/e2e/common/podtemplates.go diff --git a/test/e2e/common/podtemplates.go b/test/e2e/common/podtemplates.go new file mode 100644 index 00000000000..2594238e977 --- /dev/null +++ b/test/e2e/common/podtemplates.go @@ -0,0 +1,95 @@ +/* +Copyright 2020 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package common + +import ( + "encoding/json" + //"fmt" + + v1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/uuid" + "k8s.io/kubernetes/test/e2e/framework" + "k8s.io/apimachinery/pkg/types" + + "github.com/onsi/ginkgo" +) + +var _ = ginkgo.Describe("[sig-architecture] PodTemplates", func() { + f := framework.NewDefaultFramework("podtemplate") + + ginkgo.It("should run the lifecycle of PodTemplates", func() { + testNamespaceName := f.Namespace.Name + podTemplateName := "nginx-pod-template-" + string(uuid.NewUUID()) + + // get a list of PodTemplates (in all namespaces to hit endpoint) + podTemplateList, err := f.ClientSet.CoreV1().PodTemplates("").List(metav1.ListOptions{}) + framework.ExpectNoError(err, "failed to list all PodTemplates") + framework.ExpectEqual(len(podTemplateList.Items) == 0, true, "unable to find templates") + + // create a PodTemplate + _, err = f.ClientSet.CoreV1().PodTemplates(testNamespaceName).Create(&v1.PodTemplate{ + ObjectMeta: metav1.ObjectMeta{ + Name: podTemplateName, + Labels: map[string]string{ + "podtemplate-static": "true", + }, + }, + Template: v1.PodTemplateSpec{ + Spec: v1.PodSpec{ + Containers: []v1.Container{ + {Name: "nginx", Image: "nginx"}, + }, + }, + }, + }) + framework.ExpectNoError(err, "failed to create PodTemplate") + + // get template + podTemplateRead, err := f.ClientSet.CoreV1().PodTemplates(testNamespaceName).Get(podTemplateName, metav1.GetOptions{}) + framework.ExpectNoError(err, "failed to get created PodTemplate") + framework.ExpectEqual(podTemplateRead.ObjectMeta.Name, podTemplateName) + + // patch template + podTemplatePatch, err := json.Marshal(map[string]interface{}{ + "metadata": map[string]interface{}{ + "labels": map[string]string{ + "podtemplate": "patched", + }, + }, + }) + framework.ExpectNoError(err, "failed to marshal patch data") + _, err = f.ClientSet.CoreV1().PodTemplates(testNamespaceName).Patch(podTemplateName, types.StrategicMergePatchType, []byte(podTemplatePatch)) + framework.ExpectNoError(err, "failed to patch PodTemplate") + + // get template (ensure label is there) + podTemplateRead, err = f.ClientSet.CoreV1().PodTemplates(testNamespaceName).Get(podTemplateName, metav1.GetOptions{}) + framework.ExpectNoError(err, "failed to get PodTemplate") + framework.ExpectEqual(podTemplateRead.ObjectMeta.Labels["podtemplate"], "patched", "failed to patch template, new label not found") + + // delete the PodTemplate + err = f.ClientSet.CoreV1().PodTemplates(testNamespaceName).Delete(podTemplateName, &metav1.DeleteOptions{}) + framework.ExpectNoError(err, "failed to delete PodTemplate") + + // list the PodTemplates + podTemplateListWithLabel, err := f.ClientSet.CoreV1().PodTemplates("").List(metav1.ListOptions{ + LabelSelector: "podtemplate-static=true", + }) + framework.ExpectNoError(err, "failed to list PodTemplate") + framework.ExpectEqual(len(podTemplateListWithLabel.Items) == 0, true, "PodTemplate list returned items, failed to delete PodTemplate") + }) +}) From b50531a4a462746708ed7af1607c21ab9ad182cc Mon Sep 17 00:00:00 2001 From: Caleb Woodbine Date: Wed, 15 Jan 2020 19:49:03 +0000 Subject: [PATCH 2/4] Update: formatting, cleanup, ExpectEqual statements --- test/e2e/common/podtemplates.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/e2e/common/podtemplates.go b/test/e2e/common/podtemplates.go index 2594238e977..755eda32332 100644 --- a/test/e2e/common/podtemplates.go +++ b/test/e2e/common/podtemplates.go @@ -18,13 +18,12 @@ package common import ( "encoding/json" - //"fmt" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/uuid" "k8s.io/kubernetes/test/e2e/framework" - "k8s.io/apimachinery/pkg/types" "github.com/onsi/ginkgo" ) @@ -39,7 +38,7 @@ var _ = ginkgo.Describe("[sig-architecture] PodTemplates", func() { // get a list of PodTemplates (in all namespaces to hit endpoint) podTemplateList, err := f.ClientSet.CoreV1().PodTemplates("").List(metav1.ListOptions{}) framework.ExpectNoError(err, "failed to list all PodTemplates") - framework.ExpectEqual(len(podTemplateList.Items) == 0, true, "unable to find templates") + framework.ExpectEqual(len(podTemplateList.Items), 0, "unable to find templates") // create a PodTemplate _, err = f.ClientSet.CoreV1().PodTemplates(testNamespaceName).Create(&v1.PodTemplate{ @@ -90,6 +89,6 @@ var _ = ginkgo.Describe("[sig-architecture] PodTemplates", func() { LabelSelector: "podtemplate-static=true", }) framework.ExpectNoError(err, "failed to list PodTemplate") - framework.ExpectEqual(len(podTemplateListWithLabel.Items) == 0, true, "PodTemplate list returned items, failed to delete PodTemplate") + framework.ExpectEqual(len(podTemplateListWithLabel.Items), 0, "PodTemplate list returned items, failed to delete PodTemplate") }) }) From fe91d5fad981ed87858a89bba8f20a2c7f190211 Mon Sep 17 00:00:00 2001 From: Caleb Woodbine Date: Wed, 15 Jan 2020 21:18:22 +0000 Subject: [PATCH 3/4] Fix: bazel build errors --- test/e2e/common/BUILD | 1 + 1 file changed, 1 insertion(+) diff --git a/test/e2e/common/BUILD b/test/e2e/common/BUILD index d230eb26c59..a32cb5643b8 100644 --- a/test/e2e/common/BUILD +++ b/test/e2e/common/BUILD @@ -26,6 +26,7 @@ go_library( "networking.go", "node_lease.go", "pods.go", + "podtemplates.go", "privileged.go", "projected_combined.go", "projected_configmap.go", From 3ba8f42f96b071d486a70497e037f72344a4a9e1 Mon Sep 17 00:00:00 2001 From: Caleb Woodbine Date: Thu, 16 Jan 2020 00:52:57 +0000 Subject: [PATCH 4/4] Update: podTemplateList name; Fix: initial fetching of PodTemplates --- test/e2e/common/podtemplates.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/e2e/common/podtemplates.go b/test/e2e/common/podtemplates.go index 755eda32332..7a347cc5d4f 100644 --- a/test/e2e/common/podtemplates.go +++ b/test/e2e/common/podtemplates.go @@ -36,7 +36,9 @@ var _ = ginkgo.Describe("[sig-architecture] PodTemplates", func() { podTemplateName := "nginx-pod-template-" + string(uuid.NewUUID()) // get a list of PodTemplates (in all namespaces to hit endpoint) - podTemplateList, err := f.ClientSet.CoreV1().PodTemplates("").List(metav1.ListOptions{}) + podTemplateList, err := f.ClientSet.CoreV1().PodTemplates("").List(metav1.ListOptions{ + LabelSelector: "podtemplate-static=true", + }) framework.ExpectNoError(err, "failed to list all PodTemplates") framework.ExpectEqual(len(podTemplateList.Items), 0, "unable to find templates") @@ -85,10 +87,10 @@ var _ = ginkgo.Describe("[sig-architecture] PodTemplates", func() { framework.ExpectNoError(err, "failed to delete PodTemplate") // list the PodTemplates - podTemplateListWithLabel, err := f.ClientSet.CoreV1().PodTemplates("").List(metav1.ListOptions{ + podTemplateList, err = f.ClientSet.CoreV1().PodTemplates("").List(metav1.ListOptions{ LabelSelector: "podtemplate-static=true", }) framework.ExpectNoError(err, "failed to list PodTemplate") - framework.ExpectEqual(len(podTemplateListWithLabel.Items), 0, "PodTemplate list returned items, failed to delete PodTemplate") + framework.ExpectEqual(len(podTemplateList.Items), 0, "PodTemplate list returned items, failed to delete PodTemplate") }) })