Skip to content

Commit 23a6e2d

Browse files
committed
add mountOptions support
remove comments
1 parent 8713936 commit 23a6e2d

File tree

4 files changed

+54
-6
lines changed

4 files changed

+54
-6
lines changed

pkg/blobfuse/controllerserver.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ import (
2121
"fmt"
2222
"strings"
2323

24-
"k8s.io/kubernetes/pkg/volume/util"
24+
k8sutil "k8s.io/kubernetes/pkg/volume/util"
2525

2626
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2018-07-01/storage"
2727
azstorage "github.com/Azure/azure-sdk-for-go/storage"
2828
"github.com/container-storage-interface/spec/lib/go/csi"
29-
volumehelper "github.com/csi-driver/blobfuse-csi-driver/pkg/util"
29+
"github.com/csi-driver/blobfuse-csi-driver/pkg/util"
3030
"github.com/pborman/uuid"
3131
"k8s.io/klog"
3232

@@ -53,7 +53,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
5353
}
5454

5555
volSizeBytes := int64(req.GetCapacityRange().GetRequiredBytes())
56-
requestGiB := int(volumehelper.RoundUpGiB(volSizeBytes))
56+
requestGiB := int(util.RoundUpGiB(volSizeBytes))
5757

5858
parameters := req.GetParameters()
5959
var storageAccountType, resourceGroup, location, accountName, containerName string
@@ -92,7 +92,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
9292
if containerName == "" {
9393
// now we set as 63 for maximum container name length
9494
// todo: get cluster name
95-
containerName = util.GenerateVolumeName("pvc-fuse", uuid.NewUUID().String(), 63)
95+
containerName = k8sutil.GenerateVolumeName("pvc-fuse", uuid.NewUUID().String(), 63)
9696
}
9797

9898
klog.V(2).Infof("begin to create container(%s) on account(%s) type(%s) rg(%s) location(%s) size(%d)", containerName, accountName, storageAccountType, resourceGroup, location, requestGiB)

pkg/blobfuse/nodeserver.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ import (
2424
"strings"
2525

2626
"github.com/container-storage-interface/spec/lib/go/csi"
27+
"github.com/csi-driver/blobfuse-csi-driver/pkg/util"
2728
"k8s.io/klog"
29+
k8sutil "k8s.io/kubernetes/pkg/volume/util"
2830

2931
"google.golang.org/grpc/codes"
3032
"google.golang.org/grpc/status"
@@ -114,8 +116,15 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
114116
}
115117
}
116118

117-
// todo: user could set tmp-path and other mountOptions
118-
cmd := exec.Command("/usr/blob/blobfuse", targetPath, "--tmp-path=/mnt/"+volumeID, "--container-name="+containerName)
119+
// "allow_other" option refer to http://manpages.ubuntu.com/manpages/xenial/man8/mount.fuse.8.html
120+
options := []string{"-o allow_other"}
121+
if readOnly {
122+
options = append(options, "-o ro")
123+
}
124+
mountOptions := k8sutil.JoinMountOptions(mountFlags, options)
125+
126+
cmd := exec.Command("/usr/blob/blobfuse", targetPath, "--tmp-path=/mnt/"+volumeID,
127+
"--container-name="+containerName, util.GetMountOptions(mountOptions))
119128
cmd.Env = append(os.Environ(), "AZURE_STORAGE_ACCOUNT="+accountName, "AZURE_STORAGE_ACCESS_KEY="+accountKey)
120129
err = cmd.Run()
121130
if err != nil {

pkg/util/util.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,15 @@ func roundUpSize(volumeSizeBytes int64, allocationUnitBytes int64) int64 {
5454
}
5555
return roundedUp
5656
}
57+
58+
// GetMountOptions return options with string list seperated by space
59+
func GetMountOptions(options []string) string {
60+
if len(options) == 0 {
61+
return ""
62+
}
63+
str := options[0]
64+
for i := 1; i < len(options); i++ {
65+
str = str + " " + options[i]
66+
}
67+
return str
68+
}

pkg/util/util_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,30 @@ func TestGiBToBytes(t *testing.T) {
5353
t.Fatalf("Wrong result for GiBToBytes. Got: %d", actual)
5454
}
5555
}
56+
57+
func TestGetMountOptions(t *testing.T) {
58+
tests := []struct {
59+
options []string
60+
expected string
61+
}{
62+
{
63+
options: []string{"-o allow_other", "-o ro", "--use-https=true"},
64+
expected: "-o allow_other -o ro --use-https=true",
65+
},
66+
{
67+
options: []string{"-o allow_other"},
68+
expected: "-o allow_other",
69+
},
70+
{
71+
options: []string{""},
72+
expected: "",
73+
},
74+
}
75+
76+
for _, test := range tests {
77+
result := GetMountOptions(test.options)
78+
if result != test.expected {
79+
t.Errorf("getMountOptions(%v) result: %s, expected: %s", test.options, result, test.expected)
80+
}
81+
}
82+
}

0 commit comments

Comments
 (0)