|
| 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 | +} |
0 commit comments