Skip to content

Commit 1f89f42

Browse files
authored
Merge pull request kubernetes#92621 from spiffxp/simplify-configmap-lifecycle-test
Simplify ConfigMap lifecycle e2e test
2 parents 9a343ed + 225e7c7 commit 1f89f42

File tree

2 files changed

+48
-108
lines changed

2 files changed

+48
-108
lines changed

test/e2e/common/BUILD

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ go_library(
5858
"//staging/src/k8s.io/apimachinery/pkg/fields:go_default_library",
5959
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
6060
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
61-
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
6261
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
6362
"//staging/src/k8s.io/apimachinery/pkg/util/diff:go_default_library",
6463
"//staging/src/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
@@ -67,7 +66,6 @@ go_library(
6766
"//staging/src/k8s.io/apimachinery/pkg/util/uuid:go_default_library",
6867
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
6968
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
70-
"//staging/src/k8s.io/client-go/dynamic:go_default_library",
7169
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
7270
"//staging/src/k8s.io/client-go/tools/cache:go_default_library",
7371
"//staging/src/k8s.io/client-go/tools/watch:go_default_library",

test/e2e/common/configmap.go

Lines changed: 48 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,11 @@ import (
2020
"context"
2121
"encoding/json"
2222
"fmt"
23-
"time"
2423

2524
v1 "k8s.io/api/core/v1"
2625
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27-
"k8s.io/apimachinery/pkg/runtime/schema"
2826
"k8s.io/apimachinery/pkg/types"
2927
"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"
3328
"k8s.io/kubernetes/test/e2e/framework"
3429
imageutils "k8s.io/kubernetes/test/utils/image"
3530

@@ -39,12 +34,6 @@ import (
3934
var _ = ginkgo.Describe("[sig-node] ConfigMap", func() {
4035
f := framework.NewDefaultFramework("configmap")
4136

42-
var dc dynamic.Interface
43-
44-
ginkgo.BeforeEach(func() {
45-
dc = f.DynamicClient
46-
})
47-
4837
/*
4938
Release : v1.9
5039
Testname: ConfigMap, from environment field
@@ -172,12 +161,6 @@ var _ = ginkgo.Describe("[sig-node] ConfigMap", func() {
172161
testNamespaceName := f.Namespace.Name
173162
testConfigMapName := "test-configmap" + string(uuid.NewUUID())
174163

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-
}
181164
testConfigMap := v1.ConfigMap{
182165
ObjectMeta: metav1.ObjectMeta{
183166
Name: testConfigMapName,
@@ -190,103 +173,62 @@ var _ = ginkgo.Describe("[sig-node] ConfigMap", func() {
190173
},
191174
}
192175

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")
210179

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"])
222185

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")
240197

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")
246201

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
262216
}
263-
framework.ExpectEqual(testConfigMapFound, true, "failed to find ConfigMap in list")
217+
}
218+
framework.ExpectEqual(testConfigMapFound, true, "failed to find ConfigMap by label selector")
264219

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")
284225

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",
289229
})
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")
290232
})
291233
})
292234

0 commit comments

Comments
 (0)