Skip to content

Commit 9051609

Browse files
committed
feat: Support fsgroup in CSI calls; test: enable fsgroup e2e tests
1 parent dca8d06 commit 9051609

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

pkg/smb/nodeserver.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,12 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
132132

133133
context := req.GetVolumeContext()
134134
mountFlags := req.GetVolumeCapability().GetMount().GetMountFlags()
135+
volumeMountGroup := req.GetVolumeCapability().GetMount().GetVolumeMountGroup()
135136
secrets := req.GetSecrets()
137+
gidPresent, err := checkGidPresentInMountFlags(volumeMountGroup, mountFlags)
138+
if err != nil {
139+
return nil, err
140+
}
136141

137142
source, ok := context[sourceField]
138143
if !ok {
@@ -172,6 +177,9 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
172177
}
173178
sensitiveMountOptions = []string{fmt.Sprintf("%s=%s,%s=%s", usernameField, username, passwordField, password)}
174179
mountOptions = mountFlags
180+
if !gidPresent && volumeMountGroup != "" {
181+
mountOptions = append(mountOptions, fmt.Sprintf("gid=%s", volumeMountGroup))
182+
}
175183
if domain != "" {
176184
mountOptions = append(mountOptions, fmt.Sprintf("%s=%s", domainField, domain))
177185
}
@@ -365,3 +373,17 @@ func makeDir(pathname string) error {
365373
}
366374
return nil
367375
}
376+
377+
func checkGidPresentInMountFlags(volumeMountGroup string, mountFlags []string) (bool, error) {
378+
gidPresentInMountFlags := false
379+
for _, mountFlag := range mountFlags {
380+
if strings.HasPrefix(mountFlag, "gid") {
381+
gidPresentInMountFlags = true
382+
kvpair := strings.Split(mountFlag, "=")
383+
if volumeMountGroup != "" && len(kvpair) == 2 && !strings.EqualFold(volumeMountGroup, kvpair[1]) {
384+
return false, status.Error(codes.InvalidArgument, fmt.Sprintf("gid(%s) in storageClass and pod fsgroup(%s) are not equal", kvpair[1], volumeMountGroup))
385+
}
386+
}
387+
}
388+
return gidPresentInMountFlags, nil
389+
}

pkg/smb/smb.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func (d *Driver) Run(endpoint, kubeconfig string, testMode bool) {
8888
csi.NodeServiceCapability_RPC_GET_VOLUME_STATS,
8989
csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME,
9090
csi.NodeServiceCapability_RPC_SINGLE_NODE_MULTI_WRITER,
91+
csi.NodeServiceCapability_RPC_VOLUME_MOUNT_GROUP,
9192
})
9293

9394
s := csicommon.NewNonBlockingGRPCServer()

test/external-e2e/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ setup_e2e_binaries() {
3131

3232
# test on alternative driver name
3333
export EXTRA_HELM_OPTIONS=" --set driver.name=$DRIVER.csi.k8s.io --set controller.name=csi-$DRIVER-controller --set linux.dsName=csi-$DRIVER-node --set windows.dsName=csi-$DRIVER-node-win --set image.csiProvisioner.tag=v3.0.0"
34-
sed -i "s/smb.csi.k8s.io/$DRIVER.csi.k8s.io/g" deploy/example/storageclass-smb.yaml
34+
sed -i "s/smb.csi.k8s.io/$DRIVER.csi.k8s.io/g" test/external-e2e/storageclass-test.yaml
3535
make install-smb-provisioner
3636
make e2e-bootstrap
3737
sed -i "s/csi-smb-controller/csi-$DRIVER-controller/g" deploy/example/metrics/csi-smb-controller-svc.yaml
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
apiVersion: storage.k8s.io/v1
3+
kind: StorageClass
4+
metadata:
5+
name: smb-test
6+
provisioner: smb.csi.k8s.io
7+
parameters:
8+
# On Windows, "*.default.svc.cluster.local" could not be recognized by csi-proxy
9+
source: "//smb-server.default.svc.cluster.local/share"
10+
# if csi.storage.k8s.io/provisioner-secret is provided, will create a sub directory
11+
# with PV name under source
12+
csi.storage.k8s.io/provisioner-secret-name: "smbcreds"
13+
csi.storage.k8s.io/provisioner-secret-namespace: "default"
14+
csi.storage.k8s.io/node-stage-secret-name: "smbcreds"
15+
csi.storage.k8s.io/node-stage-secret-namespace: "default"
16+
volumeBindingMode: Immediate
17+
mountOptions:
18+
- dir_mode=0777
19+
- file_mode=0777
20+
- uid=1001

test/external-e2e/testdriver.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ DriverInfo:
1111
exec: true
1212
multipods: true
1313
RWX: true
14+
fsGroup: true
15+
volumeMountGroup: true

0 commit comments

Comments
 (0)