@@ -25,6 +25,7 @@ import (
25
25
"k8s.io/apimachinery/pkg/types"
26
26
"k8s.io/apimachinery/pkg/util/uuid"
27
27
"k8s.io/kubernetes/test/e2e/framework"
28
+ "strconv"
28
29
29
30
"github.com/onsi/ginkgo"
30
31
)
@@ -99,4 +100,79 @@ var _ = ginkgo.Describe("[sig-node] PodTemplates", func() {
99
100
framework .ExpectNoError (err , "failed to list PodTemplate" )
100
101
framework .ExpectEqual (len (podTemplateList .Items ), 0 , "PodTemplate list returned items, failed to delete PodTemplate" )
101
102
})
103
+
104
+ ginkgo .It ("should delete a collection of pod templates" , func () {
105
+ podTemplateNames := []string {"test-podtemplate-1" , "test-podtemplate-2" , "test-podtemplate-3" }
106
+ podTemplateNamesCount := len (podTemplateNames )
107
+
108
+ ginkgo .By ("Create set of pod templates" )
109
+ // create a set of pod templates in test namespace
110
+ for _ , podTemplateName := range podTemplateNames {
111
+ _ , err := f .ClientSet .CoreV1 ().PodTemplates (f .Namespace .Name ).Create (context .TODO (), & v1.PodTemplate {
112
+ ObjectMeta : metav1.ObjectMeta {
113
+ Name : podTemplateName ,
114
+ Labels : map [string ]string {"podtemplate-set" : "true" },
115
+ },
116
+ Template : v1.PodTemplateSpec {
117
+ Spec : v1.PodSpec {
118
+ Containers : []v1.Container {
119
+ {Name : "nginx" , Image : "nginx" },
120
+ },
121
+ },
122
+ },
123
+ }, metav1.CreateOptions {})
124
+ framework .ExpectNoError (err , "failed to create pod template" )
125
+ framework .Logf ("created %v" , podTemplateName )
126
+ }
127
+
128
+ ginkgo .By ("get a list of pod templates with a label in the current namespace" )
129
+ // get a list of pod templates
130
+ podTemplateList , err := f .ClientSet .CoreV1 ().PodTemplates (f .Namespace .Name ).List (context .TODO (), metav1.ListOptions {
131
+ LabelSelector : "podtemplate-set=true" ,
132
+ })
133
+ framework .ExpectNoError (err , "failed to get a list of pod templates" )
134
+
135
+ // check that we find all the pod templates created
136
+ podTemplateListItemsCount := len (podTemplateList .Items )
137
+ errMsg := "found " + strconv .Itoa (podTemplateListItemsCount ) + " pod templates when " + strconv .Itoa (podTemplateNamesCount ) + " pod templates where expected"
138
+ logMsg := "found " + strconv .Itoa (podTemplateListItemsCount ) + " pod templates"
139
+
140
+ foundCreatedSet := true
141
+ if podTemplateListItemsCount != podTemplateNamesCount {
142
+ foundCreatedSet = false
143
+ } else {
144
+ framework .Logf (logMsg )
145
+ }
146
+ framework .ExpectEqual (foundCreatedSet , true , errMsg )
147
+
148
+ ginkgo .By ("delete collection of pod templates" )
149
+ // delete collection
150
+
151
+ framework .Logf ("requesting DeleteCollection of pod templates" )
152
+ err = f .ClientSet .CoreV1 ().PodTemplates (f .Namespace .Name ).DeleteCollection (context .TODO (), metav1.DeleteOptions {}, metav1.ListOptions {
153
+ LabelSelector : "podtemplate-set=true" })
154
+ framework .ExpectNoError (err , "failed to delete all pod templates" )
155
+
156
+ ginkgo .By ("get a list of pod templates with a label in the current namespace" )
157
+ // get list of pod templates
158
+ podTemplateList , err = f .ClientSet .CoreV1 ().PodTemplates (f .Namespace .Name ).List (context .TODO (), metav1.ListOptions {
159
+ LabelSelector : "podtemplate-set=true" ,
160
+ })
161
+ framework .ExpectNoError (err , "failed to get a list of pod templates" )
162
+
163
+ // check that we don't find any created pod templates
164
+ podTemplateListItemsCount = len (podTemplateList .Items )
165
+ errMsg = "found " + strconv .Itoa (podTemplateListItemsCount ) + " pod templates when zero pod templates where expected"
166
+ logMsg = "found " + strconv .Itoa (podTemplateListItemsCount ) + " pod templates"
167
+
168
+ foundCreatedSet = false
169
+ if podTemplateListItemsCount != 0 {
170
+ foundCreatedSet = true
171
+ } else {
172
+ framework .Logf (logMsg )
173
+ }
174
+ framework .ExpectEqual (foundCreatedSet , false , errMsg )
175
+
176
+ })
177
+
102
178
})
0 commit comments