diff --git a/pkg/controller/volume/attachdetach/testing/testvolumespec.go b/pkg/controller/volume/attachdetach/testing/testvolumespec.go index 146378dd6fd..3ff5f3af9ab 100644 --- a/pkg/controller/volume/attachdetach/testing/testvolumespec.go +++ b/pkg/controller/volume/attachdetach/testing/testvolumespec.go @@ -544,7 +544,7 @@ func (attacher *testPluginAttacher) GetDeviceMountPath(spec *volume.Spec) (strin return "", nil } -func (attacher *testPluginAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string) error { +func (attacher *testPluginAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string, _ volume.DeviceMounterArgs) error { attacher.pluginLock.Lock() defer attacher.pluginLock.Unlock() if spec == nil { diff --git a/pkg/volume/awsebs/attacher.go b/pkg/volume/awsebs/attacher.go index da8eae119f1..e235edab5e0 100644 --- a/pkg/volume/awsebs/attacher.go +++ b/pkg/volume/awsebs/attacher.go @@ -206,7 +206,7 @@ func (attacher *awsElasticBlockStoreAttacher) GetDeviceMountPath( } // FIXME: this method can be further pruned. -func (attacher *awsElasticBlockStoreAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string) error { +func (attacher *awsElasticBlockStoreAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string, _ volume.DeviceMounterArgs) error { mounter := attacher.host.GetMounter(awsElasticBlockStorePluginName) notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath) if err != nil { diff --git a/pkg/volume/azuredd/attacher.go b/pkg/volume/azuredd/attacher.go index f5d84312c72..9104f5c8321 100644 --- a/pkg/volume/azuredd/attacher.go +++ b/pkg/volume/azuredd/attacher.go @@ -202,7 +202,7 @@ func (a *azureDiskAttacher) GetDeviceMountPath(spec *volume.Spec) (string, error return makeGlobalPDPath(a.plugin.host, volumeSource.DataDiskURI, isManagedDisk) } -func (a *azureDiskAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string) error { +func (a *azureDiskAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string, _ volume.DeviceMounterArgs) error { mounter := a.plugin.host.GetMounter(azureDataDiskPluginName) notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath) diff --git a/pkg/volume/cinder/attacher.go b/pkg/volume/cinder/attacher.go index a882ba33879..a8777952c55 100644 --- a/pkg/volume/cinder/attacher.go +++ b/pkg/volume/cinder/attacher.go @@ -268,7 +268,7 @@ func (attacher *cinderDiskAttacher) GetDeviceMountPath( } // FIXME: this method can be further pruned. -func (attacher *cinderDiskAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string) error { +func (attacher *cinderDiskAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string, _ volume.DeviceMounterArgs) error { mounter := attacher.host.GetMounter(cinderVolumePluginName) notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath) if err != nil { diff --git a/pkg/volume/csi/csi_attacher.go b/pkg/volume/csi/csi_attacher.go index 59548e3944b..cda9c344ad6 100644 --- a/pkg/volume/csi/csi_attacher.go +++ b/pkg/volume/csi/csi_attacher.go @@ -264,7 +264,7 @@ func (c *csiAttacher) GetDeviceMountPath(spec *volume.Spec) (string, error) { return deviceMountPath, nil } -func (c *csiAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string) error { +func (c *csiAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string, deviceMounterArgs volume.DeviceMounterArgs) error { klog.V(4).Infof(log("attacher.MountDevice(%s, %s)", devicePath, deviceMountPath)) if deviceMountPath == "" { diff --git a/pkg/volume/csi/csi_attacher_test.go b/pkg/volume/csi/csi_attacher_test.go index 2ad77408da2..df3fe002b49 100644 --- a/pkg/volume/csi/csi_attacher_test.go +++ b/pkg/volume/csi/csi_attacher_test.go @@ -1247,7 +1247,7 @@ func TestAttacherMountDevice(t *testing.T) { } // Run - err := csiAttacher.MountDevice(tc.spec, tc.devicePath, tc.deviceMountPath) + err := csiAttacher.MountDevice(tc.spec, tc.devicePath, tc.deviceMountPath, volume.DeviceMounterArgs{}) // Verify if err != nil { @@ -1435,7 +1435,7 @@ func TestAttacherMountDeviceWithInline(t *testing.T) { }() // Run - err = csiAttacher.MountDevice(tc.spec, tc.devicePath, tc.deviceMountPath) + err = csiAttacher.MountDevice(tc.spec, tc.devicePath, tc.deviceMountPath, volume.DeviceMounterArgs{}) // Verify if err != nil { diff --git a/pkg/volume/csi/csi_test.go b/pkg/volume/csi/csi_test.go index b25d50eb65d..559fae6c1e9 100644 --- a/pkg/volume/csi/csi_test.go +++ b/pkg/volume/csi/csi_test.go @@ -400,7 +400,7 @@ func TestCSI_VolumeAll(t *testing.T) { if err != nil { t.Fatalf("csiTest.VolumeAll deviceMounter.GetdeviceMountPath failed %s", err) } - if err := csiDevMounter.MountDevice(volSpec, devicePath, devMountPath); err != nil { + if err := csiDevMounter.MountDevice(volSpec, devicePath, devMountPath, volume.DeviceMounterArgs{}); err != nil { t.Fatalf("csiTest.VolumeAll deviceMounter.MountDevice failed: %v", err) } t.Log("csiTest.VolumeAll device mounted at path:", devMountPath) diff --git a/pkg/volume/fc/attacher.go b/pkg/volume/fc/attacher.go index 7b6495106a3..8775dcd530d 100644 --- a/pkg/volume/fc/attacher.go +++ b/pkg/volume/fc/attacher.go @@ -94,7 +94,7 @@ func (attacher *fcAttacher) GetDeviceMountPath( return attacher.manager.MakeGlobalPDName(*mounter.fcDisk), nil } -func (attacher *fcAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string) error { +func (attacher *fcAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string, _ volume.DeviceMounterArgs) error { mounter := attacher.host.GetMounter(fcPluginName) notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath) if err != nil { diff --git a/pkg/volume/flexvolume/attacher.go b/pkg/volume/flexvolume/attacher.go index 51587f3e0d4..5cff3aa1971 100644 --- a/pkg/volume/flexvolume/attacher.go +++ b/pkg/volume/flexvolume/attacher.go @@ -19,7 +19,7 @@ package flexvolume import ( "time" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/klog/v2" "k8s.io/kubernetes/pkg/volume" @@ -70,7 +70,7 @@ func (a *flexVolumeAttacher) GetDeviceMountPath(spec *volume.Spec) (string, erro } // MountDevice is part of the volume.Attacher interface -func (a *flexVolumeAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string) error { +func (a *flexVolumeAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string, _ volume.DeviceMounterArgs) error { // Mount only once. alreadyMounted, err := prepareForMount(a.plugin.host.GetMounter(a.plugin.GetPluginName()), deviceMountPath) if err != nil { diff --git a/pkg/volume/flexvolume/attacher_test.go b/pkg/volume/flexvolume/attacher_test.go index f8e9f12cdb4..7bdf70429d6 100644 --- a/pkg/volume/flexvolume/attacher_test.go +++ b/pkg/volume/flexvolume/attacher_test.go @@ -20,7 +20,7 @@ import ( "testing" "time" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" "k8s.io/kubernetes/pkg/volume" "k8s.io/kubernetes/test/utils/harness" ) @@ -70,7 +70,7 @@ func TestMountDevice(tt *testing.T) { ) a, _ := plugin.NewAttacher() - a.MountDevice(spec, "/dev/sdx", rootDir+"/mount-dir") + a.MountDevice(spec, "/dev/sdx", rootDir+"/mount-dir", volume.DeviceMounterArgs{}) } func TestIsVolumeAttached(tt *testing.T) { diff --git a/pkg/volume/gcepd/attacher.go b/pkg/volume/gcepd/attacher.go index 1579ff8be33..595b7d2f3d6 100644 --- a/pkg/volume/gcepd/attacher.go +++ b/pkg/volume/gcepd/attacher.go @@ -288,7 +288,7 @@ func (attacher *gcePersistentDiskAttacher) GetDeviceMountPath( return makeGlobalPDName(attacher.host, volumeSource.PDName), nil } -func (attacher *gcePersistentDiskAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string) error { +func (attacher *gcePersistentDiskAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string, _ volume.DeviceMounterArgs) error { // Only mount the PD globally once. mounter := attacher.host.GetMounter(gcePersistentDiskPluginName) notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath) diff --git a/pkg/volume/iscsi/attacher.go b/pkg/volume/iscsi/attacher.go index 94b2f382932..f4871d901af 100644 --- a/pkg/volume/iscsi/attacher.go +++ b/pkg/volume/iscsi/attacher.go @@ -98,7 +98,7 @@ func (attacher *iscsiAttacher) GetDeviceMountPath( return attacher.manager.MakeGlobalPDName(*mounter.iscsiDisk), nil } -func (attacher *iscsiAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string) error { +func (attacher *iscsiAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string, _ volume.DeviceMounterArgs) error { mounter := attacher.host.GetMounter(iscsiPluginName) notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath) if err != nil { diff --git a/pkg/volume/local/local.go b/pkg/volume/local/local.go index b2cfa9b28f6..8333a0d376f 100644 --- a/pkg/volume/local/local.go +++ b/pkg/volume/local/local.go @@ -355,7 +355,7 @@ func (dm *deviceMounter) mountLocalBlockDevice(spec *volume.Spec, devicePath str return nil } -func (dm *deviceMounter) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string) error { +func (dm *deviceMounter) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string, _ volume.DeviceMounterArgs) error { if spec.PersistentVolume.Spec.Local == nil || len(spec.PersistentVolume.Spec.Local.Path) == 0 { return fmt.Errorf("local volume source is nil or local path is not set") } diff --git a/pkg/volume/local/local_test.go b/pkg/volume/local/local_test.go index e73873d3e4a..799782396bb 100644 --- a/pkg/volume/local/local_test.go +++ b/pkg/volume/local/local_test.go @@ -231,7 +231,7 @@ func TestBlockDeviceGlobalPathAndMountDevice(t *testing.T) { fmt.Println("expected global path is:", expectedGlobalPath) - err = dm.MountDevice(pvSpec, tmpBlockDir, expectedGlobalPath) + err = dm.MountDevice(pvSpec, tmpBlockDir, expectedGlobalPath, volume.DeviceMounterArgs{}) if err != nil { t.Fatal(err) } @@ -276,7 +276,7 @@ func TestFSGlobalPathAndMountDevice(t *testing.T) { } // Actually, we will do nothing if the local path is FS type - err = dm.MountDevice(pvSpec, tmpFSDir, expectedGlobalPath) + err = dm.MountDevice(pvSpec, tmpFSDir, expectedGlobalPath, volume.DeviceMounterArgs{}) if err != nil { t.Fatal(err) } diff --git a/pkg/volume/rbd/attacher.go b/pkg/volume/rbd/attacher.go index 9b834da6ae5..9766a2895c4 100644 --- a/pkg/volume/rbd/attacher.go +++ b/pkg/volume/rbd/attacher.go @@ -146,7 +146,7 @@ func (attacher *rbdAttacher) GetDeviceMountPath(spec *volume.Spec) (string, erro // MountDevice implements Attacher.MountDevice. It is called by the kubelet to // mount device at the given mount path. // This method is idempotent, callers are responsible for retrying on failure. -func (attacher *rbdAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string) error { +func (attacher *rbdAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string, _ volume.DeviceMounterArgs) error { klog.V(4).Infof("rbd: mouting device %s to %s", devicePath, deviceMountPath) notMnt, err := attacher.mounter.IsLikelyNotMountPoint(deviceMountPath) if err != nil { diff --git a/pkg/volume/rbd/rbd_test.go b/pkg/volume/rbd/rbd_test.go index 99377f7853f..ff9b7c308ce 100644 --- a/pkg/volume/rbd/rbd_test.go +++ b/pkg/volume/rbd/rbd_test.go @@ -281,7 +281,7 @@ func doTestPlugin(t *testing.T, c *testcase) { if deviceMountPath != c.expectedDeviceMountPath { t.Errorf("Unexpected mount path, expected %q, not: %q", c.expectedDeviceMountPath, deviceMountPath) } - err = attacher.MountDevice(c.spec, devicePath, deviceMountPath) + err = attacher.MountDevice(c.spec, devicePath, deviceMountPath, volume.DeviceMounterArgs{}) if err != nil { t.Fatal(err) } diff --git a/pkg/volume/testing/testing.go b/pkg/volume/testing/testing.go index 4f297781619..34bb7ce1085 100644 --- a/pkg/volume/testing/testing.go +++ b/pkg/volume/testing/testing.go @@ -1046,7 +1046,7 @@ func (fv *FakeVolume) mountDeviceInternal(spec *Spec, devicePath string, deviceM return nil } -func (fv *FakeVolume) MountDevice(spec *Spec, devicePath string, deviceMountPath string) error { +func (fv *FakeVolume) MountDevice(spec *Spec, devicePath string, deviceMountPath string, _ volume.DeviceMounterArgs) error { return fv.mountDeviceInternal(spec, devicePath, deviceMountPath) } diff --git a/pkg/volume/util/operationexecutor/operation_generator.go b/pkg/volume/util/operationexecutor/operation_generator.go index a5aefae1d60..487c8a79bb9 100644 --- a/pkg/volume/util/operationexecutor/operation_generator.go +++ b/pkg/volume/util/operationexecutor/operation_generator.go @@ -616,7 +616,9 @@ func (og *operationGenerator) GenerateMountVolumeFunc( err = volumeDeviceMounter.MountDevice( volumeToMount.VolumeSpec, devicePath, - deviceMountPath) + deviceMountPath, + volume.DeviceMounterArgs{FsGroup: fsGroup}, + ) if err != nil { og.checkForFailedMount(volumeToMount, err) og.markDeviceErrorState(volumeToMount, devicePath, deviceMountPath, err, actualStateOfWorld) diff --git a/pkg/volume/volume.go b/pkg/volume/volume.go index 63246a85a5d..13d75a63381 100644 --- a/pkg/volume/volume.go +++ b/pkg/volume/volume.go @@ -271,6 +271,11 @@ type Attacher interface { WaitForAttach(spec *Spec, devicePath string, pod *v1.Pod, timeout time.Duration) (string, error) } +// DeviceMounterArgs provides auxiliary, optional arguments to DeviceMounter. +type DeviceMounterArgs struct { + FsGroup *int64 +} + // DeviceMounter can mount a block volume to a global path. type DeviceMounter interface { // GetDeviceMountPath returns a path where the device should @@ -285,7 +290,7 @@ type DeviceMounter interface { // - TransientOperationFailure // - UncertainProgressError // - Error of any other type should be considered a final error - MountDevice(spec *Spec, devicePath string, deviceMountPath string) error + MountDevice(spec *Spec, devicePath string, deviceMountPath string, deviceMounterArgs DeviceMounterArgs) error } type BulkVolumeVerifier interface { diff --git a/pkg/volume/vsphere_volume/attacher.go b/pkg/volume/vsphere_volume/attacher.go index 727d0ac2b64..98aa601184a 100644 --- a/pkg/volume/vsphere_volume/attacher.go +++ b/pkg/volume/vsphere_volume/attacher.go @@ -208,7 +208,7 @@ func (plugin *vsphereVolumePlugin) GetDeviceMountRefs(deviceMountPath string) ([ } // MountDevice mounts device to global mount point. -func (attacher *vsphereVMDKAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string) error { +func (attacher *vsphereVMDKAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string, _ volume.DeviceMounterArgs) error { klog.Infof("vsphere MountDevice mount %s to %s", devicePath, deviceMountPath) mounter := attacher.host.GetMounter(vsphereVolumePluginName) notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath)