mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
Drop WatchSequenceEventVerifier from configmap lifecycle test
Collecting events in a certain order and then verifying the order in which they were collected feels redundant.
This commit is contained in:
parent
71c352dee3
commit
9fb05616ca
@ -24,11 +24,11 @@ import (
|
|||||||
|
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/apimachinery/pkg/util/uuid"
|
"k8s.io/apimachinery/pkg/util/uuid"
|
||||||
watch "k8s.io/apimachinery/pkg/watch"
|
watch "k8s.io/apimachinery/pkg/watch"
|
||||||
"k8s.io/client-go/dynamic"
|
"k8s.io/client-go/dynamic"
|
||||||
|
"k8s.io/client-go/tools/cache"
|
||||||
watchtools "k8s.io/client-go/tools/watch"
|
watchtools "k8s.io/client-go/tools/watch"
|
||||||
"k8s.io/kubernetes/test/e2e/framework"
|
"k8s.io/kubernetes/test/e2e/framework"
|
||||||
imageutils "k8s.io/kubernetes/test/utils/image"
|
imageutils "k8s.io/kubernetes/test/utils/image"
|
||||||
@ -172,12 +172,6 @@ var _ = ginkgo.Describe("[sig-node] ConfigMap", func() {
|
|||||||
testNamespaceName := f.Namespace.Name
|
testNamespaceName := f.Namespace.Name
|
||||||
testConfigMapName := "test-configmap" + string(uuid.NewUUID())
|
testConfigMapName := "test-configmap" + string(uuid.NewUUID())
|
||||||
|
|
||||||
configMapResource := schema.GroupVersionResource{Group: "", Version: "v1", Resource: "configmaps"}
|
|
||||||
expectedWatchEvents := []watch.Event{
|
|
||||||
{Type: watch.Added},
|
|
||||||
{Type: watch.Modified},
|
|
||||||
{Type: watch.Deleted},
|
|
||||||
}
|
|
||||||
testConfigMap := v1.ConfigMap{
|
testConfigMap := v1.ConfigMap{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: testConfigMapName,
|
Name: testConfigMapName,
|
||||||
@ -190,23 +184,26 @@ var _ = ginkgo.Describe("[sig-node] ConfigMap", func() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
framework.WatchEventSequenceVerifier(context.TODO(), dc, configMapResource, testNamespaceName, testConfigMapName, metav1.ListOptions{LabelSelector: "test-configmap-static=true"}, expectedWatchEvents, func(retryWatcher *watchtools.RetryWatcher) (actualWatchEvents []watch.Event) {
|
w := &cache.ListWatch{
|
||||||
|
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
|
||||||
|
options.LabelSelector = "test-configmap-static=true"
|
||||||
|
return f.ClientSet.CoreV1().ConfigMaps(testNamespaceName).Watch(context.TODO(), options)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
cml, err := f.ClientSet.CoreV1().ConfigMaps(testNamespaceName).List(context.TODO(), metav1.ListOptions{LabelSelector: "test-configmap-static=true"})
|
||||||
|
framework.ExpectNoError(err)
|
||||||
|
retryWatcher, err := watchtools.NewRetryWatcher(cml.ResourceVersion, w)
|
||||||
|
|
||||||
ginkgo.By("creating a ConfigMap")
|
ginkgo.By("creating a ConfigMap")
|
||||||
_, err := f.ClientSet.CoreV1().ConfigMaps(testNamespaceName).Create(context.TODO(), &testConfigMap, metav1.CreateOptions{})
|
_, err = f.ClientSet.CoreV1().ConfigMaps(testNamespaceName).Create(context.TODO(), &testConfigMap, metav1.CreateOptions{})
|
||||||
framework.ExpectNoError(err, "failed to create ConfigMap")
|
framework.ExpectNoError(err, "failed to create ConfigMap")
|
||||||
eventFound := false
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
_, err = framework.WatchUntilWithoutRetry(ctx, retryWatcher, func(watchEvent watch.Event) (bool, error) {
|
_, err = framework.WatchUntilWithoutRetry(ctx, retryWatcher, func(watchEvent watch.Event) (bool, error) {
|
||||||
if watchEvent.Type != watch.Added {
|
return watchEvent.Type == watch.Added, nil
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
actualWatchEvents = append(actualWatchEvents, watchEvent)
|
|
||||||
eventFound = true
|
|
||||||
return true, nil
|
|
||||||
})
|
})
|
||||||
framework.ExpectNoError(err, "Wait until condition with watch events should not return an error")
|
framework.ExpectNoError(err, "failed to see a watch.Added event for the configmap we created")
|
||||||
framework.ExpectEqual(eventFound, true, "failed to find ConfigMap %v event", watch.Added)
|
|
||||||
|
|
||||||
configMapPatchPayload, err := json.Marshal(v1.ConfigMap{
|
configMapPatchPayload, err := json.Marshal(v1.ConfigMap{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
@ -224,19 +221,12 @@ var _ = ginkgo.Describe("[sig-node] ConfigMap", func() {
|
|||||||
_, err = f.ClientSet.CoreV1().ConfigMaps(testNamespaceName).Patch(context.TODO(), testConfigMapName, types.StrategicMergePatchType, []byte(configMapPatchPayload), metav1.PatchOptions{})
|
_, err = f.ClientSet.CoreV1().ConfigMaps(testNamespaceName).Patch(context.TODO(), testConfigMapName, types.StrategicMergePatchType, []byte(configMapPatchPayload), metav1.PatchOptions{})
|
||||||
framework.ExpectNoError(err, "failed to patch ConfigMap")
|
framework.ExpectNoError(err, "failed to patch ConfigMap")
|
||||||
ginkgo.By("waiting for the ConfigMap to be modified")
|
ginkgo.By("waiting for the ConfigMap to be modified")
|
||||||
eventFound = false
|
|
||||||
ctx, cancel = context.WithTimeout(context.Background(), 30*time.Second)
|
ctx, cancel = context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
_, err = framework.WatchUntilWithoutRetry(ctx, retryWatcher, func(watchEvent watch.Event) (bool, error) {
|
_, err = framework.WatchUntilWithoutRetry(ctx, retryWatcher, func(watchEvent watch.Event) (bool, error) {
|
||||||
if watchEvent.Type != watch.Modified {
|
return watchEvent.Type == watch.Modified, nil
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
actualWatchEvents = append(actualWatchEvents, watchEvent)
|
|
||||||
eventFound = true
|
|
||||||
return true, nil
|
|
||||||
})
|
})
|
||||||
framework.ExpectNoError(err, "Wait until condition with watch events should not return an error")
|
framework.ExpectNoError(err, "failed to see a watch.Modified event for the configmap we patched")
|
||||||
framework.ExpectEqual(eventFound, true, "failed to find ConfigMap %v event", watch.Modified)
|
|
||||||
|
|
||||||
ginkgo.By("fetching the ConfigMap")
|
ginkgo.By("fetching the ConfigMap")
|
||||||
configMap, err := f.ClientSet.CoreV1().ConfigMaps(testNamespaceName).Get(context.TODO(), testConfigMapName, metav1.GetOptions{})
|
configMap, err := f.ClientSet.CoreV1().ConfigMaps(testNamespaceName).Get(context.TODO(), testConfigMapName, metav1.GetOptions{})
|
||||||
@ -268,25 +258,12 @@ var _ = ginkgo.Describe("[sig-node] ConfigMap", func() {
|
|||||||
})
|
})
|
||||||
framework.ExpectNoError(err, "failed to delete ConfigMap collection with LabelSelector")
|
framework.ExpectNoError(err, "failed to delete ConfigMap collection with LabelSelector")
|
||||||
ginkgo.By("waiting for the ConfigMap to be deleted")
|
ginkgo.By("waiting for the ConfigMap to be deleted")
|
||||||
eventFound = false
|
|
||||||
ctx, cancel = context.WithTimeout(context.Background(), 30*time.Second)
|
ctx, cancel = context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
_, err = framework.WatchUntilWithoutRetry(ctx, retryWatcher, func(watchEvent watch.Event) (bool, error) {
|
_, err = framework.WatchUntilWithoutRetry(ctx, retryWatcher, func(watchEvent watch.Event) (bool, error) {
|
||||||
if watchEvent.Type != watch.Deleted {
|
return watchEvent.Type == watch.Deleted, nil
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
actualWatchEvents = append(actualWatchEvents, watchEvent)
|
|
||||||
eventFound = true
|
|
||||||
return true, nil
|
|
||||||
})
|
|
||||||
framework.ExpectNoError(err, "Wait until condition with watch events should not return an error")
|
|
||||||
framework.ExpectEqual(eventFound, true, "failed to find ConfigMap %v event", watch.Deleted)
|
|
||||||
|
|
||||||
return actualWatchEvents
|
|
||||||
}, func() (err error) {
|
|
||||||
_ = f.ClientSet.CoreV1().ConfigMaps(testNamespaceName).DeleteCollection(context.TODO(), metav1.DeleteOptions{}, metav1.ListOptions{LabelSelector: "test-configmap-static=true"})
|
|
||||||
return err
|
|
||||||
})
|
})
|
||||||
|
framework.ExpectNoError(err, "fasiled to observe a watch.Deleted event for the ConfigMap we deleted")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user