Skip to content

Commit eb4db8b

Browse files
committed
test: add bring own key e2e test
1 parent 740639a commit eb4db8b

File tree

4 files changed

+81
-5
lines changed

4 files changed

+81
-5
lines changed

pkg/blob/controllerserver.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,13 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
164164
if err != nil {
165165
return nil, err
166166
}
167+
167168
blobClient := client.GetBlobService()
168169
container := blobClient.GetContainerReference(containerName)
169-
_, err = container.CreateIfNotExists(&azstorage.CreateContainerOptions{Access: azstorage.ContainerAccessTypePrivate})
170-
if err != nil {
170+
if _, err = container.CreateIfNotExists(&azstorage.CreateContainerOptions{Access: azstorage.ContainerAccessTypePrivate}); err != nil {
171171
return nil, fmt.Errorf("failed to create container(%s) on account(%s) type(%s) rg(%s) location(%s) size(%d), error: %v", containerName, accountName, storageAccountType, resourceGroup, location, requestGiB, err)
172172
}
173173

174-
volumeID := fmt.Sprintf(volumeIDTemplate, resourceGroup, accountName, containerName)
175-
klog.V(2).Infof("create container %s on storage account %s successfully", containerName, accountName)
176-
177174
if storeAccountKey != storeAccountKeyFalse && len(req.GetSecrets()) == 0 {
178175
secretName, err := setAzureCredentials(d.cloud.KubeClient, accountName, accountKey, secretNamespace)
179176
if err != nil {
@@ -184,6 +181,9 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
184181
}
185182
}
186183

184+
volumeID := fmt.Sprintf(volumeIDTemplate, resourceGroup, accountName, containerName)
185+
klog.V(2).Infof("create container %s on storage account %s successfully", containerName, accountName)
186+
187187
return &csi.CreateVolumeResponse{
188188
Volume: &csi.Volume{
189189
VolumeId: volumeID,

test/e2e/dynamic_provisioning_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,16 @@ package e2e
1818

1919
import (
2020
"fmt"
21+
"log"
22+
"os"
23+
"os/exec"
24+
"strings"
2125

2226
"sigs.k8s.io/blob-csi-driver/test/e2e/driver"
2327
"sigs.k8s.io/blob-csi-driver/test/e2e/testsuites"
2428

2529
"github.com/onsi/ginkgo"
30+
"github.com/onsi/gomega"
2631
v1 "k8s.io/api/core/v1"
2732
clientset "k8s.io/client-go/kubernetes"
2833
"k8s.io/kubernetes/test/e2e/framework"
@@ -260,4 +265,52 @@ var _ = ginkgo.Describe("[blob-csi-e2e] Dynamic Provisioning", func() {
260265
}
261266
test.Run(cs, ns)
262267
})
268+
269+
ginkgo.It("should create a volume on demand (Bring Your Own Key)", func() {
270+
// get storage account secret name
271+
err := os.Chdir("../..")
272+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
273+
defer func() {
274+
err := os.Chdir("test/e2e")
275+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
276+
}()
277+
278+
getSecretNameScript := "test/utils/get_storage_account_secret_name.sh"
279+
log.Printf("run script: %s\n", getSecretNameScript)
280+
281+
cmd := exec.Command("bash", getSecretNameScript)
282+
output, err := cmd.CombinedOutput()
283+
log.Printf("got output: %v, error: %v\n", string(output), err)
284+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
285+
286+
secretName := strings.TrimSuffix(string(output), "\n")
287+
log.Printf("got storage account secret name: %v\n", secretName)
288+
bringKeyStorageClassParameters["csi.storage.k8s.io/provisioner-secret-name"] = secretName
289+
bringKeyStorageClassParameters["csi.storage.k8s.io/node-stage-secret-name"] = secretName
290+
291+
pods := []testsuites.PodDetails{
292+
{
293+
Cmd: "echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data",
294+
Volumes: []testsuites.VolumeDetails{
295+
{
296+
ClaimSize: "10Gi",
297+
MountOptions: []string{
298+
"-o allow_other",
299+
"--file-cache-timeout-in-seconds=120",
300+
},
301+
VolumeMount: testsuites.VolumeMountDetails{
302+
NameGenerate: "test-volume-",
303+
MountPathGenerate: "/mnt/test-",
304+
},
305+
},
306+
},
307+
},
308+
}
309+
test := testsuites.DynamicallyProvisionedCmdVolumeTest{
310+
CSIDriver: testDriver,
311+
Pods: pods,
312+
StorageClassParameters: bringKeyStorageClassParameters,
313+
}
314+
test.Run(cs, ns)
315+
})
263316
})

test/e2e/suite_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ const (
4949

5050
var blobDriver *blob.Driver
5151

52+
var bringKeyStorageClassParameters = map[string]string{
53+
"csi.storage.k8s.io/provisioner-secret-namespace": "default",
54+
"csi.storage.k8s.io/node-stage-secret-namespace": "default",
55+
}
56+
5257
type testCmd struct {
5358
command string
5459
args []string
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2020 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
#!/bin/bash
16+
17+
set -e
18+
kubectl get secret | grep azure-storage-account | head -n 1 | awk '{print $1}'

0 commit comments

Comments
 (0)