Skip to content

Commit

Permalink
issue-2091: set grpid option (#2423)
Browse files Browse the repository at this point in the history
issue: #2091

Add grpid option to have volume_mount_group as GID for newly created files and directories.
  • Loading branch information
antonmyagkov authored Nov 8, 2024
1 parent ab12a72 commit ba8f76a
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
70 changes: 70 additions & 0 deletions cloud/blockstore/tests/csi_driver/e2e_tests_part2/test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest
import subprocess

from pathlib import Path

import cloud.blockstore.tests.csi_driver.lib.csi_runner as csi


Expand Down Expand Up @@ -57,3 +59,71 @@ def test_readonly_volume(mount_path, access_type, vm_mode, gid):
raise
finally:
csi.cleanup_after_test(env, volume_name, access_type, [pod_id])


def test_mount_volume_group():
# Scenario
# 1. create volume and publish volume without mount volume group
# 2. create directory and file
# 3. unpublish volume
# 4. create new group with specified GID
# 5. publish volume with mount volume group GID
# 6. check that mounted dir and existing files have specified GID
# 7. create new directory and file
# 8. check that new directory and file have specified GID
env, run = csi.init()
try:
volume_name = "example-disk"
volume_size = 1024 ** 3
pod_name = "example-pod"
pod_id = "deadbeef1"
access_type = "mount"
env.csi.create_volume(name=volume_name, size=volume_size)
env.csi.stage_volume(volume_name, access_type)

gid = 1013
result = subprocess.run(
["groupadd", "-g", str(gid), "test_group_" + str(gid)],
capture_output=True,
)
assert result.returncode == 0

env.csi.publish_volume(
pod_id,
volume_name,
pod_name,
access_type
)

mount_path = Path("/var/lib/kubelet/pods") / pod_id / "volumes/kubernetes.io~csi" / volume_name / "mount"
test_dir1 = mount_path / "testdir1"
test_dir1.mkdir()
test_file1 = test_dir1 / "testfile1"
test_file1.touch()

env.csi.unpublish_volume(pod_id, volume_name, access_type)
env.csi.publish_volume(
pod_id,
volume_name,
pod_name,
access_type,
volume_mount_group=str(gid)
)

assert gid == mount_path.stat().st_gid
assert gid == test_dir1.stat().st_gid
assert gid == test_file1.stat().st_gid

test_file2 = mount_path / "testfile2"
test_file2.touch()
assert gid == test_file2.stat().st_gid

test_dir2 = mount_path / "testdir2"
test_dir2.mkdir()
assert gid == test_dir2.stat().st_gid

except subprocess.CalledProcessError as e:
csi.log_called_process_error(e)
raise
finally:
csi.cleanup_after_test(env, volume_name, access_type, [pod_id])
2 changes: 1 addition & 1 deletion cloud/blockstore/tools/csi_driver/internal/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ func (s *nodeService) nodeStageDiskAsFilesystem(
return fmt.Errorf("failed to create staging directory: %w", err)
}

mountOptions := []string{}
mountOptions := []string{"grpid"}
if mnt != nil {
for _, flag := range mnt.MountFlags {
mountOptions = append(mountOptions, flag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ func TestPublishUnpublishDiskForInfrakuber(t *testing.T) {

mockCallIsMountPoint := mounter.On("IsMountPoint", stagingTargetPath).Return(false, nil)

mounter.On("Mount", nbdDeviceFile, stagingTargetPath, "ext4", []string{}).Return(nil)
mounter.On("Mount", nbdDeviceFile, stagingTargetPath, "ext4", []string{"grpid"}).Return(nil)

_, err = nodeService.NodeStageVolume(ctx, &csi.NodeStageVolumeRequest{
VolumeId: diskId,
Expand Down

0 comments on commit ba8f76a

Please sign in to comment.