mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Pass FsGroup to MountDevice
This commit is contained in:
parent
ae5668edef
commit
0e315355df
@ -544,7 +544,7 @@ func (attacher *testPluginAttacher) GetDeviceMountPath(spec *volume.Spec) (strin
|
|||||||
return "", nil
|
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()
|
attacher.pluginLock.Lock()
|
||||||
defer attacher.pluginLock.Unlock()
|
defer attacher.pluginLock.Unlock()
|
||||||
if spec == nil {
|
if spec == nil {
|
||||||
|
@ -206,7 +206,7 @@ func (attacher *awsElasticBlockStoreAttacher) GetDeviceMountPath(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: this method can be further pruned.
|
// 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)
|
mounter := attacher.host.GetMounter(awsElasticBlockStorePluginName)
|
||||||
notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath)
|
notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -202,7 +202,7 @@ func (a *azureDiskAttacher) GetDeviceMountPath(spec *volume.Spec) (string, error
|
|||||||
return makeGlobalPDPath(a.plugin.host, volumeSource.DataDiskURI, isManagedDisk)
|
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)
|
mounter := a.plugin.host.GetMounter(azureDataDiskPluginName)
|
||||||
notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath)
|
notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath)
|
||||||
|
|
||||||
|
@ -268,7 +268,7 @@ func (attacher *cinderDiskAttacher) GetDeviceMountPath(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: this method can be further pruned.
|
// 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)
|
mounter := attacher.host.GetMounter(cinderVolumePluginName)
|
||||||
notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath)
|
notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -264,7 +264,7 @@ func (c *csiAttacher) GetDeviceMountPath(spec *volume.Spec) (string, error) {
|
|||||||
return deviceMountPath, nil
|
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))
|
klog.V(4).Infof(log("attacher.MountDevice(%s, %s)", devicePath, deviceMountPath))
|
||||||
|
|
||||||
if deviceMountPath == "" {
|
if deviceMountPath == "" {
|
||||||
|
@ -1247,7 +1247,7 @@ func TestAttacherMountDevice(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run
|
// Run
|
||||||
err := csiAttacher.MountDevice(tc.spec, tc.devicePath, tc.deviceMountPath)
|
err := csiAttacher.MountDevice(tc.spec, tc.devicePath, tc.deviceMountPath, volume.DeviceMounterArgs{})
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1435,7 +1435,7 @@ func TestAttacherMountDeviceWithInline(t *testing.T) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
// Run
|
// Run
|
||||||
err = csiAttacher.MountDevice(tc.spec, tc.devicePath, tc.deviceMountPath)
|
err = csiAttacher.MountDevice(tc.spec, tc.devicePath, tc.deviceMountPath, volume.DeviceMounterArgs{})
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -400,7 +400,7 @@ func TestCSI_VolumeAll(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("csiTest.VolumeAll deviceMounter.GetdeviceMountPath failed %s", err)
|
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.Fatalf("csiTest.VolumeAll deviceMounter.MountDevice failed: %v", err)
|
||||||
}
|
}
|
||||||
t.Log("csiTest.VolumeAll device mounted at path:", devMountPath)
|
t.Log("csiTest.VolumeAll device mounted at path:", devMountPath)
|
||||||
|
@ -94,7 +94,7 @@ func (attacher *fcAttacher) GetDeviceMountPath(
|
|||||||
return attacher.manager.MakeGlobalPDName(*mounter.fcDisk), nil
|
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)
|
mounter := attacher.host.GetMounter(fcPluginName)
|
||||||
notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath)
|
notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -19,7 +19,7 @@ package flexvolume
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
"k8s.io/kubernetes/pkg/volume"
|
"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
|
// 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.
|
// Mount only once.
|
||||||
alreadyMounted, err := prepareForMount(a.plugin.host.GetMounter(a.plugin.GetPluginName()), deviceMountPath)
|
alreadyMounted, err := prepareForMount(a.plugin.host.GetMounter(a.plugin.GetPluginName()), deviceMountPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/kubernetes/pkg/volume"
|
"k8s.io/kubernetes/pkg/volume"
|
||||||
"k8s.io/kubernetes/test/utils/harness"
|
"k8s.io/kubernetes/test/utils/harness"
|
||||||
)
|
)
|
||||||
@ -70,7 +70,7 @@ func TestMountDevice(tt *testing.T) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
a, _ := plugin.NewAttacher()
|
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) {
|
func TestIsVolumeAttached(tt *testing.T) {
|
||||||
|
@ -288,7 +288,7 @@ func (attacher *gcePersistentDiskAttacher) GetDeviceMountPath(
|
|||||||
return makeGlobalPDName(attacher.host, volumeSource.PDName), nil
|
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.
|
// Only mount the PD globally once.
|
||||||
mounter := attacher.host.GetMounter(gcePersistentDiskPluginName)
|
mounter := attacher.host.GetMounter(gcePersistentDiskPluginName)
|
||||||
notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath)
|
notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath)
|
||||||
|
@ -98,7 +98,7 @@ func (attacher *iscsiAttacher) GetDeviceMountPath(
|
|||||||
return attacher.manager.MakeGlobalPDName(*mounter.iscsiDisk), nil
|
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)
|
mounter := attacher.host.GetMounter(iscsiPluginName)
|
||||||
notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath)
|
notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -355,7 +355,7 @@ func (dm *deviceMounter) mountLocalBlockDevice(spec *volume.Spec, devicePath str
|
|||||||
return nil
|
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 {
|
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")
|
return fmt.Errorf("local volume source is nil or local path is not set")
|
||||||
}
|
}
|
||||||
|
@ -231,7 +231,7 @@ func TestBlockDeviceGlobalPathAndMountDevice(t *testing.T) {
|
|||||||
|
|
||||||
fmt.Println("expected global path is:", expectedGlobalPath)
|
fmt.Println("expected global path is:", expectedGlobalPath)
|
||||||
|
|
||||||
err = dm.MountDevice(pvSpec, tmpBlockDir, expectedGlobalPath)
|
err = dm.MountDevice(pvSpec, tmpBlockDir, expectedGlobalPath, volume.DeviceMounterArgs{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -276,7 +276,7 @@ func TestFSGlobalPathAndMountDevice(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actually, we will do nothing if the local path is FS type
|
// 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 {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,7 @@ func (attacher *rbdAttacher) GetDeviceMountPath(spec *volume.Spec) (string, erro
|
|||||||
// MountDevice implements Attacher.MountDevice. It is called by the kubelet to
|
// MountDevice implements Attacher.MountDevice. It is called by the kubelet to
|
||||||
// mount device at the given mount path.
|
// mount device at the given mount path.
|
||||||
// This method is idempotent, callers are responsible for retrying on failure.
|
// 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)
|
klog.V(4).Infof("rbd: mouting device %s to %s", devicePath, deviceMountPath)
|
||||||
notMnt, err := attacher.mounter.IsLikelyNotMountPoint(deviceMountPath)
|
notMnt, err := attacher.mounter.IsLikelyNotMountPoint(deviceMountPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -281,7 +281,7 @@ func doTestPlugin(t *testing.T, c *testcase) {
|
|||||||
if deviceMountPath != c.expectedDeviceMountPath {
|
if deviceMountPath != c.expectedDeviceMountPath {
|
||||||
t.Errorf("Unexpected mount path, expected %q, not: %q", c.expectedDeviceMountPath, deviceMountPath)
|
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 {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -1046,7 +1046,7 @@ func (fv *FakeVolume) mountDeviceInternal(spec *Spec, devicePath string, deviceM
|
|||||||
return nil
|
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)
|
return fv.mountDeviceInternal(spec, devicePath, deviceMountPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -616,7 +616,9 @@ func (og *operationGenerator) GenerateMountVolumeFunc(
|
|||||||
err = volumeDeviceMounter.MountDevice(
|
err = volumeDeviceMounter.MountDevice(
|
||||||
volumeToMount.VolumeSpec,
|
volumeToMount.VolumeSpec,
|
||||||
devicePath,
|
devicePath,
|
||||||
deviceMountPath)
|
deviceMountPath,
|
||||||
|
volume.DeviceMounterArgs{FsGroup: fsGroup},
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
og.checkForFailedMount(volumeToMount, err)
|
og.checkForFailedMount(volumeToMount, err)
|
||||||
og.markDeviceErrorState(volumeToMount, devicePath, deviceMountPath, err, actualStateOfWorld)
|
og.markDeviceErrorState(volumeToMount, devicePath, deviceMountPath, err, actualStateOfWorld)
|
||||||
|
@ -271,6 +271,11 @@ type Attacher interface {
|
|||||||
WaitForAttach(spec *Spec, devicePath string, pod *v1.Pod, timeout time.Duration) (string, error)
|
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.
|
// DeviceMounter can mount a block volume to a global path.
|
||||||
type DeviceMounter interface {
|
type DeviceMounter interface {
|
||||||
// GetDeviceMountPath returns a path where the device should
|
// GetDeviceMountPath returns a path where the device should
|
||||||
@ -285,7 +290,7 @@ type DeviceMounter interface {
|
|||||||
// - TransientOperationFailure
|
// - TransientOperationFailure
|
||||||
// - UncertainProgressError
|
// - UncertainProgressError
|
||||||
// - Error of any other type should be considered a final error
|
// - 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 {
|
type BulkVolumeVerifier interface {
|
||||||
|
@ -208,7 +208,7 @@ func (plugin *vsphereVolumePlugin) GetDeviceMountRefs(deviceMountPath string) ([
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MountDevice mounts device to global mount point.
|
// 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)
|
klog.Infof("vsphere MountDevice mount %s to %s", devicePath, deviceMountPath)
|
||||||
mounter := attacher.host.GetMounter(vsphereVolumePluginName)
|
mounter := attacher.host.GetMounter(vsphereVolumePluginName)
|
||||||
notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath)
|
notMnt, err := mounter.IsLikelyNotMountPoint(deviceMountPath)
|
||||||
|
Loading…
Reference in New Issue
Block a user