From cf125a2db35430edeebce5d10cdce2061e7511c7 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Thu, 25 Jul 2019 15:03:06 +0200 Subject: [PATCH] e2e storage: enable testing of ephemeral inline volumes with hostpath CSI driver We need the 1.2.0 driver for that because that has support for detecting the volume mode dynamically, and we need to deploy a CSIDriver object which enables pod info (for the dynamic detection) and both modes (to satisfy the new mode sanity check). --- test/e2e/storage/csi_volumes.go | 1 + test/e2e/storage/drivers/csi.go | 36 ++++++++++++++----- test/e2e/storage/utils/deployment.go | 8 +++-- .../hostpath/csi-hostpath-driverinfo.yaml | 10 ++++++ 4 files changed, 44 insertions(+), 11 deletions(-) create mode 100644 test/e2e/testing-manifests/storage-csi/hostpath/hostpath/csi-hostpath-driverinfo.yaml diff --git a/test/e2e/storage/csi_volumes.go b/test/e2e/storage/csi_volumes.go index 5d1d01c2028..706b9f7dd66 100644 --- a/test/e2e/storage/csi_volumes.go +++ b/test/e2e/storage/csi_volumes.go @@ -42,6 +42,7 @@ var csiTestDrivers = []func() testsuites.TestDriver{ // List of testSuites to be executed in below loop var csiTestSuites = []func() testsuites.TestSuite{ + testsuites.InitEphemeralTestSuite, testsuites.InitVolumesTestSuite, testsuites.InitVolumeIOTestSuite, testsuites.InitVolumeModeTestSuite, diff --git a/test/e2e/storage/drivers/csi.go b/test/e2e/storage/drivers/csi.go index 87d511a45f3..e70dd468925 100644 --- a/test/e2e/storage/drivers/csi.go +++ b/test/e2e/storage/drivers/csi.go @@ -62,11 +62,12 @@ const ( // hostpathCSI type hostpathCSIDriver struct { - driverInfo testsuites.DriverInfo - manifests []string + driverInfo testsuites.DriverInfo + manifests []string + volumeAttributes []map[string]string } -func initHostPathCSIDriver(name string, capabilities map[testsuites.Capability]bool, manifests ...string) testsuites.TestDriver { +func initHostPathCSIDriver(name string, capabilities map[testsuites.Capability]bool, volumeAttributes []map[string]string, manifests ...string) testsuites.TestDriver { return &hostpathCSIDriver{ driverInfo: testsuites.DriverInfo{ Name: name, @@ -77,13 +78,15 @@ func initHostPathCSIDriver(name string, capabilities map[testsuites.Capability]b ), Capabilities: capabilities, }, - manifests: manifests, + manifests: manifests, + volumeAttributes: volumeAttributes, } } var _ testsuites.TestDriver = &hostpathCSIDriver{} var _ testsuites.DynamicPVTestDriver = &hostpathCSIDriver{} var _ testsuites.SnapshottableTestDriver = &hostpathCSIDriver{} +var _ testsuites.EphemeralTestDriver = &hostpathCSIDriver{} // InitHostPathCSIDriver returns hostpathCSIDriver that implements TestDriver interface func InitHostPathCSIDriver() testsuites.TestDriver { @@ -97,15 +100,20 @@ func InitHostPathCSIDriver() testsuites.TestDriver { } return initHostPathCSIDriver("csi-hostpath", capabilities, + // Volume attributes don't matter, but we have to provide at least one map. + []map[string]string{ + {"foo": "bar"}, + }, "test/e2e/testing-manifests/storage-csi/external-attacher/rbac.yaml", "test/e2e/testing-manifests/storage-csi/external-provisioner/rbac.yaml", "test/e2e/testing-manifests/storage-csi/external-snapshotter/rbac.yaml", "test/e2e/testing-manifests/storage-csi/external-resizer/rbac.yaml", "test/e2e/testing-manifests/storage-csi/hostpath/hostpath/csi-hostpath-attacher.yaml", - "test/e2e/testing-manifests/storage-csi/hostpath/hostpath/csi-hostpath-provisioner.yaml", - "test/e2e/testing-manifests/storage-csi/hostpath/hostpath/csi-hostpath-snapshotter.yaml", - "test/e2e/testing-manifests/storage-csi/hostpath/hostpath/csi-hostpath-resizer.yaml", + "test/e2e/testing-manifests/storage-csi/hostpath/hostpath/csi-hostpath-driverinfo.yaml", "test/e2e/testing-manifests/storage-csi/hostpath/hostpath/csi-hostpath-plugin.yaml", + "test/e2e/testing-manifests/storage-csi/hostpath/hostpath/csi-hostpath-provisioner.yaml", + "test/e2e/testing-manifests/storage-csi/hostpath/hostpath/csi-hostpath-resizer.yaml", + "test/e2e/testing-manifests/storage-csi/hostpath/hostpath/csi-hostpath-snapshotter.yaml", "test/e2e/testing-manifests/storage-csi/hostpath/hostpath/e2e-test-rbac.yaml", ) } @@ -115,6 +123,9 @@ func (h *hostpathCSIDriver) GetDriverInfo() *testsuites.DriverInfo { } func (h *hostpathCSIDriver) SkipUnsupportedTest(pattern testpatterns.TestPattern) { + if pattern.VolType == testpatterns.CSIInlineVolume && len(h.volumeAttributes) == 0 { + framework.Skipf("%s has no volume attributes defined, doesn't support ephemeral inline volumes", h.driverInfo.Name) + } } func (h *hostpathCSIDriver) GetDynamicProvisionStorageClass(config *testsuites.PerTestConfig, fsType string) *storagev1.StorageClass { @@ -126,6 +137,14 @@ func (h *hostpathCSIDriver) GetDynamicProvisionStorageClass(config *testsuites.P return testsuites.GetStorageClass(provisioner, parameters, nil, ns, suffix) } +func (h *hostpathCSIDriver) GetVolumeAttributes(config *testsuites.PerTestConfig, volumeNumber int) map[string]string { + return h.volumeAttributes[volumeNumber%len(h.volumeAttributes)] +} + +func (h *hostpathCSIDriver) GetCSIDriverName(config *testsuites.PerTestConfig) string { + return config.GetUniqueDriverName() +} + func (h *hostpathCSIDriver) GetSnapshotClass(config *testsuites.PerTestConfig) *unstructured.Unstructured { snapshotter := config.GetUniqueDriverName() parameters := map[string]string{} @@ -303,7 +322,7 @@ func (m *mockCSIDriver) PrepareTest(f *framework.Framework) (*testsuites.PerTest NodeName: config.ClientNodeName, PodInfo: m.podInfo, CanAttach: &m.attachable, - VolumeLifecycleModes: []storagev1beta1.VolumeLifecycleMode{ + VolumeLifecycleModes: &[]storagev1beta1.VolumeLifecycleMode{ storagev1beta1.VolumeLifecyclePersistent, storagev1beta1.VolumeLifecycleEphemeral, }, @@ -327,6 +346,7 @@ func (m *mockCSIDriver) PrepareTest(f *framework.Framework) (*testsuites.PerTest func InitHostPathV0CSIDriver() testsuites.TestDriver { return initHostPathCSIDriver("csi-hostpath-v0", map[testsuites.Capability]bool{testsuites.CapPersistence: true, testsuites.CapMultiPODs: true}, + nil, /* no volume attributes -> no ephemeral volume testing */ // Using the current set of rbac.yaml files is problematic here because they don't // match the version of the rules that were written for the releases of external-attacher // and external-provisioner that we are using here. It happens to work in practice... diff --git a/test/e2e/storage/utils/deployment.go b/test/e2e/storage/utils/deployment.go index 067e8cd20f4..c8161f7f057 100644 --- a/test/e2e/storage/utils/deployment.go +++ b/test/e2e/storage/utils/deployment.go @@ -131,7 +131,9 @@ func PatchCSIDeployment(f *framework.Framework, o PatchCSIOptions, object interf if o.CanAttach != nil { object.Spec.AttachRequired = o.CanAttach } - object.Spec.VolumeLifecycleModes = o.VolumeLifecycleModes + if o.VolumeLifecycleModes != nil { + object.Spec.VolumeLifecycleModes = *o.VolumeLifecycleModes + } } return nil @@ -171,8 +173,8 @@ type PatchCSIOptions struct { // field *if* the driver deploys a CSIDriver object. Ignored // otherwise. CanAttach *bool - // The value to use for the CSIDriver.Spec.VolumeLifecycleModes + // If not nil, the value to use for the CSIDriver.Spec.VolumeLifecycleModes // field *if* the driver deploys a CSIDriver object. Ignored // otherwise. - VolumeLifecycleModes []storagev1beta1.VolumeLifecycleMode + VolumeLifecycleModes *[]storagev1beta1.VolumeLifecycleMode } diff --git a/test/e2e/testing-manifests/storage-csi/hostpath/hostpath/csi-hostpath-driverinfo.yaml b/test/e2e/testing-manifests/storage-csi/hostpath/hostpath/csi-hostpath-driverinfo.yaml new file mode 100644 index 00000000000..b4371003b34 --- /dev/null +++ b/test/e2e/testing-manifests/storage-csi/hostpath/hostpath/csi-hostpath-driverinfo.yaml @@ -0,0 +1,10 @@ +apiVersion: storage.k8s.io/v1beta1 +kind: CSIDriver +metadata: + name: hostpath.csi.k8s.io +spec: + # Supports both modes, but needs pod info for that to determine the actual mode. + podInfoOnMount: true + volumeLifecycleModes: + - Persistent + - Ephemeral