Skip to content

Commit f455a14

Browse files
authored
Merge pull request kubernetes#91259 from ii/heyste-create-delete-core-v1-collection-namespaced-pod-template-test
Create deleteCoreV1CollectionNamespacedPodTemplate test+promote - +1 endpoint coverage
2 parents 13f1d95 + aaa0734 commit f455a14

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

test/e2e/common/podtemplates.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,19 @@ import (
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2525
"k8s.io/apimachinery/pkg/types"
2626
"k8s.io/apimachinery/pkg/util/uuid"
27+
"k8s.io/apimachinery/pkg/util/wait"
2728
"k8s.io/kubernetes/test/e2e/framework"
29+
imageutils "k8s.io/kubernetes/test/utils/image"
30+
"time"
2831

2932
"github.com/onsi/ginkgo"
3033
)
3134

35+
const (
36+
podTemplateRetryPeriod = 1 * time.Second
37+
podTemplateRetryTimeout = 1 * time.Minute
38+
)
39+
3240
var _ = ginkgo.Describe("[sig-node] PodTemplates", func() {
3341
f := framework.NewDefaultFramework("podtemplate")
3442
/*
@@ -99,4 +107,71 @@ var _ = ginkgo.Describe("[sig-node] PodTemplates", func() {
99107
framework.ExpectNoError(err, "failed to list PodTemplate")
100108
framework.ExpectEqual(len(podTemplateList.Items), 0, "PodTemplate list returned items, failed to delete PodTemplate")
101109
})
110+
111+
ginkgo.It("should delete a collection of pod templates", func() {
112+
podTemplateNames := []string{"test-podtemplate-1", "test-podtemplate-2", "test-podtemplate-3"}
113+
114+
ginkgo.By("Create set of pod templates")
115+
// create a set of pod templates in test namespace
116+
for _, podTemplateName := range podTemplateNames {
117+
_, err := f.ClientSet.CoreV1().PodTemplates(f.Namespace.Name).Create(context.TODO(), &v1.PodTemplate{
118+
ObjectMeta: metav1.ObjectMeta{
119+
Name: podTemplateName,
120+
Labels: map[string]string{"podtemplate-set": "true"},
121+
},
122+
Template: v1.PodTemplateSpec{
123+
Spec: v1.PodSpec{
124+
Containers: []v1.Container{
125+
{Name: "token-test", Image: imageutils.GetE2EImage(imageutils.Agnhost)},
126+
},
127+
},
128+
},
129+
}, metav1.CreateOptions{})
130+
framework.ExpectNoError(err, "failed to create pod template")
131+
framework.Logf("created %v", podTemplateName)
132+
}
133+
134+
ginkgo.By("get a list of pod templates with a label in the current namespace")
135+
// get a list of pod templates
136+
podTemplateList, err := f.ClientSet.CoreV1().PodTemplates(f.Namespace.Name).List(context.TODO(), metav1.ListOptions{
137+
LabelSelector: "podtemplate-set=true",
138+
})
139+
framework.ExpectNoError(err, "failed to get a list of pod templates")
140+
141+
framework.ExpectEqual(len(podTemplateList.Items), len(podTemplateNames), "looking for expected number of pod templates")
142+
143+
ginkgo.By("delete collection of pod templates")
144+
// delete collection
145+
146+
framework.Logf("requesting DeleteCollection of pod templates")
147+
err = f.ClientSet.CoreV1().PodTemplates(f.Namespace.Name).DeleteCollection(context.TODO(), metav1.DeleteOptions{}, metav1.ListOptions{
148+
LabelSelector: "podtemplate-set=true"})
149+
framework.ExpectNoError(err, "failed to delete all pod templates")
150+
151+
ginkgo.By("check that the list of pod templates matches the requested quantity")
152+
153+
err = wait.PollImmediate(podTemplateRetryPeriod, podTemplateRetryTimeout, checkPodTemplateListQuantity(f, "podtemplate-set=true", 0))
154+
framework.ExpectNoError(err, "failed to count required pod templates")
155+
})
156+
102157
})
158+
159+
func checkPodTemplateListQuantity(f *framework.Framework, label string, quantity int) func() (bool, error) {
160+
return func() (bool, error) {
161+
var err error
162+
163+
framework.Logf("requesting list of pod templates to confirm quantity")
164+
165+
list, err := f.ClientSet.CoreV1().PodTemplates(f.Namespace.Name).List(context.TODO(), metav1.ListOptions{
166+
LabelSelector: label})
167+
168+
if err != nil {
169+
return false, err
170+
}
171+
172+
if len(list.Items) != quantity {
173+
return false, err
174+
}
175+
return true, nil
176+
}
177+
}

0 commit comments

Comments
 (0)