Skip to content

Commit c673e9d

Browse files
authored
Merge pull request #91 from andyzhangx/reclaim-policy-e2e-test
test: add reclaim policy e2e test
2 parents baa553a + 83c9a06 commit c673e9d

File tree

4 files changed

+178
-0
lines changed

4 files changed

+178
-0
lines changed

test/e2e/dynamic_provisioning_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,67 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
231231
}
232232
test.Run(cs, ns)
233233
})
234+
235+
ginkgo.It(fmt.Sprintf("should delete PV with reclaimPolicy %q [smb.csi.k8s.io] [Windows]", v1.PersistentVolumeReclaimDelete), func() {
236+
reclaimPolicy := v1.PersistentVolumeReclaimDelete
237+
volumes := []testsuites.VolumeDetails{
238+
{
239+
ClaimSize: "10Gi",
240+
ReclaimPolicy: &reclaimPolicy,
241+
},
242+
}
243+
test := testsuites.DynamicallyProvisionedReclaimPolicyTest{
244+
CSIDriver: testDriver,
245+
Volumes: volumes,
246+
StorageClassParameters: defaultStorageClassParameters,
247+
}
248+
test.Run(cs, ns)
249+
})
250+
251+
ginkgo.It(fmt.Sprintf("should retain PV with reclaimPolicy %q [smb.csi.k8s.io] [Windows]", v1.PersistentVolumeReclaimRetain), func() {
252+
reclaimPolicy := v1.PersistentVolumeReclaimRetain
253+
volumes := []testsuites.VolumeDetails{
254+
{
255+
ClaimSize: "10Gi",
256+
ReclaimPolicy: &reclaimPolicy,
257+
},
258+
}
259+
test := testsuites.DynamicallyProvisionedReclaimPolicyTest{
260+
CSIDriver: testDriver,
261+
Volumes: volumes,
262+
Driver: smbDriver,
263+
StorageClassParameters: defaultStorageClassParameters,
264+
}
265+
test.Run(cs, ns)
266+
})
267+
268+
ginkgo.It("should create a pod with multiple volumes [smb.csi.k8s.io] [Windows]", func() {
269+
volumes := []testsuites.VolumeDetails{}
270+
for i := 1; i <= 6; i++ {
271+
volume := testsuites.VolumeDetails{
272+
ClaimSize: "100Gi",
273+
VolumeMount: testsuites.VolumeMountDetails{
274+
NameGenerate: "test-volume-",
275+
MountPathGenerate: "/mnt/test-",
276+
},
277+
}
278+
volumes = append(volumes, volume)
279+
}
280+
281+
pods := []testsuites.PodDetails{
282+
{
283+
Cmd: convertToPowershellCommandIfNecessary("echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data"),
284+
Volumes: volumes,
285+
IsWindows: isWindowsCluster,
286+
},
287+
}
288+
test := testsuites.DynamicallyProvisionedPodWithMultiplePVsTest{
289+
CSIDriver: testDriver,
290+
Pods: pods,
291+
StorageClassParameters: storageClassCreateSubDir,
292+
}
293+
test.Run(cs, ns)
294+
})
234295
})
235296

