Skip to content

Commit 0dca1be

Browse files
committed
feat: support volume mount group
1 parent 4b0fb27 commit 0dca1be

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

pkg/blob/blob.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ type DriverOptions struct {
168168
EnableAznfsMount bool
169169
VolStatsCacheExpireInMinutes int
170170
SasTokenExpirationMinutes int
171+
EnableVolumeMountGroup bool
171172
}
172173

173174
func (option *DriverOptions) AddFlags() {
@@ -185,6 +186,7 @@ func (option *DriverOptions) AddFlags() {
185186
flag.BoolVar(&option.EnableAznfsMount, "enable-aznfs-mount", false, "replace nfs mount with aznfs mount")
186187
flag.IntVar(&option.VolStatsCacheExpireInMinutes, "vol-stats-cache-expire-in-minutes", 10, "The cache expire time in minutes for volume stats cache")
187188
flag.IntVar(&option.SasTokenExpirationMinutes, "sas-token-expiration-minutes", 1440, "sas token expiration minutes during volume cloning")
189+
flag.BoolVar(&option.EnableVolumeMountGroup, "enable-volume-mount-group", true, "indicates whether enabling VOLUME_MOUNT_GROUP")
188190
}
189191

190192
// Driver implements all interfaces of CSI drivers
@@ -204,6 +206,7 @@ type Driver struct {
204206
blobfuseProxyConnTimout int
205207
mountPermissions uint64
206208
enableAznfsMount bool
209+
enableVolumeMountGroup bool
207210
mounter *mount.SafeFormatAndMount
208211
volLockMap *util.LockMap
209212
// A map storing all volumes with ongoing operations so that additional operations
@@ -239,6 +242,7 @@ func NewDriver(options *DriverOptions, kubeClient kubernetes.Interface, cloud *p
239242
blobfuseProxyConnTimout: options.BlobfuseProxyConnTimout,
240243
enableBlobMockMount: options.EnableBlobMockMount,
241244
enableGetVolumeStats: options.EnableGetVolumeStats,
245+
enableVolumeMountGroup: options.EnableVolumeMountGroup,
242246
appendMountErrorHelpLink: options.AppendMountErrorHelpLink,
243247
mountPermissions: options.MountPermissions,
244248
enableAznfsMount: options.EnableAznfsMount,
@@ -297,6 +301,9 @@ func NewDriver(options *DriverOptions, kubeClient kubernetes.Interface, cloud *p
297301
if d.enableGetVolumeStats {
298302
nodeCap = append(nodeCap, csi.NodeServiceCapability_RPC_GET_VOLUME_STATS)
299303
}
304+
if d.enableVolumeMountGroup {
305+
nodeCap = append(nodeCap, csi.NodeServiceCapability_RPC_VOLUME_MOUNT_GROUP)
306+
}
300307
d.AddNodeServiceCapabilities(nodeCap)
301308

302309
return &d

pkg/blob/nodeserver.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
237237
defer d.volumeLocks.Release(lockKey)
238238

239239
mountFlags := req.GetVolumeCapability().GetMount().GetMountFlags()
240+
volumeMountGroup := req.GetVolumeCapability().GetMount().GetVolumeMountGroup()
240241
attrib := req.GetVolumeContext()
241242
secrets := req.GetSecrets()
242243

@@ -361,6 +362,11 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
361362
if isHnsEnabled {
362363
mountOptions = util.JoinMountOptions(mountOptions, []string{"--use-adls=true"})
363364
}
365+
366+
if !checkGidPresentInMountFlags(mountFlags) && volumeMountGroup != "" {
367+
mountOptions = append(mountOptions, fmt.Sprintf("gid=%s", volumeMountGroup))
368+
}
369+
364370
tmpPath := fmt.Sprintf("%s/%s", "/mnt", volumeID)
365371
if d.appendTimeStampInCacheDir {
366372
tmpPath += fmt.Sprintf("#%d", time.Now().Unix())
@@ -372,8 +378,8 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
372378
args = args + " " + opt
373379
}
374380

375-
klog.V(2).Infof("target %v\nprotocol %v\n\nvolumeId %v\ncontext %v\nmountflags %v\nmountOptions %v\nargs %v\nserverAddress %v",
376-
targetPath, protocol, volumeID, attrib, mountFlags, mountOptions, args, serverAddress)
381+
klog.V(2).Infof("target %v\nprotocol %v\n\nvolumeId %v\ncontext %v\nmountflags %v mountOptions %v volumeMountGroup %s\nargs %v\nserverAddress %v",
382+
targetPath, protocol, volumeID, attrib, mountFlags, mountOptions, volumeMountGroup, args, serverAddress)
377383

378384
authEnv = append(authEnv, "AZURE_STORAGE_ACCOUNT="+accountName, "AZURE_STORAGE_BLOB_ENDPOINT="+serverAddress)
379385
if d.enableBlobMockMount {
@@ -653,3 +659,12 @@ func waitForMount(path string, intervel, timeout time.Duration) error {
653659
}
654660
}
655661
}
662+
663+
func checkGidPresentInMountFlags(mountFlags []string) bool {
664+
for _, mountFlag := range mountFlags {
665+
if strings.HasPrefix(mountFlag, "gid") {
666+
return true
667+
}
668+
}
669+
return false
670+
}

pkg/blob/nodeserver_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,3 +812,29 @@ func Test_waitForMount(t *testing.T) {
812812
})
813813
}
814814
}
815+
816+
func TestCheckGidPresentInMountFlags(t *testing.T) {
817+
tests := []struct {
818+
desc string
819+
MountFlags []string
820+
result bool
821+
}{
822+
{
823+
desc: "[Success] Gid present in mount flags",
824+
MountFlags: []string{"gid=3000"},
825+
result: true,
826+
},
827+
{
828+
desc: "[Success] Gid not present in mount flags",
829+
MountFlags: []string{},
830+
result: false,
831+
},
832+
}
833+
834+
for _, test := range tests {
835+
gIDPresent := checkGidPresentInMountFlags(test.MountFlags)
836+
if gIDPresent != test.result {
837+
t.Errorf("[%s]: Expected result : %t, Actual result: %t", test.desc, test.result, gIDPresent)
838+
}
839+
}
840+
}

0 commit comments

Comments
 (0)