@@ -20,16 +20,11 @@ import (
20
20
"context"
21
21
"encoding/json"
22
22
"fmt"
23
- "time"
24
23
25
24
v1 "k8s.io/api/core/v1"
26
25
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27
- "k8s.io/apimachinery/pkg/runtime/schema"
28
26
"k8s.io/apimachinery/pkg/types"
29
27
"k8s.io/apimachinery/pkg/util/uuid"
30
- watch "k8s.io/apimachinery/pkg/watch"
31
- "k8s.io/client-go/dynamic"
32
- watchtools "k8s.io/client-go/tools/watch"
33
28
"k8s.io/kubernetes/test/e2e/framework"
34
29
imageutils "k8s.io/kubernetes/test/utils/image"
35
30
@@ -39,12 +34,6 @@ import (
39
34
var _ = ginkgo .Describe ("[sig-node] ConfigMap" , func () {
40
35
f := framework .NewDefaultFramework ("configmap" )
41
36
42
- var dc dynamic.Interface
43
-
44
- ginkgo .BeforeEach (func () {
45
- dc = f .DynamicClient
46
- })
47
-
48
37
/*
49
38
Release : v1.9
50
39
Testname: ConfigMap, from environment field
@@ -172,12 +161,6 @@ var _ = ginkgo.Describe("[sig-node] ConfigMap", func() {
172
161
testNamespaceName := f .Namespace .Name
173
162
testConfigMapName := "test-configmap" + string (uuid .NewUUID ())
174
163
175
- configMapResource := schema.GroupVersionResource {Group : "" , Version : "v1" , Resource : "configmaps" }
176
- expectedWatchEvents := []watch.Event {
177
- {Type : watch .Added },
178
- {Type : watch .Modified },
179
- {Type : watch .Deleted },
180
- }
181
164
testConfigMap := v1.ConfigMap {
182
165
ObjectMeta : metav1.ObjectMeta {
183
166
Name : testConfigMapName ,
@@ -190,103 +173,62 @@ var _ = ginkgo.Describe("[sig-node] ConfigMap", func() {
190
173
},
191
174
}
192
175
193
- framework .WatchEventSequenceVerifier (context .TODO (), dc , configMapResource , testNamespaceName , testConfigMapName , metav1.ListOptions {LabelSelector : "test-configmap-static=true" }, expectedWatchEvents , func (retryWatcher * watchtools.RetryWatcher ) (actualWatchEvents []watch.Event ) {
194
- ginkgo .By ("creating a ConfigMap" )
195
- _ , err := f .ClientSet .CoreV1 ().ConfigMaps (testNamespaceName ).Create (context .TODO (), & testConfigMap , metav1.CreateOptions {})
196
- framework .ExpectNoError (err , "failed to create ConfigMap" )
197
- eventFound := false
198
- ctx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
199
- defer cancel ()
200
- _ , err = framework .WatchUntilWithoutRetry (ctx , retryWatcher , func (watchEvent watch.Event ) (bool , error ) {
201
- if watchEvent .Type != watch .Added {
202
- return false , nil
203
- }
204
- actualWatchEvents = append (actualWatchEvents , watchEvent )
205
- eventFound = true
206
- return true , nil
207
- })
208
- framework .ExpectNoError (err , "Wait until condition with watch events should not return an error" )
209
- framework .ExpectEqual (eventFound , true , "failed to find ConfigMap %v event" , watch .Added )
176
+ ginkgo .By ("creating a ConfigMap" )
177
+ _ , err := f .ClientSet .CoreV1 ().ConfigMaps (testNamespaceName ).Create (context .TODO (), & testConfigMap , metav1.CreateOptions {})
178
+ framework .ExpectNoError (err , "failed to create ConfigMap" )
210
179
211
- configMapPatchPayload , err := json .Marshal (v1.ConfigMap {
212
- ObjectMeta : metav1.ObjectMeta {
213
- Labels : map [string ]string {
214
- "test-configmap" : "patched" ,
215
- },
216
- },
217
- Data : map [string ]string {
218
- "valueName" : "value1" ,
219
- },
220
- })
221
- framework .ExpectNoError (err , "failed to marshal patch data" )
180
+ ginkgo .By ("fetching the ConfigMap" )
181
+ configMap , err := f .ClientSet .CoreV1 ().ConfigMaps (testNamespaceName ).Get (context .TODO (), testConfigMapName , metav1.GetOptions {})
182
+ framework .ExpectNoError (err , "failed to get ConfigMap" )
183
+ framework .ExpectEqual (configMap .Data ["valueName" ], testConfigMap .Data ["valueName" ])
184
+ framework .ExpectEqual (configMap .Labels ["test-configmap-static" ], testConfigMap .Labels ["test-configmap-static" ])
222
185
223
- ginkgo .By ("patching the ConfigMap" )
224
- _ , err = f .ClientSet .CoreV1 ().ConfigMaps (testNamespaceName ).Patch (context .TODO (), testConfigMapName , types .StrategicMergePatchType , []byte (configMapPatchPayload ), metav1.PatchOptions {})
225
- framework .ExpectNoError (err , "failed to patch ConfigMap" )
226
- ginkgo .By ("waiting for the ConfigMap to be modified" )
227
- eventFound = false
228
- ctx , cancel = context .WithTimeout (context .Background (), 30 * time .Second )
229
- defer cancel ()
230
- _ , err = framework .WatchUntilWithoutRetry (ctx , retryWatcher , func (watchEvent watch.Event ) (bool , error ) {
231
- if watchEvent .Type != watch .Modified {
232
- return false , nil
233
- }
234
- actualWatchEvents = append (actualWatchEvents , watchEvent )
235
- eventFound = true
236
- return true , nil
237
- })
238
- framework .ExpectNoError (err , "Wait until condition with watch events should not return an error" )
239
- framework .ExpectEqual (eventFound , true , "failed to find ConfigMap %v event" , watch .Modified )
186
+ configMapPatchPayload , err := json .Marshal (v1.ConfigMap {
187
+ ObjectMeta : metav1.ObjectMeta {
188
+ Labels : map [string ]string {
189
+ "test-configmap" : "patched" ,
190
+ },
191
+ },
192
+ Data : map [string ]string {
193
+ "valueName" : "value1" ,
194
+ },
195
+ })
196
+ framework .ExpectNoError (err , "failed to marshal patch data" )
240
197
241
- ginkgo .By ("fetching the ConfigMap" )
242
- configMap , err := f .ClientSet .CoreV1 ().ConfigMaps (testNamespaceName ).Get (context .TODO (), testConfigMapName , metav1.GetOptions {})
243
- framework .ExpectNoError (err , "failed to get ConfigMap" )
244
- framework .ExpectEqual (configMap .Data ["valueName" ], "value1" , "failed to patch ConfigMap" )
245
- framework .ExpectEqual (configMap .Labels ["test-configmap" ], "patched" , "failed to patch ConfigMap" )
198
+ ginkgo .By ("patching the ConfigMap" )
199
+ _ , err = f .ClientSet .CoreV1 ().ConfigMaps (testNamespaceName ).Patch (context .TODO (), testConfigMapName , types .StrategicMergePatchType , []byte (configMapPatchPayload ), metav1.PatchOptions {})
200
+ framework .ExpectNoError (err , "failed to patch ConfigMap" )
246
201
247
- ginkgo .By ("listing all ConfigMaps in all namespaces" )
248
- configMapList , err := f .ClientSet .CoreV1 ().ConfigMaps ("" ).List (context .TODO (), metav1.ListOptions {
249
- LabelSelector : "test-configmap-static=true" ,
250
- })
251
- framework .ExpectNoError (err , "failed to list ConfigMaps with LabelSelector" )
252
- framework .ExpectNotEqual (len (configMapList .Items ), 0 , "no ConfigMaps found in ConfigMap list" )
253
- testConfigMapFound := false
254
- for _ , cm := range configMapList .Items {
255
- if cm .ObjectMeta .Name == testConfigMapName &&
256
- cm .ObjectMeta .Namespace == testNamespaceName &&
257
- cm .ObjectMeta .Labels ["test-configmap-static" ] == "true" &&
258
- cm .Data ["valueName" ] == "value1" {
259
- testConfigMapFound = true
260
- break
261
- }
202
+ ginkgo .By ("listing all ConfigMaps in all namespaces with a label selector" )
203
+ configMapList , err := f .ClientSet .CoreV1 ().ConfigMaps ("" ).List (context .TODO (), metav1.ListOptions {
204
+ LabelSelector : "test-configmap=patched" ,
205
+ })
206
+ framework .ExpectNoError (err , "failed to list ConfigMaps with LabelSelector" )
207
+ testConfigMapFound := false
208
+ for _ , cm := range configMapList .Items {
209
+ if cm .ObjectMeta .Name == testConfigMap .ObjectMeta .Name &&
210
+ cm .ObjectMeta .Namespace == testNamespaceName &&
211
+ cm .ObjectMeta .Labels ["test-configmap-static" ] == testConfigMap .ObjectMeta .Labels ["test-configmap-static" ] &&
212
+ cm .ObjectMeta .Labels ["test-configmap" ] == "patched" &&
213
+ cm .Data ["valueName" ] == "value1" {
214
+ testConfigMapFound = true
215
+ break
262
216
}
263
- framework .ExpectEqual (testConfigMapFound , true , "failed to find ConfigMap in list" )
217
+ }
218
+ framework .ExpectEqual (testConfigMapFound , true , "failed to find ConfigMap by label selector" )
264
219
265
- ginkgo .By ("deleting the ConfigMap by a collection" )
266
- err = f .ClientSet .CoreV1 ().ConfigMaps (testNamespaceName ).DeleteCollection (context .TODO (), metav1.DeleteOptions {}, metav1.ListOptions {
267
- LabelSelector : "test-configmap-static=true" ,
268
- })
269
- framework .ExpectNoError (err , "failed to delete ConfigMap collection with LabelSelector" )
270
- ginkgo .By ("waiting for the ConfigMap to be deleted" )
271
- eventFound = false
272
- ctx , cancel = context .WithTimeout (context .Background (), 30 * time .Second )
273
- defer cancel ()
274
- _ , err = framework .WatchUntilWithoutRetry (ctx , retryWatcher , func (watchEvent watch.Event ) (bool , error ) {
275
- if watchEvent .Type != watch .Deleted {
276
- return false , nil
277
- }
278
- actualWatchEvents = append (actualWatchEvents , watchEvent )
279
- eventFound = true
280
- return true , nil
281
- })
282
- framework .ExpectNoError (err , "Wait until condition with watch events should not return an error" )
283
- framework .ExpectEqual (eventFound , true , "failed to find ConfigMap %v event" , watch .Deleted )
220
+ ginkgo .By ("deleting the ConfigMap by collection with a label selector" )
221
+ err = f .ClientSet .CoreV1 ().ConfigMaps (testNamespaceName ).DeleteCollection (context .TODO (), metav1.DeleteOptions {}, metav1.ListOptions {
222
+ LabelSelector : "test-configmap-static=true" ,
223
+ })
224
+ framework .ExpectNoError (err , "failed to delete ConfigMap collection with LabelSelector" )
284
225
285
- return actualWatchEvents
286
- }, func () (err error ) {
287
- _ = f .ClientSet .CoreV1 ().ConfigMaps (testNamespaceName ).DeleteCollection (context .TODO (), metav1.DeleteOptions {}, metav1.ListOptions {LabelSelector : "test-configmap-static=true" })
288
- return err
226
+ ginkgo .By ("listing all ConfigMaps in test namespace" )
227
+ configMapList , err = f .ClientSet .CoreV1 ().ConfigMaps (testNamespaceName ).List (context .TODO (), metav1.ListOptions {
228
+ LabelSelector : "test-configmap-static=true" ,
289
229
})
230
+ framework .ExpectNoError (err , "failed to list ConfigMap by LabelSelector" )
231
+ framework .ExpectEqual (len (configMapList .Items ), 0 , "ConfigMap is still present after being deleted by collection" )
290
232
})
291
233
})
292
234
0 commit comments