Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: use env var for smb server configuration #773

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions test/e2e/dynamic_provisioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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-",
Expand Down Expand Up @@ -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-",
Expand Down
95 changes: 57 additions & 38 deletions test/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
)

Expand All @@ -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{
Expand All @@ -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("../..")
Expand Down Expand Up @@ -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
}
5 changes: 4 additions & 1 deletion test/utils/check_driver_pods_restart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down
Loading