Skip to content

Commit 064b591

Browse files
committed
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
1 parent b4b973c commit 064b591

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

test/e2e/storage/testsuites/provisioning.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package testsuites
1919
import (
2020
"context"
2121
"fmt"
22+
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
23+
crdclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
2224
"strconv"
2325
"strings"
2426
"sync"
@@ -297,12 +299,34 @@ func (p *provisioningTestSuite) DefineTests(driver storageframework.TestDriver,
297299
framework.ExpectNoError(err)
298300
ginkgo.DeferCleanup(f.DeleteNamespace, valNamespace.Name)
299301

300-
ginkgo.By("Deploying validator")
301302
valManifests := []string{
302-
"test/e2e/testing-manifests/storage-csi/any-volume-datasource/crd/populator.storage.k8s.io_volumepopulators.yaml",
303303
"test/e2e/testing-manifests/storage-csi/any-volume-datasource/volume-data-source-validator/rbac-data-source-validator.yaml",
304304
"test/e2e/testing-manifests/storage-csi/any-volume-datasource/volume-data-source-validator/setup-data-source-validator.yaml",
305305
}
306+
307+
crdManifestPath := "test/e2e/testing-manifests/storage-csi/any-volume-datasource/crd/populator.storage.k8s.io_volumepopulators.yaml"
308+
crdItems, err := storageutils.LoadFromManifests(crdManifestPath)
309+
framework.ExpectNoError(err, "Failed to load VolumePopulator CRD manifest")
310+
gomega.Expect(crdItems).To(gomega.HaveLen(1), "Expected exactly one CRD in manifest")
311+
312+
crd, ok := crdItems[0].(*apiextensionsv1.CustomResourceDefinition)
313+
gomega.Expect(ok).To(gomega.BeTrueBecause("Resource in loaded manifest file is not a CustomResourceDefinition: %s", crdManifestPath))
314+
315+
config, err := framework.LoadConfig()
316+
framework.ExpectNoError(err)
317+
apiExtensionClient, err := crdclientset.NewForConfig(config)
318+
framework.ExpectNoError(err)
319+
320+
ginkgo.By(fmt.Sprintf("Checking if %s CRD exists", crd.Name))
321+
_, err = apiExtensionClient.ApiextensionsV1().CustomResourceDefinitions().Get(ctx, crd.Name, metav1.GetOptions{})
322+
if err != nil && apierrors.IsNotFound(err) {
323+
ginkgo.By("VolumePopulator CRD not found, test will create it and remove when done")
324+
valManifests = append(valManifests, crdManifestPath)
325+
} else if err != nil {
326+
framework.ExpectNoError(err, "Error checking for VolumePopulator CRD existence")
327+
}
328+
329+
ginkgo.By("Deploying validator")
306330
err = storageutils.CreateFromManifests(ctx, f, valNamespace,
307331
func(item interface{}) error { return nil },
308332
valManifests...)

0 commit comments

Comments
 (0)