add subPath e2e test
This commit is contained in:
parent
0e56559fce
commit
3a9b724316
@ -234,6 +234,29 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
|
|||||||
}
|
}
|
||||||
test.Run(cs, ns)
|
test.Run(cs, ns)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ginkgo.It("should create a pod with volume mount subpath [nfs.csi.k8s.io]", func() {
|
||||||
|
pods := []testsuites.PodDetails{
|
||||||
|
{
|
||||||
|
Cmd: convertToPowershellCommandIfNecessary("echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data"),
|
||||||
|
Volumes: []testsuites.VolumeDetails{
|
||||||
|
{
|
||||||
|
ClaimSize: "10Gi",
|
||||||
|
VolumeMount: testsuites.VolumeMountDetails{
|
||||||
|
NameGenerate: "test-volume-",
|
||||||
|
MountPathGenerate: "/mnt/test-",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
test := testsuites.DynamicallyProvisionedVolumeSubpathTester{
|
||||||
|
CSIDriver: testDriver,
|
||||||
|
Pods: pods,
|
||||||
|
StorageClassParameters: defaultStorageClassParameters,
|
||||||
|
}
|
||||||
|
test.Run(cs, ns)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
func restClient(group string, version string) (restclientset.Interface, error) {
|
func restClient(group string, version string) (restclientset.Interface, error) {
|
||||||
|
|||||||
@ -36,12 +36,14 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
kubeconfigEnvVar = "KUBECONFIG"
|
kubeconfigEnvVar = "KUBECONFIG"
|
||||||
|
testWindowsEnvVar = "TEST_WINDOWS"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
nodeID = os.Getenv("NODE_ID")
|
nodeID = os.Getenv("NODE_ID")
|
||||||
perm *uint32
|
perm *uint32
|
||||||
nfsDriver *nfs.Driver
|
nfsDriver *nfs.Driver
|
||||||
|
isWindowsCluster = os.Getenv(testWindowsEnvVar) != ""
|
||||||
defaultStorageClassParameters = map[string]string{
|
defaultStorageClassParameters = map[string]string{
|
||||||
"server": "nfs-server.default.svc.cluster.local",
|
"server": "nfs-server.default.svc.cluster.local",
|
||||||
"share": "/",
|
"share": "/",
|
||||||
@ -168,3 +170,24 @@ func TestE2E(t *testing.T) {
|
|||||||
gomega.RegisterFailHandler(ginkgo.Fail)
|
gomega.RegisterFailHandler(ginkgo.Fail)
|
||||||
ginkgo.RunSpecs(t, "E2E Suite")
|
ginkgo.RunSpecs(t, "E2E Suite")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func convertToPowershellCommandIfNecessary(command string) string {
|
||||||
|
if !isWindowsCluster {
|
||||||
|
return command
|
||||||
|
}
|
||||||
|
|
||||||
|
switch command {
|
||||||
|
case "echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data":
|
||||||
|
return "echo 'hello world' | Out-File -FilePath C:\\mnt\\test-1\\data.txt; Get-Content C:\\mnt\\test-1\\data.txt | findstr 'hello world'"
|
||||||
|
case "touch /mnt/test-1/data":
|
||||||
|
return "echo $null >> C:\\mnt\\test-1\\data"
|
||||||
|
case "while true; do echo $(date -u) >> /mnt/test-1/data; sleep 100; done":
|
||||||
|
return "while (1) { Add-Content -Encoding Unicode C:\\mnt\\test-1\\data.txt $(Get-Date -Format u); sleep 1 }"
|
||||||
|
case "echo 'hello world' >> /mnt/test-1/data && while true; do sleep 100; done":
|
||||||
|
return "Add-Content -Encoding Unicode C:\\mnt\\test-1\\data.txt 'hello world'; while (1) { sleep 1 }"
|
||||||
|
case "echo 'hello world' >> /mnt/test-1/data && while true; do sleep 3600; done":
|
||||||
|
return "Add-Content -Encoding Unicode C:\\mnt\\test-1\\data.txt 'hello world'; while (1) { sleep 1 }"
|
||||||
|
}
|
||||||
|
|
||||||
|
return command
|
||||||
|
}
|
||||||
|
|||||||
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2021 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package testsuites
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/kubernetes-csi/csi-driver-nfs/test/e2e/driver"
|
||||||
|
|
||||||
|
"github.com/onsi/ginkgo"
|
||||||
|
v1 "k8s.io/api/core/v1"
|
||||||
|
clientset "k8s.io/client-go/kubernetes"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DynamicallyProvisionedCmdVolumeTest will provision required StorageClass(es), PVC(s) and Pod(s)
|
||||||
|
// Waiting for the PV provisioner to create a new PV
|
||||||
|
// Testing if the Pod(s) Cmd is run with a 0 exit code
|
||||||
|
type DynamicallyProvisionedVolumeSubpathTester struct {
|
||||||
|
CSIDriver driver.DynamicPVTestDriver
|
||||||
|
Pods []PodDetails
|
||||||
|
StorageClassParameters map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *DynamicallyProvisionedVolumeSubpathTester) Run(client clientset.Interface, namespace *v1.Namespace) {
|
||||||
|
for _, pod := range t.Pods {
|
||||||
|
tpod, cleanup := pod.SetupWithDynamicVolumesWithSubpath(client, namespace, t.CSIDriver, t.StorageClassParameters)
|
||||||
|
// defer must be called here for resources not get removed before using them
|
||||||
|
for i := range cleanup {
|
||||||
|
defer cleanup[i]()
|
||||||
|
}
|
||||||
|
|
||||||
|
ginkgo.By("deploying the pod")
|
||||||
|
tpod.Create()
|
||||||
|
defer tpod.Cleanup()
|
||||||
|
ginkgo.By("checking that the pods command exits with no error")
|
||||||
|
tpod.WaitForSuccess()
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -159,3 +159,14 @@ func (pod *PodDetails) SetupWithDynamicMultipleVolumes(client clientset.Interfac
|
|||||||
}
|
}
|
||||||
return tpod, cleanupFuncs
|
return tpod, cleanupFuncs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (pod *PodDetails) SetupWithDynamicVolumesWithSubpath(client clientset.Interface, namespace *v1.Namespace, csiDriver driver.DynamicPVTestDriver, storageClassParameters map[string]string) (*TestPod, []func()) {
|
||||||
|
tpod := NewTestPod(client, namespace, pod.Cmd)
|
||||||
|
cleanupFuncs := make([]func(), 0)
|
||||||
|
for n, v := range pod.Volumes {
|
||||||
|
tpvc, funcs := v.SetupDynamicPersistentVolumeClaim(client, namespace, csiDriver, storageClassParameters)
|
||||||
|
cleanupFuncs = append(cleanupFuncs, funcs...)
|
||||||
|
tpod.SetupVolumeMountWithSubpath(tpvc.persistentVolumeClaim, fmt.Sprintf("%s%d", v.VolumeMount.NameGenerate, n+1), fmt.Sprintf("%s%d", v.VolumeMount.MountPathGenerate, n+1), "testSubpath", v.VolumeMount.ReadOnly)
|
||||||
|
}
|
||||||
|
return tpod, cleanupFuncs
|
||||||
|
}
|
||||||
|
|||||||
@ -573,3 +573,25 @@ func (t *TestPersistentVolumeClaim) DeleteBackingVolume(cs *nfs.ControllerServer
|
|||||||
ginkgo.Fail(fmt.Sprintf("could not delete volume %q: %v", volumeID, err))
|
ginkgo.Fail(fmt.Sprintf("could not delete volume %q: %v", volumeID, err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *TestPod) SetupVolumeMountWithSubpath(pvc *v1.PersistentVolumeClaim, name, mountPath string, subpath string, readOnly bool) {
|
||||||
|
volumeMount := v1.VolumeMount{
|
||||||
|
Name: name,
|
||||||
|
MountPath: mountPath,
|
||||||
|
SubPath: subpath,
|
||||||
|
ReadOnly: readOnly,
|
||||||
|
}
|
||||||
|
|
||||||
|
t.pod.Spec.Containers[0].VolumeMounts = append(t.pod.Spec.Containers[0].VolumeMounts, volumeMount)
|
||||||
|
|
||||||
|
volume := v1.Volume{
|
||||||
|
Name: name,
|
||||||
|
VolumeSource: v1.VolumeSource{
|
||||||
|
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{
|
||||||
|
ClaimName: pvc.Name,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
t.pod.Spec.Volumes = append(t.pod.Spec.Volumes, volume)
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user