Skip to content

Commit 23c1420

Browse files
authored
Merge pull request #417 from andyzhangx/volname-suffix
fix: second pod mount error for static provisioning(containerName specified)
2 parents 4c721f4 + 7b31583 commit 23c1420

File tree

5 files changed

+108
-1
lines changed

5 files changed

+108
-1
lines changed

pkg/blob/blob.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func (d *Driver) Run(endpoint, kubeconfig string, testBool bool) {
169169
}
170170

171171
// GetContainerInfo get container info according to volume id, e.g.
172-
// input: "rg#f5713de20cde511e8ba4900#pvc-fuse-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41"
172+
// input: "rg#f5713de20cde511e8ba4900#pvc-fuse-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41#uuid"
173173
// output: rg, f5713de20cde511e8ba4900, pvc-fuse-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41
174174
func GetContainerInfo(id string) (string, string, string, error) {
175175
segments := strings.Split(id, separator)

pkg/blob/blob_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,20 @@ func TestGetContainerInfo(t *testing.T) {
145145
expected3 string
146146
expected4 error
147147
}{
148+
{
149+
options: "rg#f5713de20cde511e8ba4900#pvc-file-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41#uuid",
150+
expected1: "rg",
151+
expected2: "f5713de20cde511e8ba4900",
152+
expected3: "pvc-file-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41",
153+
expected4: nil,
154+
},
155+
{
156+
options: "rg#f5713de20cde511e8ba4900#pvc-file-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41#",
157+
expected1: "rg",
158+
expected2: "f5713de20cde511e8ba4900",
159+
expected3: "pvc-file-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41",
160+
expected4: nil,
161+
},
148162
{
149163
options: "rg#f5713de20cde511e8ba4900#pvc-file-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41",
150164
expected1: "rg",

pkg/blob/controllerserver.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
207207
}
208208

209209
volumeID := fmt.Sprintf(volumeIDTemplate, resourceGroup, accountName, containerName)
210+
if containerName != "" {
211+
// add volume name as suffix to differentiate volumeID since "containerName" is specified
212+
// not necessary for dynamic container name creation since volumeID already contains volume name
213+
volumeID = volumeID + "#" + name
214+
}
210215
klog.V(2).Infof("create container %s on storage account %s successfully", containerName, accountName)
211216

212217
isOperationSucceeded = true

test/e2e/pre_provisioning_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package e2e
1919
import (
2020
"context"
2121
"fmt"
22+
"time"
2223

2324
"sigs.k8s.io/blob-csi-driver/test/e2e/driver"
2425
"sigs.k8s.io/blob-csi-driver/test/e2e/testsuites"
@@ -137,6 +138,41 @@ var _ = ginkgo.Describe("[blob-csi-e2e] Pre-Provisioned", func() {
137138
test.Run(cs, ns)
138139
})
139140

141+
ginkgo.It("should use a pre-provisioned volume and mount it by multiple pods", func() {
142+
volumeSize := fmt.Sprintf("%dGi", defaultVolumeSize)
143+
pods := []testsuites.PodDetails{}
144+
for i := 1; i <= 6; i++ {
145+
req := makeCreateVolumeReq(fmt.Sprintf("pre-provisioned-multiple-pods%d", time.Now().UnixNano()))
146+
resp, err := blobDriver.CreateVolume(context.Background(), req)
147+
if err != nil {
148+
ginkgo.Fail(fmt.Sprintf("create volume error: %v", err))
149+
}
150+
volumeID := resp.Volume.VolumeId
151+
ginkgo.By(fmt.Sprintf("Successfully provisioned blob volume: %q\n", volumeID))
152+
153+
pod := testsuites.PodDetails{
154+
Cmd: "echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data",
155+
Volumes: []testsuites.VolumeDetails{
156+
{
157+
VolumeID: volumeID,
158+
ClaimSize: volumeSize,
159+
VolumeMount: testsuites.VolumeMountDetails{
160+
NameGenerate: "test-volume-",
161+
MountPathGenerate: "/mnt/test-",
162+
},
163+
},
164+
},
165+
}
166+
pods = append(pods, pod)
167+
}
168+
169+
test := testsuites.PreProvisionedMultiplePods{
170+
CSIDriver: testDriver,
171+
Pods: pods,
172+
}
173+
test.Run(cs, ns)
174+
})
175+
140176
ginkgo.It("should use existing credentials in k8s cluster", func() {
141177
req := makeCreateVolumeReq("pre-provisioned-existing-credentials")
142178
resp, err := blobDriver.CreateVolume(context.Background(), req)
@@ -233,6 +269,10 @@ func makeCreateVolumeReq(volumeName string) *csi.CreateVolumeRequest {
233269
RequiredBytes: defaultVolumeSizeBytes,
234270
LimitBytes: defaultVolumeSizeBytes,
235271
},
272+
Parameters: map[string]string{
273+
"skuname": "Standard_LRS",
274+
"containerName": "test",
275+
},
236276
}
237277

238278
return req
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Copyright 2020 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 testsuites
18+
19+
import (
20+
"sigs.k8s.io/blob-csi-driver/test/e2e/driver"
21+
22+
"github.com/onsi/ginkgo"
23+
v1 "k8s.io/api/core/v1"
24+
clientset "k8s.io/client-go/kubernetes"
25+
)
26+
27+
// PreProvisionedMultiplePods will provision required PV(s), PVC(s) and Pod(s)
28+
// Testing that the Pod(s) cannot write to the volume when mounted
29+
type PreProvisionedMultiplePods struct {
30+
CSIDriver driver.PreProvisionedVolumeTestDriver
31+
Pods []PodDetails
32+
}
33+
34+
func (t *PreProvisionedMultiplePods) Run(client clientset.Interface, namespace *v1.Namespace) {
35+
for _, pod := range t.Pods {
36+
tpod, cleanup := pod.SetupWithPreProvisionedVolumes(client, namespace, t.CSIDriver)
37+
// defer must be called here for resources not get removed before using them
38+
for i := range cleanup {
39+
defer cleanup[i]()
40+
}
41+
42+
ginkgo.By("deploying the pod")
43+
tpod.Create()
44+
defer tpod.Cleanup()
45+
ginkgo.By("checking that the pods command exits with no error")
46+
tpod.WaitForSuccess()
47+
}
48+
}

0 commit comments

Comments
 (0)