Skip to content

Commit 121676e

Browse files
committed
Drop the use of watchtools
The thing is, for this test at least, I'm pretty sure there's nothing we need to wait on. Instead of waiting for a deleted event, we will relist configmaps and expect 0, to confirm the deletion took effect
1 parent 0a869ac commit 121676e

File tree

2 files changed

+6
-79
lines changed

2 files changed

+6
-79
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: 6 additions & 77 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"
2726
"k8s.io/apimachinery/pkg/types"
2827
"k8s.io/apimachinery/pkg/util/uuid"
29-
watch "k8s.io/apimachinery/pkg/watch"
30-
"k8s.io/client-go/dynamic"
31-
"k8s.io/client-go/tools/cache"
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
@@ -184,37 +173,10 @@ var _ = ginkgo.Describe("[sig-node] ConfigMap", func() {
184173
},
185174
}
186175

187-
w := &cache.ListWatch{
188-
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
189-
options.LabelSelector = "test-configmap-static=true"
190-
return f.ClientSet.CoreV1().ConfigMaps(testNamespaceName).Watch(context.TODO(), options)
191-
},
192-
}
193-
cml, err := f.ClientSet.CoreV1().ConfigMaps(testNamespaceName).List(context.TODO(), metav1.ListOptions{LabelSelector: "test-configmap-static=true"})
194-
framework.ExpectNoError(err)
195-
196176
ginkgo.By("creating a ConfigMap")
197-
cm, err := f.ClientSet.CoreV1().ConfigMaps(testNamespaceName).Create(context.TODO(), &testConfigMap, metav1.CreateOptions{})
177+
_, err := f.ClientSet.CoreV1().ConfigMaps(testNamespaceName).Create(context.TODO(), &testConfigMap, metav1.CreateOptions{})
198178
framework.ExpectNoError(err, "failed to create ConfigMap")
199179

200-
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
201-
defer cancel()
202-
_, err = watchtools.Until(ctx, cml.ResourceVersion, w, func(event watch.Event) (bool, error) {
203-
switch event.Type {
204-
case watch.Added:
205-
if cm, ok := event.Object.(*v1.ConfigMap); ok {
206-
found := cm.ObjectMeta.Name == testConfigMap.Name &&
207-
cm.Labels["test-configmap-static"] == "true" &&
208-
cm.Data["valueName"] == "value"
209-
return found, nil
210-
}
211-
default:
212-
framework.Logf("observed event type %v", event.Type)
213-
}
214-
return false, nil
215-
})
216-
framework.ExpectNoError(err, "failed to see a watch.Added event for the configmap we created")
217-
218180
configMapPatchPayload, err := json.Marshal(v1.ConfigMap{
219181
ObjectMeta: metav1.ObjectMeta{
220182
Labels: map[string]string{
@@ -228,27 +190,8 @@ var _ = ginkgo.Describe("[sig-node] ConfigMap", func() {
228190
framework.ExpectNoError(err, "failed to marshal patch data")
229191

230192
ginkgo.By("patching the ConfigMap")
231-
cm2, err := f.ClientSet.CoreV1().ConfigMaps(testNamespaceName).Patch(context.TODO(), testConfigMapName, types.StrategicMergePatchType, []byte(configMapPatchPayload), metav1.PatchOptions{})
193+
_, err = f.ClientSet.CoreV1().ConfigMaps(testNamespaceName).Patch(context.TODO(), testConfigMapName, types.StrategicMergePatchType, []byte(configMapPatchPayload), metav1.PatchOptions{})
232194
framework.ExpectNoError(err, "failed to patch ConfigMap")
233-
ginkgo.By("waiting for the ConfigMap to be modified")
234-
ctx, cancel = context.WithTimeout(context.Background(), 30*time.Second)
235-
defer cancel()
236-
_, err = watchtools.Until(ctx, cm.ResourceVersion, w, func(event watch.Event) (bool, error) {
237-
switch event.Type {
238-
case watch.Modified:
239-
if cm, ok := event.Object.(*v1.ConfigMap); ok {
240-
found := cm.ObjectMeta.Name == testConfigMap.Name &&
241-
cm.Labels["test-configmap-static"] == "true" &&
242-
cm.Labels["test-configmap"] == "patched" &&
243-
cm.Data["valueName"] == "value1"
244-
return found, nil
245-
}
246-
default:
247-
framework.Logf("observed event type %v", event.Type)
248-
}
249-
return false, nil
250-
})
251-
framework.ExpectNoError(err, "failed to see a watch.Modified event for the configmap we patched")
252195

253196
ginkgo.By("fetching the ConfigMap")
254197
configMap, err := f.ClientSet.CoreV1().ConfigMaps(testNamespaceName).Get(context.TODO(), testConfigMapName, metav1.GetOptions{})
@@ -279,25 +222,11 @@ var _ = ginkgo.Describe("[sig-node] ConfigMap", func() {
279222
LabelSelector: "test-configmap-static=true",
280223
})
281224
framework.ExpectNoError(err, "failed to delete ConfigMap collection with LabelSelector")
282-
ginkgo.By("waiting for the ConfigMap to be deleted")
283-
ctx, cancel = context.WithTimeout(context.Background(), 30*time.Second)
284-
defer cancel()
285-
_, err = watchtools.Until(ctx, cm2.ResourceVersion, w, func(event watch.Event) (bool, error) {
286-
switch event.Type {
287-
case watch.Deleted:
288-
if cm, ok := event.Object.(*v1.ConfigMap); ok {
289-
found := cm.ObjectMeta.Name == testConfigMap.Name &&
290-
cm.Labels["test-configmap-static"] == "true" &&
291-
cm.Labels["test-configmap"] == "patched" &&
292-
cm.Data["valueName"] == "value1"
293-
return found, nil
294-
}
295-
default:
296-
framework.Logf("observed event type %v", event.Type)
297-
}
298-
return false, nil
225+
ginkgo.By("listing all ConfigMaps in all namespaces")
226+
configMapList, err = f.ClientSet.CoreV1().ConfigMaps("").List(context.TODO(), metav1.ListOptions{
227+
LabelSelector: "test-configmap-static=true",
299228
})
300-
framework.ExpectNoError(err, "fasiled to observe a watch.Deleted event for the ConfigMap we deleted")
229+
framework.ExpectEqual(len(configMapList.Items), 0, "ConfigMap is still present after being deleted by collection")
301230
})
302231
})
303232

0 commit comments

Comments
 (0)