Skip to content

Commit

Permalink
test: add on-prem support e2e test
Browse files Browse the repository at this point in the history
fix create secret issue
  • Loading branch information
andyzhangx committed May 31, 2021
1 parent 6ff633b commit c92b050
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 4 deletions.
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,13 @@ clean:
.PHONY: create-metrics-svc
create-metrics-svc:
kubectl create -f deploy/example/metrics/csi-azurefile-controller-svc.yaml

.PHONY: install-smb-provisioner
install-smb-provisioner:
kubectl delete secret smbcreds --ignore-not-found
kubectl create secret generic smbcreds --from-literal azurestorageaccountname=USERNAME --from-literal azurestorageaccountkey="PASSWORD"
ifdef TEST_WINDOWS
kubectl apply -f deploy/example/smb-provisioner/smb-server-lb.yaml
else
kubectl apply -f deploy/example/smb-provisioner/smb-server.yaml
endif
59 changes: 59 additions & 0 deletions deploy/example/smb-provisioner/smb-server-lb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
kind: Service
apiVersion: v1
metadata:
name: smb-server
labels:
app: smb-server
spec:
type: LoadBalancer
selector:
app: smb-server
ports:
- port: 445
name: smb-server
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: smb-server
spec:
replicas: 1
selector:
matchLabels:
app: smb-server
template:
metadata:
name: smb-server
labels:
app: smb-server
spec:
nodeSelector:
"kubernetes.io/os": linux
containers:
- name: smb-server
image: andyzhangx/samba:win-fix
env:
- name: PERMISSIONS
value: "0777"
- name: USERNAME
valueFrom:
secretKeyRef:
name: smbcreds
key: azurestorageaccountname
- name: PASSWORD
valueFrom:
secretKeyRef:
name: smbcreds
key: azurestorageaccountkey
args: ["-u", "$(USERNAME);$(PASSWORD)", "-s", "share;/smbshare/;yes;no;no;all;none", "-p"]
volumeMounts:
- mountPath: /smbshare
name: data-volume
ports:
- containerPort: 445
volumes:
- name: data-volume
hostPath:
path: /home/kubernetes/smbshare-volume # modify this to specify another path to store smb share data
type: DirectoryOrCreate
59 changes: 59 additions & 0 deletions deploy/example/smb-provisioner/smb-server.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
kind: Service
apiVersion: v1
metadata:
name: smb-server
labels:
app: smb-server
spec:
type: ClusterIP # use "LoadBalancer" to get a public ip
selector:
app: smb-server
ports:
- port: 445
name: smb-server
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: smb-server
spec:
replicas: 1
selector:
matchLabels:
app: smb-server
template:
metadata:
name: smb-server
labels:
app: smb-server
spec:
nodeSelector:
"kubernetes.io/os": linux
containers:
- name: smb-server
image: andyzhangx/samba:win-fix
env:
- name: PERMISSIONS
value: "0777"
- name: USERNAME
valueFrom:
secretKeyRef:
name: smbcreds
key: azurestorageaccountname
- name: PASSWORD
valueFrom:
secretKeyRef:
name: smbcreds
key: azurestorageaccountkey
args: ["-u", "$(USERNAME);$(PASSWORD)", "-s", "share;/smbshare/;yes;no;no;all;none", "-p"]
volumeMounts:
- mountPath: /smbshare
name: data-volume
ports:
- containerPort: 445
volumes:
- name: data-volume
hostPath:
path: /home/kubernetes/smbshare-volume # modify this to specify another path to store smb share data
type: DirectoryOrCreate
48 changes: 48 additions & 0 deletions test/e2e/dynamic_provisioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,54 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
test.Run(cs, ns)
})

ginkgo.It("should mount on-prem smb server [file.csi.azure.com]", func() {
skipIfUsingInTreeVolumePlugin()
skipIfTestingInWindowsCluster()

createSecretScript := fmt.Sprintf(`kubectl create secret -n %s generic smbcreds --from-literal azurestorageaccountname=USERNAME --from-literal azurestorageaccountkey="PASSWORD"`, ns.Name)
log.Printf("run script: %s\n", createSecretScript)
cmd := exec.Command(createSecretScript)
output, err := cmd.CombinedOutput()
log.Printf("got output: %v, error: %v\n", string(output), err)
gomega.Expect(err).NotTo(gomega.HaveOccurred())

pods := []testsuites.PodDetails{
{
Cmd: convertToPowershellCommandIfNecessary("echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data"),
Volumes: []testsuites.VolumeDetails{
{
ClaimSize: "10Gi",
MountOptions: []string{
"dir_mode=0777",
"file_mode=0777",
"uid=0",
"gid=0",
"mfsymlinks",
"cache=strict",
"nosharesock",
},
VolumeMount: testsuites.VolumeMountDetails{
NameGenerate: "test-volume-",
MountPathGenerate: "/mnt/test-",
},
},
},
IsWindows: isWindowsCluster,
},
}

test := testsuites.DynamicallyProvisionedInlineVolumeTest{
CSIDriver: testDriver,
Pods: pods,
SecretName: "smbcreds",
ShareName: "share",
ReadOnly: false,
CSIInlineVolume: true,
Server: "//smb-server.default.svc.cluster.local",
}
test.Run(cs, ns)
})

