From 064b5916172fd414695eb6c27363ea8548cc632b Mon Sep 17 00:00:00 2001 From: Roman Bednar Date: Wed, 6 Aug 2025 17:54:06 +0200 Subject: [PATCH] improve CRD handling in VolumePopulator test Test: provisioning should provision storage with any volume data source During CSI certification test we observed that the test can fail with a message: "customresourcedefinitions.apiextensions.k8s.io \"volumepopulators.populator.storage.k8s.io\" already exists" This is because the test does not consider that this CRD can be already installed in the cluster. The test was updated to handle the CRD better by creating it for the duration of the test and removing it afterward. Otherwise, if the CRD is already installed, the test will neither create nor remove it --- test/e2e/storage/testsuites/provisioning.go | 28 +++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/test/e2e/storage/testsuites/provisioning.go b/test/e2e/storage/testsuites/provisioning.go index bb220b3ade0..a564a31cee2 100644 --- a/test/e2e/storage/testsuites/provisioning.go +++ b/test/e2e/storage/testsuites/provisioning.go @@ -19,6 +19,8 @@ package testsuites import ( "context" "fmt" + apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" + crdclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" "strconv" "strings" "sync" @@ -297,12 +299,34 @@ func (p *provisioningTestSuite) DefineTests(driver storageframework.TestDriver, framework.ExpectNoError(err) ginkgo.DeferCleanup(f.DeleteNamespace, valNamespace.Name) - ginkgo.By("Deploying validator") valManifests := []string{ - "test/e2e/testing-manifests/storage-csi/any-volume-datasource/crd/populator.storage.k8s.io_volumepopulators.yaml", "test/e2e/testing-manifests/storage-csi/any-volume-datasource/volume-data-source-validator/rbac-data-source-validator.yaml", "test/e2e/testing-manifests/storage-csi/any-volume-datasource/volume-data-source-validator/setup-data-source-validator.yaml", } + + crdManifestPath := "test/e2e/testing-manifests/storage-csi/any-volume-datasource/crd/populator.storage.k8s.io_volumepopulators.yaml" + crdItems, err := storageutils.LoadFromManifests(crdManifestPath) + framework.ExpectNoError(err, "Failed to load VolumePopulator CRD manifest") + gomega.Expect(crdItems).To(gomega.HaveLen(1), "Expected exactly one CRD in manifest") + + crd, ok := crdItems[0].(*apiextensionsv1.CustomResourceDefinition) + gomega.Expect(ok).To(gomega.BeTrueBecause("Resource in loaded manifest file is not a CustomResourceDefinition: %s", crdManifestPath)) + + config, err := framework.LoadConfig() + framework.ExpectNoError(err) + apiExtensionClient, err := crdclientset.NewForConfig(config) + framework.ExpectNoError(err) + + ginkgo.By(fmt.Sprintf("Checking if %s CRD exists", crd.Name)) + _, err = apiExtensionClient.ApiextensionsV1().CustomResourceDefinitions().Get(ctx, crd.Name, metav1.GetOptions{}) + if err != nil && apierrors.IsNotFound(err) { + ginkgo.By("VolumePopulator CRD not found, test will create it and remove when done") + valManifests = append(valManifests, crdManifestPath) + } else if err != nil { + framework.ExpectNoError(err, "Error checking for VolumePopulator CRD existence") + } + + ginkgo.By("Deploying validator") err = storageutils.CreateFromManifests(ctx, f, valNamespace, func(item interface{}) error { return nil }, valManifests...)