mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +00:00
crd-e2e: check watch observes CR modified events; use WatchUnsafe
creation method when the test doesn't exercise CR API
This commit is contained in:
parent
a1f1f0b599
commit
626c4770e6
@ -26,6 +26,7 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
"k8s.io/client-go/dynamic"
|
||||
"k8s.io/kubernetes/test/e2e/framework"
|
||||
@ -99,6 +100,18 @@ var _ = SIGDescribe("CustomResourceDefinition Watch", func() {
|
||||
expectEvent(watchB, watch.Added, testCrB)
|
||||
expectNoEvent(watchA, watch.Added, testCrB)
|
||||
|
||||
ginkgo.By("Modifying first CR")
|
||||
err = patchCustomResource(noxuResourceClient, watchCRNameA)
|
||||
framework.ExpectNoError(err, "failed to patch custom resource: %s", watchCRNameA)
|
||||
expectEvent(watchA, watch.Modified, nil)
|
||||
expectNoEvent(watchB, watch.Modified, nil)
|
||||
|
||||
ginkgo.By("Modifying second CR")
|
||||
err = patchCustomResource(noxuResourceClient, watchCRNameB)
|
||||
framework.ExpectNoError(err, "failed to patch custom resource: %s", watchCRNameB)
|
||||
expectEvent(watchB, watch.Modified, nil)
|
||||
expectNoEvent(watchA, watch.Modified, nil)
|
||||
|
||||
ginkgo.By("Deleting first CR")
|
||||
err = deleteCustomResource(noxuResourceClient, watchCRNameA)
|
||||
framework.ExpectNoError(err, "failed to delete custom resource: %s", watchCRNameA)
|
||||
@ -152,6 +165,15 @@ func instantiateCustomResource(instanceToCreate *unstructured.Unstructured, clie
|
||||
return createdInstance, nil
|
||||
}
|
||||
|
||||
func patchCustomResource(client dynamic.ResourceInterface, name string) error {
|
||||
_, err := client.Patch(
|
||||
name,
|
||||
types.JSONPatchType,
|
||||
[]byte(`[{ "op": "add", "path": "/dummy", "value": "test" }]`),
|
||||
metav1.PatchOptions{})
|
||||
return err
|
||||
}
|
||||
|
||||
func deleteCustomResource(client dynamic.ResourceInterface, name string) error {
|
||||
return client.Delete(name, &metav1.DeleteOptions{})
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ import (
|
||||
|
||||
var _ = SIGDescribe("CustomResourceDefinition resources", func() {
|
||||
|
||||
f := framework.NewDefaultFramework("custom-resource-definition")
|
||||
framework.NewDefaultFramework("custom-resource-definition")
|
||||
|
||||
ginkgo.Context("Simple CustomResourceDefinition", func() {
|
||||
/*
|
||||
@ -55,7 +55,7 @@ var _ = SIGDescribe("CustomResourceDefinition resources", func() {
|
||||
randomDefinition := fixtures.NewRandomNameV1CustomResourceDefinition(v1.ClusterScoped)
|
||||
|
||||
// Create CRD and waits for the resource to be recognized and available.
|
||||
randomDefinition, err = fixtures.CreateNewV1CustomResourceDefinition(randomDefinition, apiExtensionClient, f.DynamicClient)
|
||||
randomDefinition, err = fixtures.CreateNewV1CustomResourceDefinitionWatchUnsafe(randomDefinition, apiExtensionClient)
|
||||
framework.ExpectNoError(err, "creating CustomResourceDefinition")
|
||||
|
||||
defer func() {
|
||||
@ -84,14 +84,14 @@ var _ = SIGDescribe("CustomResourceDefinition resources", func() {
|
||||
for i := 0; i < testListSize; i++ {
|
||||
crd := fixtures.NewRandomNameV1CustomResourceDefinition(v1.ClusterScoped)
|
||||
crd.Labels = map[string]string{"e2e-list-test-uuid": testUUID}
|
||||
crd, err = fixtures.CreateNewV1CustomResourceDefinition(crd, apiExtensionClient, f.DynamicClient)
|
||||
crd, err = fixtures.CreateNewV1CustomResourceDefinitionWatchUnsafe(crd, apiExtensionClient)
|
||||
framework.ExpectNoError(err, "creating CustomResourceDefinition")
|
||||
crds[i] = crd
|
||||
}
|
||||
|
||||
// Create a crd w/o the label to ensure the label selector matching works correctly
|
||||
crd := fixtures.NewRandomNameV1CustomResourceDefinition(v1.ClusterScoped)
|
||||
crd, err = fixtures.CreateNewV1CustomResourceDefinition(crd, apiExtensionClient, f.DynamicClient)
|
||||
crd, err = fixtures.CreateNewV1CustomResourceDefinitionWatchUnsafe(crd, apiExtensionClient)
|
||||
framework.ExpectNoError(err, "creating CustomResourceDefinition")
|
||||
defer func() {
|
||||
err = fixtures.DeleteV1CustomResourceDefinition(crd, apiExtensionClient)
|
||||
@ -140,7 +140,7 @@ var _ = SIGDescribe("CustomResourceDefinition resources", func() {
|
||||
|
||||
// Create CRD and waits for the resource to be recognized and available.
|
||||
crd := fixtures.NewRandomNameV1CustomResourceDefinition(v1.ClusterScoped)
|
||||
crd, err = fixtures.CreateNewV1CustomResourceDefinition(crd, apiExtensionClient, f.DynamicClient)
|
||||
crd, err = fixtures.CreateNewV1CustomResourceDefinitionWatchUnsafe(crd, apiExtensionClient)
|
||||
framework.ExpectNoError(err, "creating CustomResourceDefinition")
|
||||
defer func() {
|
||||
err = fixtures.DeleteV1CustomResourceDefinition(crd, apiExtensionClient)
|
||||
|
Loading…
Reference in New Issue
Block a user