Skip to content

Commit

Permalink
fix dynamic inline volume and byok volume
Browse files Browse the repository at this point in the history
  • Loading branch information
cvvz committed Mar 30, 2023
1 parent 0e4b11e commit f1f55e4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 74 deletions.
89 changes: 35 additions & 54 deletions test/e2e/dynamic_provisioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,12 @@ package e2e
import (
"context"
"fmt"
"log"
"os"
"os/exec"
"strings"
"time"

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

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/test/e2e/framework"
Expand Down Expand Up @@ -373,26 +368,28 @@ var _ = ginkgo.Describe("[blob-csi-e2e] Dynamic Provisioning", func() {
})

ginkgo.It("should create a volume on demand (Bring Your Own Key)", func() {
// get storage account secret name
err := os.Chdir("../..")
gomega.Expect(err).NotTo(gomega.HaveOccurred())
defer func() {
err := os.Chdir("test/e2e")
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}()

getSecretNameScript := "test/utils/get_storage_account_secret_name.sh"
log.Printf("run script: %s\n", getSecretNameScript)

cmd := exec.Command("bash", getSecretNameScript)
output, err := cmd.CombinedOutput()
log.Printf("got output: %v, error: %v\n", string(output), err)
gomega.Expect(err).NotTo(gomega.HaveOccurred())

secretName := strings.TrimSuffix(string(output), "\n")
log.Printf("got storage account secret name: %v\n", secretName)
// create a volume
volName := fmt.Sprintf("BYOK-%d", ginkgo.GinkgoParallelProcess())
resp, err := blobDriver.CreateVolume(context.Background(), makeCreateVolumeReq(volName, ns.Name))
framework.ExpectNoError(err, "create volume error")
volumeID := resp.Volume.VolumeId
// get accountname and key
accountName, accountKey, _, _, err := blobDriver.GetStorageAccountAndContainer(context.Background(), volumeID, nil, nil)
framework.ExpectNoError(err, fmt.Sprintf("Error GetStorageAccountAndContainer from volumeID(%s): %v", volumeID, err))
// create secret
secretName := "byok-secret"
secretData := map[string]string{
"azurestorageaccountname": accountName,
"azurestorageaccountkey": accountKey,
}
tsecret := testsuites.NewTestSecret(cs, ns, secretName, secretData)
tsecret.Create()
defer tsecret.Cleanup()

bringKeyStorageClassParameters["csi.storage.k8s.io/provisioner-secret-name"] = secretName
bringKeyStorageClassParameters["csi.storage.k8s.io/node-stage-secret-name"] = secretName
bringKeyStorageClassParameters["csi.storage.k8s.io/provisioner-secret-namespace"] = ns.Name
bringKeyStorageClassParameters["csi.storage.k8s.io/node-stage-secret-namespace"] = ns.Name

pods := []testsuites.PodDetails{
{
Expand Down Expand Up @@ -447,39 +444,23 @@ var _ = ginkgo.Describe("[blob-csi-e2e] Dynamic Provisioning", func() {
})

ginkgo.It("should create an CSI inline volume [blob.csi.azure.com]", func() {
// get storage account secret name
err := os.Chdir("../..")
gomega.Expect(err).NotTo(gomega.HaveOccurred())
defer func() {
err := os.Chdir("test/e2e")
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}()

getSecretNameScript := "test/utils/get_storage_account_secret_name.sh"
log.Printf("run script: %s\n", getSecretNameScript)

cmd := exec.Command("bash", getSecretNameScript)
output, err := cmd.CombinedOutput()
log.Printf("got output: %v, error: %v\n", string(output), err)
gomega.Expect(err).NotTo(gomega.HaveOccurred())

secretName := strings.TrimSuffix(string(output), "\n")
log.Printf("got storage account secret name: %v\n", secretName)
segments := strings.Split(secretName, "-")
if len(segments) != 5 {
ginkgo.Fail(fmt.Sprintf("%s have %d elements, expected: %d ", secretName, len(segments), 5))
}
accountName := segments[3]

// create a volume
containerName := "csi-inline-blobfuse-volume"
req := makeCreateVolumeReq(containerName, ns.Name)
req.Parameters["storageAccount"] = accountName
resp, err := blobDriver.CreateVolume(context.Background(), req)
if err != nil {
ginkgo.Fail(fmt.Sprintf("create volume error: %v", err))
}
resp, err := blobDriver.CreateVolume(context.Background(), makeCreateVolumeReq(containerName, ns.Name))
framework.ExpectNoError(err, "create volume error")
volumeID := resp.Volume.VolumeId
ginkgo.By(fmt.Sprintf("Successfully provisioned Blobfuse volume: %q\n", volumeID))
// get accountname and key
accountName, accountKey, _, _, err := blobDriver.GetStorageAccountAndContainer(context.Background(), volumeID, nil, nil)
framework.ExpectNoError(err, fmt.Sprintf("Error GetStorageAccountAndContainer from volumeID(%s): %v", volumeID, err))
// create secret
secretName := "csi-inline-blobfuse-volume-secret"
secretData := map[string]string{
"azurestorageaccountname": accountName,
"azurestorageaccountkey": accountKey,
}
tsecret := testsuites.NewTestSecret(cs, ns, secretName, secretData)
tsecret.Create()
defer tsecret.Cleanup()

pods := []testsuites.PodDetails{
{
Expand Down
5 changes: 4 additions & 1 deletion test/e2e/pre_provisioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package e2e
import (
"context"
"fmt"
"math/rand"
"strconv"

"sigs.k8s.io/blob-csi-driver/test/e2e/driver"
"sigs.k8s.io/blob-csi-driver/test/e2e/testsuites"
Expand Down Expand Up @@ -66,7 +68,8 @@ var _ = ginkgo.Describe("[blob-csi-e2e] Pre-Provisioned", func() {
ns = f.Namespace
testDriver = driver.InitBlobCSIDriver()

resp, err := blobDriver.CreateVolume(context.Background(), makeCreateVolumeReq(fmt.Sprintf("pre-provisioned-%d", ginkgo.GinkgoParallelProcess()), ns.Name))
volName := fmt.Sprintf("pre-provisioned-%d-%v", ginkgo.GinkgoParallelProcess(), strconv.Itoa(rand.Intn(10000)))
resp, err := blobDriver.CreateVolume(context.Background(), makeCreateVolumeReq(volName, ns.Name))
framework.ExpectNoError(err, "create volume error")
volumeID = resp.Volume.VolumeId

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/testsuites/testsuites.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ func (t *TestPod) SetupInlineVolume(name, mountPath, secretName, containerName s
Driver: blob.DefaultDriverName,
VolumeAttributes: map[string]string{
"secretName": secretName,
"secretNamespace": "default",
"secretNamespace": t.namespace.Name,
"containerName": containerName,
"mountOptions": "-o allow_other --file-cache-timeout-in-seconds=240",
},
Expand Down
18 changes: 0 additions & 18 deletions test/utils/get_storage_account_secret_name.sh

This file was deleted.

0 comments on commit f1f55e4

Please sign in to comment.