Skip to content

Commit

Permalink
fix: second pod mount error for static provisioning(containerName spe…
Browse files Browse the repository at this point in the history
…cified)

add go file

fix misspelling

fix invalid container name

fix e2e test failure
  • Loading branch information
andyzhangx committed May 7, 2021
1 parent 4c721f4 commit d661e2c
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions pkg/blob/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions pkg/blob/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions test/e2e/pre_provisioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
48 changes: 48 additions & 0 deletions test/e2e/testsuites/pre_provisioned_multiple_pods.go
Original file line number Diff line number Diff line change
@@ -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()
}
}

0 comments on commit d661e2c

Please sign in to comment.