@@ -24,11 +24,19 @@ import (
24
24
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25
25
"k8s.io/apimachinery/pkg/types"
26
26
"k8s.io/apimachinery/pkg/util/uuid"
27
+ "k8s.io/apimachinery/pkg/util/wait"
27
28
"k8s.io/kubernetes/test/e2e/framework"
29
+ imageutils "k8s.io/kubernetes/test/utils/image"
30
+ "time"
28
31
29
32
"github.com/onsi/ginkgo"
30
33
)
31
34
35
+ const (
36
+ podTemplateRetryPeriod = 1 * time .Second
37
+ podTemplateRetryTimeout = 1 * time .Minute
38
+ )
39
+
32
40
var _ = ginkgo .Describe ("[sig-node] PodTemplates" , func () {
33
41
f := framework .NewDefaultFramework ("podtemplate" )
34
42
/*
@@ -99,4 +107,71 @@ var _ = ginkgo.Describe("[sig-node] PodTemplates", func() {
99
107
framework .ExpectNoError (err , "failed to list PodTemplate" )
100
108
framework .ExpectEqual (len (podTemplateList .Items ), 0 , "PodTemplate list returned items, failed to delete PodTemplate" )
101
109
})
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
+
102
157
})
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