mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Merge pull request #92621 from spiffxp/simplify-configmap-lifecycle-test
Simplify ConfigMap lifecycle e2e test
This commit is contained in:
commit
1f89f42602
@ -58,7 +58,6 @@ go_library(
|
|||||||
"//staging/src/k8s.io/apimachinery/pkg/fields:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/fields:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/util/diff:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/util/diff:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
|
||||||
@ -67,7 +66,6 @@ go_library(
|
|||||||
"//staging/src/k8s.io/apimachinery/pkg/util/uuid:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/util/uuid:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/dynamic:go_default_library",
|
|
||||||
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
|
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/tools/cache:go_default_library",
|
"//staging/src/k8s.io/client-go/tools/cache:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/tools/watch:go_default_library",
|
"//staging/src/k8s.io/client-go/tools/watch:go_default_library",
|
||||||
|
@ -20,16 +20,11 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
|
|
||||||
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"
|
|
||||||
"k8s.io/client-go/dynamic"
|
|
||||||
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"
|
||||||
|
|
||||||
@ -39,12 +34,6 @@ import (
|
|||||||
var _ = ginkgo.Describe("[sig-node] ConfigMap", func() {
|
var _ = ginkgo.Describe("[sig-node] ConfigMap", func() {
|
||||||
f := framework.NewDefaultFramework("configmap")
|
f := framework.NewDefaultFramework("configmap")
|
||||||
|
|
||||||
var dc dynamic.Interface
|
|
||||||
|
|
||||||
ginkgo.BeforeEach(func() {
|
|
||||||
dc = f.DynamicClient
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Release : v1.9
|
Release : v1.9
|
||||||
Testname: ConfigMap, from environment field
|
Testname: ConfigMap, from environment field
|
||||||
@ -172,12 +161,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 +173,15 @@ 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) {
|
|
||||||
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)
|
ginkgo.By("fetching the ConfigMap")
|
||||||
defer cancel()
|
configMap, err := f.ClientSet.CoreV1().ConfigMaps(testNamespaceName).Get(context.TODO(), testConfigMapName, metav1.GetOptions{})
|
||||||
_, err = framework.WatchUntilWithoutRetry(ctx, retryWatcher, func(watchEvent watch.Event) (bool, error) {
|
framework.ExpectNoError(err, "failed to get ConfigMap")
|
||||||
if watchEvent.Type != watch.Added {
|
framework.ExpectEqual(configMap.Data["valueName"], testConfigMap.Data["valueName"])
|
||||||
return false, nil
|
framework.ExpectEqual(configMap.Labels["test-configmap-static"], testConfigMap.Labels["test-configmap-static"])
|
||||||
}
|
|
||||||
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.Added)
|
|
||||||
|
|
||||||
configMapPatchPayload, err := json.Marshal(v1.ConfigMap{
|
configMapPatchPayload, err := json.Marshal(v1.ConfigMap{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
@ -223,70 +198,37 @@ var _ = ginkgo.Describe("[sig-node] ConfigMap", func() {
|
|||||||
ginkgo.By("patching the ConfigMap")
|
ginkgo.By("patching the ConfigMap")
|
||||||
_, 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")
|
|
||||||
eventFound = false
|
|
||||||
ctx, cancel = context.WithTimeout(context.Background(), 30*time.Second)
|
|
||||||
defer cancel()
|
|
||||||
_, err = framework.WatchUntilWithoutRetry(ctx, retryWatcher, func(watchEvent watch.Event) (bool, error) {
|
|
||||||
if watchEvent.Type != watch.Modified {
|
|
||||||
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.Modified)
|
|
||||||
|
|
||||||
ginkgo.By("fetching the ConfigMap")
|
ginkgo.By("listing all ConfigMaps in all namespaces with a label selector")
|
||||||
configMap, err := f.ClientSet.CoreV1().ConfigMaps(testNamespaceName).Get(context.TODO(), testConfigMapName, metav1.GetOptions{})
|
|
||||||
framework.ExpectNoError(err, "failed to get ConfigMap")
|
|
||||||
framework.ExpectEqual(configMap.Data["valueName"], "value1", "failed to patch ConfigMap")
|
|
||||||
framework.ExpectEqual(configMap.Labels["test-configmap"], "patched", "failed to patch ConfigMap")
|
|
||||||
|
|
||||||
ginkgo.By("listing all ConfigMaps in all namespaces")
|
|
||||||
configMapList, err := f.ClientSet.CoreV1().ConfigMaps("").List(context.TODO(), metav1.ListOptions{
|
configMapList, err := f.ClientSet.CoreV1().ConfigMaps("").List(context.TODO(), metav1.ListOptions{
|
||||||
LabelSelector: "test-configmap-static=true",
|
LabelSelector: "test-configmap=patched",
|
||||||
})
|
})
|
||||||
framework.ExpectNoError(err, "failed to list ConfigMaps with LabelSelector")
|
framework.ExpectNoError(err, "failed to list ConfigMaps with LabelSelector")
|
||||||
framework.ExpectNotEqual(len(configMapList.Items), 0, "no ConfigMaps found in ConfigMap list")
|
|
||||||
testConfigMapFound := false
|
testConfigMapFound := false
|
||||||
for _, cm := range configMapList.Items {
|
for _, cm := range configMapList.Items {
|
||||||
if cm.ObjectMeta.Name == testConfigMapName &&
|
if cm.ObjectMeta.Name == testConfigMap.ObjectMeta.Name &&
|
||||||
cm.ObjectMeta.Namespace == testNamespaceName &&
|
cm.ObjectMeta.Namespace == testNamespaceName &&
|
||||||
cm.ObjectMeta.Labels["test-configmap-static"] == "true" &&
|
cm.ObjectMeta.Labels["test-configmap-static"] == testConfigMap.ObjectMeta.Labels["test-configmap-static"] &&
|
||||||
|
cm.ObjectMeta.Labels["test-configmap"] == "patched" &&
|
||||||
cm.Data["valueName"] == "value1" {
|
cm.Data["valueName"] == "value1" {
|
||||||
testConfigMapFound = true
|
testConfigMapFound = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
framework.ExpectEqual(testConfigMapFound, true, "failed to find ConfigMap in list")
|
framework.ExpectEqual(testConfigMapFound, true, "failed to find ConfigMap by label selector")
|
||||||
|
|
||||||
ginkgo.By("deleting the ConfigMap by a collection")
|
ginkgo.By("deleting the ConfigMap by collection with a label selector")
|
||||||
err = f.ClientSet.CoreV1().ConfigMaps(testNamespaceName).DeleteCollection(context.TODO(), metav1.DeleteOptions{}, metav1.ListOptions{
|
err = f.ClientSet.CoreV1().ConfigMaps(testNamespaceName).DeleteCollection(context.TODO(), metav1.DeleteOptions{}, metav1.ListOptions{
|
||||||
LabelSelector: "test-configmap-static=true",
|
LabelSelector: "test-configmap-static=true",
|
||||||
})
|
})
|
||||||
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")
|
|
||||||
eventFound = false
|
|
||||||
ctx, cancel = context.WithTimeout(context.Background(), 30*time.Second)
|
|
||||||
defer cancel()
|
|
||||||
_, err = framework.WatchUntilWithoutRetry(ctx, retryWatcher, func(watchEvent watch.Event) (bool, error) {
|
|
||||||
if watchEvent.Type != watch.Deleted {
|
|
||||||
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
|
ginkgo.By("listing all ConfigMaps in test namespace")
|
||||||
}, func() (err error) {
|
configMapList, err = f.ClientSet.CoreV1().ConfigMaps(testNamespaceName).List(context.TODO(), metav1.ListOptions{
|
||||||
_ = f.ClientSet.CoreV1().ConfigMaps(testNamespaceName).DeleteCollection(context.TODO(), metav1.DeleteOptions{}, metav1.ListOptions{LabelSelector: "test-configmap-static=true"})
|
LabelSelector: "test-configmap-static=true",
|
||||||
return err
|
|
||||||
})
|
})
|
||||||
|
framework.ExpectNoError(err, "failed to list ConfigMap by LabelSelector")
|
||||||
|
framework.ExpectEqual(len(configMapList.Items), 0, "ConfigMap is still present after being deleted by collection")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user