Skip to content

Commit 0018ccf

Browse files
authored
Merge pull request #55 from ZeroMagic/pre_provisioned_reclaim_policy
test: add e2e test "pre_provisioned_reclaim_policy"
2 parents 21610b6 + 8407c48 commit 0018ccf

File tree

3 files changed

+174
-1
lines changed

3 files changed

+174
-1
lines changed

test/e2e/pre_provisioning.go

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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 e2e
18+
19+
import (
20+
"context"
21+
"fmt"
22+
"os"
23+
24+
"github.com/container-storage-interface/spec/lib/go/csi"
25+
"github.com/csi-driver/blobfuse-csi-driver/pkg/blobfuse"
26+
"github.com/csi-driver/blobfuse-csi-driver/test/e2e/driver"
27+
"github.com/csi-driver/blobfuse-csi-driver/test/e2e/testsuites"
28+
. "github.com/onsi/ginkgo"
29+
30+
v1 "k8s.io/api/core/v1"
31+
clientset "k8s.io/client-go/kubernetes"
32+
"k8s.io/kubernetes/test/e2e/framework"
33+
)
34+
35+
const (
36+
defaultVolumeSize = 10
37+
)
38+
39+
var (
40+
defaultVolumeSizeBytes int64 = defaultVolumeSize * 1024 * 1024 * 1024
41+
)
42+
43+
var _ = Describe("[blobfuse-csi-e2e] [single-az] Pre-Provisioned", func() {
44+
f := framework.NewDefaultFramework("blobfuse")
45+
46+
var (
47+
cs clientset.Interface
48+
ns *v1.Namespace
49+
testDriver driver.PreProvisionedVolumeTestDriver
50+
volumeID string
51+
// Set to true if the volume should be deleted automatically after test
52+
skipManuallyDeletingVolume bool
53+
)
54+
nodeid := os.Getenv("nodeid")
55+
blobfuseDriver := blobfuse.NewDriver(nodeid)
56+
endpoint := "unix:///tmp/csi.sock"
57+
58+
go func() {
59+
blobfuseDriver.Run(endpoint)
60+
}()
61+
62+
BeforeEach(func() {
63+
cs = f.ClientSet
64+
ns = f.Namespace
65+
testDriver = driver.InitBlobFuseCSIDriver()
66+
})
67+
68+
AfterEach(func() {
69+
if !skipManuallyDeletingVolume {
70+
req := &csi.DeleteVolumeRequest{
71+
VolumeId: volumeID,
72+
}
73+
_, err := blobfuseDriver.DeleteVolume(context.Background(), req)
74+
if err != nil {
75+
Fail(fmt.Sprintf("create volume %q error: %v", volumeID, err))
76+
}
77+
}
78+
})
79+
80+
It(fmt.Sprintf("[env] should use a pre-provisioned volume and retain PV with reclaimPolicy %q", v1.PersistentVolumeReclaimRetain), func() {
81+
req := makeCreateVolumeReq("pre-provisioned-retain-reclaimPolicy")
82+
resp, err := blobfuseDriver.CreateVolume(context.Background(), req)
83+
if err != nil {
84+
Fail(fmt.Sprintf("create volume error: %v", err))
85+
}
86+
volumeID = resp.Volume.VolumeId
87+
By(fmt.Sprintf("Successfully provisioned BlobFuse volume: %q\n", volumeID))
88+
89+
volumeSize := fmt.Sprintf("%dGi", defaultVolumeSize)
90+
reclaimPolicy := v1.PersistentVolumeReclaimRetain
91+
volumes := []testsuites.VolumeDetails{
92+
{
93+
VolumeID: volumeID,
94+
FSType: "ext4",
95+
ClaimSize: volumeSize,
96+
ReclaimPolicy: &reclaimPolicy,
97+
},
98+
}
99+
test := testsuites.PreProvisionedReclaimPolicyTest{
100+
CSIDriver: testDriver,
101+
Volumes: volumes,
102+
}
103+
test.Run(cs, ns)
104+
})
105+
})
106+
107+
func makeCreateVolumeReq(volumeName string) *csi.CreateVolumeRequest {
108+
req := &csi.CreateVolumeRequest{
109+
Name: volumeName,
110+
VolumeCapabilities: []*csi.VolumeCapability{
111+
{
112+
AccessType: &csi.VolumeCapability_Mount{
113+
Mount: &csi.VolumeCapability_MountVolume{},
114+
},
115+
AccessMode: &csi.VolumeCapability_AccessMode{
116+
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
117+
},
118+
},
119+
},
120+
CapacityRange: &csi.CapacityRange{
121+
RequiredBytes: defaultVolumeSizeBytes,
122+
LimitBytes: defaultVolumeSizeBytes,
123+
},
124+
}
125+
126+
return req
127+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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/test/e2e/driver"
21+
22+
"k8s.io/api/core/v1"
23+
clientset "k8s.io/client-go/kubernetes"
24+
)
25+
26+
// PreProvisionedReclaimPolicyTest will provision required PV(s) and PVC(s)
27+
// Testing the correct behavior for different reclaimPolicies
28+
type PreProvisionedReclaimPolicyTest struct {
29+
CSIDriver driver.PreProvisionedVolumeTestDriver
30+
Volumes []VolumeDetails
31+
}
32+
33+
func (t *PreProvisionedReclaimPolicyTest) Run(client clientset.Interface, namespace *v1.Namespace) {
34+
for _, volume := range t.Volumes {
35+
tpvc, _ := volume.SetupPreProvisionedPersistentVolumeClaim(client, namespace, t.CSIDriver)
36+
37+
// will delete the PVC
38+
// will also wait for PV to be deleted when reclaimPolicy=Delete
39+
tpvc.Cleanup()
40+
// first check PV stills exists, then manually delete it
41+
if tpvc.ReclaimPolicy() == v1.PersistentVolumeReclaimRetain {
42+
tpvc.WaitForPersistentVolumePhase(v1.VolumeReleased)
43+
tpvc.DeleteBoundPersistentVolume()
44+
}
45+
}
46+
}

test/e2e/testsuites/testsuites.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ type TestDeployment struct {
366366
}
367367

368368
func NewTestDeployment(c clientset.Interface, ns *v1.Namespace, command string, pvc *v1.PersistentVolumeClaim, volumeName, mountPath string, readOnly bool) *TestDeployment {
369-
generateName := "ebs-volume-tester-"
369+
generateName := "blobfuse-volume-tester-"
370370
selectorValue := fmt.Sprintf("%s%d", generateName, rand.Int())
371371
replicas := int32(1)
372372
return &TestDeployment{

0 commit comments

Comments
 (0)