ginkgo.It("should create a NFS volume on demand with mount options [file.csi.azure.com] [nfs]", func() {
skipIfTestingInWindowsCluster()
skipIfUsingInTreeVolumePlugin()
Expand Down
11 changes: 11 additions & 0 deletions test/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ var _ = ginkgo.BeforeSuite(func() {
}
execTestCmd([]testCmd{e2eBootstrap, createMetricsSVC})

if !isTestingMigration {
// Install SMB provisioner on cluster
installSMBProvisioner := testCmd{
command: "make",
args: []string{"install-smb-provisioner"},
startLog: "Installing SMB provisioner...",
endLog: "SMB provisioner installed",
}
execTestCmd([]testCmd{installSMBProvisioner})
}

nodeid := os.Getenv("nodeid")
kubeconfig := os.Getenv(kubeconfigEnvVar)
azurefileDriver = azurefile.NewDriver(nodeid)
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/testsuites/dynamically_provisioned_inline_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type DynamicallyProvisionedInlineVolumeTest struct {
Pods []PodDetails
SecretName string
ShareName string
Server string
ReadOnly bool
CSIInlineVolume bool
}
Expand All @@ -41,7 +42,7 @@ func (t *DynamicallyProvisionedInlineVolumeTest) Run(client clientset.Interface,
var tpod *TestPod
var cleanup []func()
if t.CSIInlineVolume {
tpod, cleanup = pod.SetupWithCSIInlineVolumes(client, namespace, t.CSIDriver, t.SecretName, t.ShareName, t.ReadOnly)
tpod, cleanup = pod.SetupWithCSIInlineVolumes(client, namespace, t.CSIDriver, t.SecretName, t.ShareName, t.Server, t.ReadOnly)
} else {
tpod, cleanup = pod.SetupWithInlineVolumes(client, namespace, t.CSIDriver, t.SecretName, t.ShareName, t.ReadOnly)
}
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/testsuites/specs.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ func (pod *PodDetails) SetupWithInlineVolumes(client clientset.Interface, namesp
return tpod, cleanupFuncs
}

func (pod *PodDetails) SetupWithCSIInlineVolumes(client clientset.Interface, namespace *v1.Namespace, csiDriver driver.DynamicPVTestDriver, secretName, shareName string, readOnly bool) (*TestPod, []func()) {
func (pod *PodDetails) SetupWithCSIInlineVolumes(client clientset.Interface, namespace *v1.Namespace, csiDriver driver.DynamicPVTestDriver, secretName, shareName, server string, readOnly bool) (*TestPod, []func()) {
tpod := NewTestPod(client, namespace, pod.Cmd, pod.IsWindows)
cleanupFuncs := make([]func(), 0)
for n, v := range pod.Volumes {
tpod.SetupCSIInlineVolume(fmt.Sprintf("%s%d", v.VolumeMount.NameGenerate, n+1), fmt.Sprintf("%s%d", v.VolumeMount.MountPathGenerate, n+1), secretName, shareName, readOnly)
tpod.SetupCSIInlineVolume(fmt.Sprintf("%s%d", v.VolumeMount.NameGenerate, n+1), fmt.Sprintf("%s%d", v.VolumeMount.MountPathGenerate, n+1), secretName, shareName, server, readOnly)
}
return tpod, cleanupFuncs
}
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/testsuites/testsuites.go
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ func (t *TestPod) SetupInlineVolume(name, mountPath, secretName, shareName strin
t.pod.Spec.Volumes = append(t.pod.Spec.Volumes, volume)
}

func (t *TestPod) SetupCSIInlineVolume(name, mountPath, secretName, shareName string, readOnly bool) {
func (t *TestPod) SetupCSIInlineVolume(name, mountPath, secretName, shareName, server string, readOnly bool) {
volumeMount := v1.VolumeMount{
Name: name,
MountPath: mountPath,
Expand All @@ -821,6 +821,7 @@ func (t *TestPod) SetupCSIInlineVolume(name, mountPath, secretName, shareName st
"secretName": secretName,
"secretNamespace": "default",
"shareName": shareName,
"server": server,
},
ReadOnly: to.BoolPtr(readOnly),
},
Expand Down

0 comments on commit c92b050

Please # to comment.