236297
func restClient(group string, version string) (restclientset.Interface, error) {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package testsuites
18+
19+
import (
20+
"github.com/kubernetes-csi/csi-driver-smb/test/e2e/driver"
21+
22+
"github.com/onsi/ginkgo"
23+
v1 "k8s.io/api/core/v1"
24+
clientset "k8s.io/client-go/kubernetes"
25+
)
26+
27+
// DynamicallyProvisionedPodWithMultiplePVsTest will provision
28+
// one pod with multiple PVs
29+
// Waiting for the PV provisioner to create a new PV
30+
// Testing if the Pod(s) Cmd is run with a 0 exit code
31+
type DynamicallyProvisionedPodWithMultiplePVsTest struct {
32+
CSIDriver driver.DynamicPVTestDriver
33+
Pods []PodDetails
34+
StorageClassParameters map[string]string
35+
}
36+
37+
func (t *DynamicallyProvisionedPodWithMultiplePVsTest) Run(client clientset.Interface, namespace *v1.Namespace) {
38+
for _, pod := range t.Pods {
39+
tpod, cleanup := pod.SetupWithDynamicMultipleVolumes(client, namespace, t.CSIDriver, t.StorageClassParameters)
40+
// defer must be called here for resources not get removed before using them
41+
for i := range cleanup {
42+
defer cleanup[i]()
43+
}
44+
45+
ginkgo.By("deploying the pod")
46+
tpod.Create()
47+
defer tpod.Cleanup()
48+
ginkgo.By("checking that the pods command exits with no error")
49+
tpod.WaitForSuccess()
50+
}
51+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package testsuites
18+
19+
import (
20+
"github.com/kubernetes-csi/csi-driver-smb/pkg/smb"
21+
"github.com/kubernetes-csi/csi-driver-smb/test/e2e/driver"
22+
23+
v1 "k8s.io/api/core/v1"
24+
clientset "k8s.io/client-go/kubernetes"
25+
)
26+
27+
// DynamicallyProvisionedReclaimPolicyTest will provision required PV(s) and PVC(s)
28+
// Testing the correct behavior for different reclaimPolicies
29+
type DynamicallyProvisionedReclaimPolicyTest struct {
30+
CSIDriver driver.DynamicPVTestDriver
31+
Volumes []VolumeDetails
32+
Driver *smb.Driver
33+
StorageClassParameters map[string]string
34+
}
35+
36+
func (t *DynamicallyProvisionedReclaimPolicyTest) Run(client clientset.Interface, namespace *v1.Namespace) {
37+
for _, volume := range t.Volumes {
38+
tpvc, _ := volume.SetupDynamicPersistentVolumeClaim(client, namespace, t.CSIDriver, t.StorageClassParameters)
39+
40+
// will delete the PVC
41+
// will also wait for PV to be deleted when reclaimPolicy=Delete
42+
tpvc.Cleanup()
43+
// first check PV stills exists, then manually delete it
44+
if tpvc.ReclaimPolicy() == v1.PersistentVolumeReclaimRetain {
45+
tpvc.WaitForPersistentVolumePhase(v1.VolumeReleased)
46+
tpvc.DeleteBoundPersistentVolume()
47+
tpvc.DeleteBackingVolume(t.Driver)
48+
}
49+
}
50+
}

test/e2e/testsuites/specs.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,22 @@ func (pod *PodDetails) SetupWithDynamicVolumes(client clientset.Interface, names
102102
return tpod, cleanupFuncs
103103
}
104104

105+
// SetupWithDynamicMultipleVolumes each pod will be mounted with multiple volumes
106+
func (pod *PodDetails) SetupWithDynamicMultipleVolumes(client clientset.Interface, namespace *v1.Namespace, csiDriver driver.DynamicPVTestDriver, storageClassParameters map[string]string) (*TestPod, []func()) {
107+
tpod := NewTestPod(client, namespace, pod.Cmd, pod.IsWindows)
108+
cleanupFuncs := make([]func(), 0)
109+
for n, v := range pod.Volumes {
110+
tpvc, funcs := v.SetupDynamicPersistentVolumeClaim(client, namespace, csiDriver, storageClassParameters)
111+
cleanupFuncs = append(cleanupFuncs, funcs...)
112+
if v.VolumeMode == Block {
113+
tpod.SetupRawBlockVolume(tpvc.persistentVolumeClaim, fmt.Sprintf("%s%d", v.VolumeDevice.NameGenerate, n+1), v.VolumeDevice.DevicePath)
114+
} else {
115+
tpod.SetupVolume(tpvc.persistentVolumeClaim, fmt.Sprintf("%s%d", v.VolumeMount.NameGenerate, n+1), fmt.Sprintf("%s%d", v.VolumeMount.MountPathGenerate, n+1), v.VolumeMount.ReadOnly)
116+
}
117+
}
118+
return tpod, cleanupFuncs
119+
}
120+
105121
func (pod *PodDetails) SetupWithPreProvisionedVolumes(client clientset.Interface, namespace *v1.Namespace, csiDriver driver.PreProvisionedVolumeTestDriver) (*TestPod, []func()) {
106122
tpod := NewTestPod(client, namespace, pod.Cmd, pod.IsWindows)
107123
cleanupFuncs := make([]func(), 0)

0 commit comments

Comments
 (0)