Skip to content

Commit f9f79bd

Browse files
committed
test: add e2e test "dynamically_provisioned_reclaim_policy_test"
Signed-off-by: ZeroMagic <[email protected]>
1 parent 98a0274 commit f9f79bd

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

test/e2e/dynamic_provisioning.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,37 @@ var _ = Describe("Dynamic Provisioning", func() {
160160
}
161161
test.Run(cs, ns)
162162
})
163+
164+
It(fmt.Sprintf("should delete PV with reclaimPolicy %q", v1.PersistentVolumeReclaimDelete), func() {
165+
reclaimPolicy := v1.PersistentVolumeReclaimDelete
166+
volumes := []testsuites.VolumeDetails{
167+
{
168+
FSType: "ext4",
169+
ClaimSize: "10Gi",
170+
ReclaimPolicy: &reclaimPolicy,
171+
},
172+
}
173+
test := testsuites.DynamicallyProvisionedReclaimPolicyTest{
174+
CSIDriver: testDriver,
175+
Volumes: volumes,
176+
}
177+
test.Run(cs, ns)
178+
})
179+
180+
It(fmt.Sprintf("[env] should retain PV with reclaimPolicy %q", v1.PersistentVolumeReclaimRetain), func() {
181+
reclaimPolicy := v1.PersistentVolumeReclaimRetain
182+
volumes := []testsuites.VolumeDetails{
183+
{
184+
FSType: "ext4",
185+
ClaimSize: "10Gi",
186+
ReclaimPolicy: &reclaimPolicy,
187+
},
188+
}
189+
test := testsuites.DynamicallyProvisionedReclaimPolicyTest{
190+
CSIDriver: testDriver,
191+
Volumes: volumes,
192+
Blobfuse: blobfuseDriver,
193+
}
194+
test.Run(cs, ns)
195+
})
163196
})
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Copyright 2019 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/csi-driver/blobfuse-csi-driver/pkg/blobfuse"
21+
"github.com/csi-driver/blobfuse-csi-driver/test/e2e/driver"
22+
23+
"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+
Blobfuse *blobfuse.Driver
33+
}
34+
35+
func (t *DynamicallyProvisionedReclaimPolicyTest) Run(client clientset.Interface, namespace *v1.Namespace) {
36+
for _, volume := range t.Volumes {
37+
tpvc, _ := volume.SetupDynamicPersistentVolumeClaim(client, namespace, t.CSIDriver)
38+
39+
// will delete the PVC
40+
// will also wait for PV to be deleted when reclaimPolicy=Delete
41+
tpvc.Cleanup()
42+
// first check PV stills exists, then manually delete it
43+
if tpvc.ReclaimPolicy() == v1.PersistentVolumeReclaimRetain {
44+
tpvc.WaitForPersistentVolumePhase(v1.VolumeReleased)
45+
tpvc.DeleteBoundPersistentVolume()
46+
tpvc.DeleteBackingVolume(t.Blobfuse)
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)