From 6e93edeb6bd92e593c3c786a93e05f39d29d3696 Mon Sep 17 00:00:00 2001 From: Penghao Date: Tue, 7 May 2024 08:42:23 +0800 Subject: [PATCH] test: use env var for smb server configuration --- test/e2e/dynamic_provisioning_test.go | 8 +++ test/e2e/suite_test.go | 95 +++++++++++++++---------- test/utils/check_driver_pods_restart.sh | 5 +- 3 files changed, 69 insertions(+), 39 deletions(-) diff --git a/test/e2e/dynamic_provisioning_test.go b/test/e2e/dynamic_provisioning_test.go index 33dff2e2b66..3ba5bd6ec7e 100644 --- a/test/e2e/dynamic_provisioning_test.go +++ b/test/e2e/dynamic_provisioning_test.go @@ -61,6 +61,10 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() { Volumes: []testsuites.VolumeDetails{ { ClaimSize: "10Gi", + MountOptions: []string{ + "dir_mode=0777", + "file_mode=0777", + }, VolumeMount: testsuites.VolumeMountDetails{ NameGenerate: "test-volume-", MountPathGenerate: "/mnt/test-", @@ -203,6 +207,10 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() { Volumes: []testsuites.VolumeDetails{ { ClaimSize: "10Gi", + MountOptions: []string{ + "dir_mode=0777", + "file_mode=0777", + }, VolumeMount: testsuites.VolumeMountDetails{ NameGenerate: "test-volume-", MountPathGenerate: "/mnt/test-", diff --git a/test/e2e/suite_test.go b/test/e2e/suite_test.go index 6daf79ff432..32a66fe0ddb 100644 --- a/test/e2e/suite_test.go +++ b/test/e2e/suite_test.go @@ -38,59 +38,65 @@ import ( ) const ( - kubeconfigEnvVar = "KUBECONFIG" - reportDirEnv = "ARTIFACTS" - testWindowsEnvVar = "TEST_WINDOWS" - defaultReportDir = "test/e2e" + kubeconfigEnvVar = "KUBECONFIG" + reportDirEnv = "ARTIFACTS" + testWindowsEnvVar = "TEST_WINDOWS" + defaultReportDir = "test/e2e" + testSmbSourceEnvVar = "TEST_SMB_SOURCE" + testSmbSecretNameEnvVar = "TEST_SMB_SECRET_NAME" + testSmbSecretNamespaceEnvVar = "TEST_SMB_SECRET_NAMESPACE" + defaultSmbSource = "//smb-server.default.svc.cluster.local/share" + defaultSmbSecretName = "smbcreds" + defaultSmbSecretNamespace = "default" ) var ( smbDriver *smb.Driver isWindowsCluster = os.Getenv(testWindowsEnvVar) != "" defaultStorageClassParameters = map[string]string{ - "source": "//smb-server.default.svc.cluster.local/share", - "csi.storage.k8s.io/provisioner-secret-name": "smbcreds", - "csi.storage.k8s.io/provisioner-secret-namespace": "default", - "csi.storage.k8s.io/node-stage-secret-name": "smbcreds", - "csi.storage.k8s.io/node-stage-secret-namespace": "default", + "source": getSmbTestEnvVarValue(testSmbSourceEnvVar, defaultSmbSource), + "csi.storage.k8s.io/provisioner-secret-name": getSmbTestEnvVarValue(testSmbSecretNameEnvVar, defaultSmbSecretName), + "csi.storage.k8s.io/provisioner-secret-namespace": getSmbTestEnvVarValue(testSmbSecretNamespaceEnvVar, defaultSmbSecretNamespace), + "csi.storage.k8s.io/node-stage-secret-name": getSmbTestEnvVarValue(testSmbSecretNameEnvVar, defaultSmbSecretName), + "csi.storage.k8s.io/node-stage-secret-namespace": getSmbTestEnvVarValue(testSmbSecretNamespaceEnvVar, defaultSmbSecretNamespace), } subDirStorageClassParameters = map[string]string{ - "source": "//smb-server.default.svc.cluster.local/share", + "source": getSmbTestEnvVarValue(testSmbSourceEnvVar, defaultSmbSource), "subDir": "subDirectory-${pvc.metadata.name}", - "csi.storage.k8s.io/provisioner-secret-name": "smbcreds", - "csi.storage.k8s.io/provisioner-secret-namespace": "default", - "csi.storage.k8s.io/node-stage-secret-name": "smbcreds", - "csi.storage.k8s.io/node-stage-secret-namespace": "default", + "csi.storage.k8s.io/provisioner-secret-name": getSmbTestEnvVarValue(testSmbSecretNameEnvVar, defaultSmbSecretName), + "csi.storage.k8s.io/provisioner-secret-namespace": getSmbTestEnvVarValue(testSmbSecretNamespaceEnvVar, defaultSmbSecretNamespace), + "csi.storage.k8s.io/node-stage-secret-name": getSmbTestEnvVarValue(testSmbSecretNameEnvVar, defaultSmbSecretName), + "csi.storage.k8s.io/node-stage-secret-namespace": getSmbTestEnvVarValue(testSmbSecretNamespaceEnvVar, defaultSmbSecretNamespace), } retainStorageClassParameters = map[string]string{ - "source": "//smb-server.default.svc.cluster.local/share", - "csi.storage.k8s.io/provisioner-secret-name": "smbcreds", - "csi.storage.k8s.io/provisioner-secret-namespace": "default", - "csi.storage.k8s.io/node-stage-secret-name": "smbcreds", - "csi.storage.k8s.io/node-stage-secret-namespace": "default", + "source": getSmbTestEnvVarValue(testSmbSourceEnvVar, defaultSmbSource), + "csi.storage.k8s.io/provisioner-secret-name": getSmbTestEnvVarValue(testSmbSecretNameEnvVar, defaultSmbSecretName), + "csi.storage.k8s.io/provisioner-secret-namespace": getSmbTestEnvVarValue(testSmbSecretNamespaceEnvVar, defaultSmbSecretNamespace), + "csi.storage.k8s.io/node-stage-secret-name": getSmbTestEnvVarValue(testSmbSecretNameEnvVar, defaultSmbSecretName), + "csi.storage.k8s.io/node-stage-secret-namespace": getSmbTestEnvVarValue(testSmbSecretNamespaceEnvVar, defaultSmbSecretNamespace), "onDelete": "retain", } archiveStorageClassParameters = map[string]string{ - "source": "//smb-server.default.svc.cluster.local/share", - "csi.storage.k8s.io/provisioner-secret-name": "smbcreds", - "csi.storage.k8s.io/provisioner-secret-namespace": "default", - "csi.storage.k8s.io/node-stage-secret-name": "smbcreds", - "csi.storage.k8s.io/node-stage-secret-namespace": "default", + "source": getSmbTestEnvVarValue(testSmbSourceEnvVar, defaultSmbSource), + "csi.storage.k8s.io/provisioner-secret-name": getSmbTestEnvVarValue(testSmbSecretNameEnvVar, defaultSmbSecretName), + "csi.storage.k8s.io/provisioner-secret-namespace": getSmbTestEnvVarValue(testSmbSecretNamespaceEnvVar, defaultSmbSecretNamespace), + "csi.storage.k8s.io/node-stage-secret-name": getSmbTestEnvVarValue(testSmbSecretNameEnvVar, defaultSmbSecretName), + "csi.storage.k8s.io/node-stage-secret-namespace": getSmbTestEnvVarValue(testSmbSecretNamespaceEnvVar, defaultSmbSecretNamespace), "onDelete": "archive", } archiveSubDirStorageClassParameters = map[string]string{ - "source": "//smb-server.default.svc.cluster.local/share", + "source": getSmbTestEnvVarValue(testSmbSourceEnvVar, defaultSmbSource), "subDir": "${pvc.metadata.namespace}/${pvc.metadata.name}", - "csi.storage.k8s.io/provisioner-secret-name": "smbcreds", - "csi.storage.k8s.io/provisioner-secret-namespace": "default", - "csi.storage.k8s.io/node-stage-secret-name": "smbcreds", - "csi.storage.k8s.io/node-stage-secret-namespace": "default", + "csi.storage.k8s.io/provisioner-secret-name": getSmbTestEnvVarValue(testSmbSecretNameEnvVar, defaultSmbSecretName), + "csi.storage.k8s.io/provisioner-secret-namespace": getSmbTestEnvVarValue(testSmbSecretNamespaceEnvVar, defaultSmbSecretNamespace), + "csi.storage.k8s.io/node-stage-secret-name": getSmbTestEnvVarValue(testSmbSecretNameEnvVar, defaultSmbSecretName), + "csi.storage.k8s.io/node-stage-secret-namespace": getSmbTestEnvVarValue(testSmbSecretNamespaceEnvVar, defaultSmbSecretNamespace), "onDelete": "archive", } noProvisionerSecretStorageClassParameters = map[string]string{ - "source": "//smb-server.default.svc.cluster.local/share", - "csi.storage.k8s.io/node-stage-secret-name": "smbcreds", - "csi.storage.k8s.io/node-stage-secret-namespace": "default", + "source": getSmbTestEnvVarValue(testSmbSourceEnvVar, defaultSmbSource), + "csi.storage.k8s.io/node-stage-secret-name": getSmbTestEnvVarValue(testSmbSecretNameEnvVar, defaultSmbSecretName), + "csi.storage.k8s.io/node-stage-secret-namespace": getSmbTestEnvVarValue(testSmbSecretNamespaceEnvVar, defaultSmbSecretNamespace), } ) @@ -111,6 +117,11 @@ var _ = ginkgo.BeforeSuite(func() { handleFlags() framework.AfterReadingAllFlags(&framework.TestContext) + kubeconfig := os.Getenv(kubeconfigEnvVar) + options := smb.DriverOptions{ + DriverName: smb.DefaultDriverName, + } + if testutil.IsRunningInProw() { // Install SMB provisioner on cluster installSMBProvisioner := testCmd{ @@ -137,17 +148,16 @@ var _ = ginkgo.BeforeSuite(func() { execTestCmd([]testCmd{installSMBProvisioner, e2eBootstrap, createMetricsSVC}) nodeid := os.Getenv("nodeid") - kubeconfig := os.Getenv(kubeconfigEnvVar) - options := smb.DriverOptions{ + options = smb.DriverOptions{ NodeID: nodeid, DriverName: smb.DefaultDriverName, EnableGetVolumeStats: false, } - smbDriver = smb.NewDriver(&options) - go func() { - smbDriver.Run(fmt.Sprintf("unix:///tmp/csi-%s.sock", uuid.NewUUID().String()), kubeconfig, false) - }() } + smbDriver = smb.NewDriver(&options) + go func() { + smbDriver.Run(fmt.Sprintf("unix:///tmp/csi-%s.sock", uuid.NewUUID().String()), kubeconfig, false) + }() if isWindowsCluster { err := os.Chdir("../..") @@ -270,3 +280,12 @@ func skipIfTestingInWindowsCluster() { ginkgo.Skip("test case not supported by Windows clusters") } } + +// getSmbTestEnvVarValue gets the smbTestEnvValue from env var if the var does not set use the defaultVarValue +func getSmbTestEnvVarValue(envVarName string, defaultVarValue string) (smbTestEnvValue string) { + smbTestEnvValue = os.Getenv(envVarName) + if smbTestEnvValue == "" { + smbTestEnvValue = defaultVarValue + } + return +} diff --git a/test/utils/check_driver_pods_restart.sh b/test/utils/check_driver_pods_restart.sh index be8da1f779e..27682bcc445 100644 --- a/test/utils/check_driver_pods_restart.sh +++ b/test/utils/check_driver_pods_restart.sh @@ -16,8 +16,11 @@ set -e +# Get the value of the environment variable or set a default value if it's empty +CSI_DRIVER_INSTALLED_NAMESPACE="${CSI_DRIVER_INSTALLED_NAMESPACE:-kube-system}" + echo "check the driver pods if restarts ..." -restarts=$(kubectl get pods -n kube-system | grep smb | awk '{print $4}') +restarts=$(kubectl get pods -n "${CSI_DRIVER_INSTALLED_NAMESPACE}" | grep smb | awk '{print $4}') for num in $restarts do if [ "$num" -ne "0" ]