From d661e2c70d837effad33fa03a0d4c49189ef0daf Mon Sep 17 00:00:00 2001 From: andyzhangx Date: Thu, 6 May 2021 14:17:55 +0000 Subject: [PATCH] fix: second pod mount error for static provisioning(containerName specified) add go file fix misspelling fix invalid container name fix e2e test failure --- pkg/blob/blob.go | 2 +- pkg/blob/blob_test.go | 14 ++++++ pkg/blob/controllerserver.go | 5 ++ test/e2e/pre_provisioning_test.go | 39 +++++++++++++++ .../pre_provisioned_multiple_pods.go | 48 +++++++++++++++++++ 5 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 test/e2e/testsuites/pre_provisioned_multiple_pods.go diff --git a/pkg/blob/blob.go b/pkg/blob/blob.go index 1a58b994e..fe7771349 100644 --- a/pkg/blob/blob.go +++ b/pkg/blob/blob.go @@ -169,7 +169,7 @@ func (d *Driver) Run(endpoint, kubeconfig string, testBool bool) { } // GetContainerInfo get container info according to volume id, e.g. -// input: "rg#f5713de20cde511e8ba4900#pvc-fuse-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41" +// input: "rg#f5713de20cde511e8ba4900#pvc-fuse-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41#uuid" // output: rg, f5713de20cde511e8ba4900, pvc-fuse-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41 func GetContainerInfo(id string) (string, string, string, error) { segments := strings.Split(id, separator) diff --git a/pkg/blob/blob_test.go b/pkg/blob/blob_test.go index 91cecd502..b62313311 100644 --- a/pkg/blob/blob_test.go +++ b/pkg/blob/blob_test.go @@ -145,6 +145,20 @@ func TestGetContainerInfo(t *testing.T) { expected3 string expected4 error }{ + { + options: "rg#f5713de20cde511e8ba4900#pvc-file-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41#uuid", + expected1: "rg", + expected2: "f5713de20cde511e8ba4900", + expected3: "pvc-file-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41", + expected4: nil, + }, + { + options: "rg#f5713de20cde511e8ba4900#pvc-file-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41#", + expected1: "rg", + expected2: "f5713de20cde511e8ba4900", + expected3: "pvc-file-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41", + expected4: nil, + }, { options: "rg#f5713de20cde511e8ba4900#pvc-file-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41", expected1: "rg", diff --git a/pkg/blob/controllerserver.go b/pkg/blob/controllerserver.go index 54c4b93e8..22913ec3c 100644 --- a/pkg/blob/controllerserver.go +++ b/pkg/blob/controllerserver.go @@ -207,6 +207,11 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) } volumeID := fmt.Sprintf(volumeIDTemplate, resourceGroup, accountName, containerName) + if containerName != "" { + // add volume name as suffix to differentiate volumeID since "containerName" is specified + // not necessary for dynamic container name creation since volumeID already contains volume name + volumeID = volumeID + "#" + name + } klog.V(2).Infof("create container %s on storage account %s successfully", containerName, accountName) isOperationSucceeded = true diff --git a/test/e2e/pre_provisioning_test.go b/test/e2e/pre_provisioning_test.go index 9c3bac535..d55a18f32 100644 --- a/test/e2e/pre_provisioning_test.go +++ b/test/e2e/pre_provisioning_test.go @@ -137,6 +137,41 @@ var _ = ginkgo.Describe("[blob-csi-e2e] Pre-Provisioned", func() { test.Run(cs, ns) }) + ginkgo.It("should use a pre-provisioned volume and mount it by multiple pods", func() { + volumeSize := fmt.Sprintf("%dGi", defaultVolumeSize) + pods := []testsuites.PodDetails{} + for i := 1; i <= 6; i++ { + req := makeCreateVolumeReq("pre-provisioned-multiple-pods") + resp, err := blobDriver.CreateVolume(context.Background(), req) + if err != nil { + ginkgo.Fail(fmt.Sprintf("create volume error: %v", err)) + } + volumeID := resp.Volume.VolumeId + ginkgo.By(fmt.Sprintf("Successfully provisioned blob volume: %q\n", volumeID)) + + pod := testsuites.PodDetails{ + Cmd: "echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data", + Volumes: []testsuites.VolumeDetails{ + { + VolumeID: volumeID, + ClaimSize: volumeSize, + VolumeMount: testsuites.VolumeMountDetails{ + NameGenerate: "test-volume-", + MountPathGenerate: "/mnt/test-", + }, + }, + }, + } + pods = append(pods, pod) + } + + test := testsuites.PreProvisionedMultiplePods{ + CSIDriver: testDriver, + Pods: pods, + } + test.Run(cs, ns) + }) + ginkgo.It("should use existing credentials in k8s cluster", func() { req := makeCreateVolumeReq("pre-provisioned-existing-credentials") resp, err := blobDriver.CreateVolume(context.Background(), req) @@ -233,6 +268,10 @@ func makeCreateVolumeReq(volumeName string) *csi.CreateVolumeRequest { RequiredBytes: defaultVolumeSizeBytes, LimitBytes: defaultVolumeSizeBytes, }, + Parameters: map[string]string{ + "skuname": "Standard_LRS", + "containerName": "test", + }, } return req diff --git a/test/e2e/testsuites/pre_provisioned_multiple_pods.go b/test/e2e/testsuites/pre_provisioned_multiple_pods.go new file mode 100644 index 000000000..3c0bda601 --- /dev/null +++ b/test/e2e/testsuites/pre_provisioned_multiple_pods.go @@ -0,0 +1,48 @@ +/* +Copyright 2020 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package testsuites + +import ( + "sigs.k8s.io/blob-csi-driver/test/e2e/driver" + + "github.com/onsi/ginkgo" + v1 "k8s.io/api/core/v1" + clientset "k8s.io/client-go/kubernetes" +) + +// PreProvisionedMultiplePods will provision required PV(s), PVC(s) and Pod(s) +// Testing that the Pod(s) cannot write to the volume when mounted +type PreProvisionedMultiplePods struct { + CSIDriver driver.PreProvisionedVolumeTestDriver + Pods []PodDetails +} + +func (t *PreProvisionedMultiplePods) Run(client clientset.Interface, namespace *v1.Namespace) { + for _, pod := range t.Pods { + tpod, cleanup := pod.SetupWithPreProvisionedVolumes(client, namespace, t.CSIDriver) + // defer must be called here for resources not get removed before using them + for i := range cleanup { + defer cleanup[i]() + } + + ginkgo.By("deploying the pod") + tpod.Create() + defer tpod.Cleanup() + ginkgo.By("checking that the pods command exits with no error") + tpod.WaitForSuccess() + } +}