mirror of
https://github.com/outbackdingo/kubernetes.git
synced 2026-01-27 10:19:35 +00:00
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
This commit is contained in:
@@ -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...)
|
||||
|
||||
Reference in New Issue
Block a user