mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Merge pull request #88759 from andyzhangx/csi-dir-fix
feat: ignore mount dir check in csi node stage/publish
This commit is contained in:
commit
2b4be7bb5f
@ -239,23 +239,6 @@ func (c *csiAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMo
|
|||||||
return errors.New(log("attacher.MountDevice failed, deviceMountPath is empty"))
|
return errors.New(log("attacher.MountDevice failed, deviceMountPath is empty"))
|
||||||
}
|
}
|
||||||
|
|
||||||
corruptedDir := false
|
|
||||||
mounted, err := isDirMounted(c.plugin, deviceMountPath)
|
|
||||||
if err != nil {
|
|
||||||
klog.Error(log("attacher.MountDevice failed while checking mount status for dir [%s]", deviceMountPath))
|
|
||||||
if isCorruptedDir(deviceMountPath) {
|
|
||||||
corruptedDir = true // leave to CSI driver to handle corrupted mount
|
|
||||||
klog.Warning(log("attacher.MountDevice detected corrupted mount for dir [%s]", deviceMountPath))
|
|
||||||
} else {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if mounted && !corruptedDir {
|
|
||||||
klog.V(4).Info(log("attacher.MountDevice skipping mount, dir already mounted [%s]", deviceMountPath))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setup
|
// Setup
|
||||||
if spec == nil {
|
if spec == nil {
|
||||||
return errors.New(log("attacher.MountDevice failed, spec is nil"))
|
return errors.New(log("attacher.MountDevice failed, spec is nil"))
|
||||||
@ -304,7 +287,7 @@ func (c *csiAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMo
|
|||||||
|
|
||||||
// Store volume metadata for UnmountDevice. Keep it around even if the
|
// Store volume metadata for UnmountDevice. Keep it around even if the
|
||||||
// driver does not support NodeStage, UnmountDevice still needs it.
|
// driver does not support NodeStage, UnmountDevice still needs it.
|
||||||
if err = os.MkdirAll(deviceMountPath, 0750); err != nil && !corruptedDir {
|
if err = os.MkdirAll(deviceMountPath, 0750); err != nil {
|
||||||
return errors.New(log("attacher.MountDevice failed to create dir %#v: %v", deviceMountPath, err))
|
return errors.New(log("attacher.MountDevice failed to create dir %#v: %v", deviceMountPath, err))
|
||||||
}
|
}
|
||||||
klog.V(4).Info(log("created target path successfully [%s]", deviceMountPath))
|
klog.V(4).Info(log("created target path successfully [%s]", deviceMountPath))
|
||||||
|
@ -1257,6 +1257,18 @@ func TestAttacherMountDevice(t *testing.T) {
|
|||||||
t.Errorf("expected mount options: %v, got: %v", tc.spec.PersistentVolume.Spec.MountOptions, vol.MountFlags)
|
t.Errorf("expected mount options: %v, got: %v", tc.spec.PersistentVolume.Spec.MountOptions, vol.MountFlags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify the deviceMountPath was created by the plugin
|
||||||
|
if tc.stageUnstageSet {
|
||||||
|
s, err := os.Stat(tc.deviceMountPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("expected staging directory %s to be created and be a directory, got error: %s", tc.deviceMountPath, err)
|
||||||
|
} else {
|
||||||
|
if !s.IsDir() {
|
||||||
|
t.Errorf("expected staging directory %s to be directory, got something else", tc.deviceMountPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,22 +107,6 @@ func (c *csiMountMgr) SetUp(mounterArgs volume.MounterArgs) error {
|
|||||||
func (c *csiMountMgr) SetUpAt(dir string, mounterArgs volume.MounterArgs) error {
|
func (c *csiMountMgr) SetUpAt(dir string, mounterArgs volume.MounterArgs) error {
|
||||||
klog.V(4).Infof(log("Mounter.SetUpAt(%s)", dir))
|
klog.V(4).Infof(log("Mounter.SetUpAt(%s)", dir))
|
||||||
|
|
||||||
corruptedDir := false
|
|
||||||
mounted, err := isDirMounted(c.plugin, dir)
|
|
||||||
if err != nil {
|
|
||||||
if isCorruptedDir(dir) {
|
|
||||||
corruptedDir = true // leave to CSI driver to handle corrupted mount
|
|
||||||
klog.Warning(log("mounter.SetUpAt detected corrupted mount for dir [%s]", dir))
|
|
||||||
} else {
|
|
||||||
return errors.New(log("mounter.SetUpAt failed while checking mount status for dir [%s]: %v", dir, err))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if mounted && !corruptedDir {
|
|
||||||
klog.V(4).Info(log("mounter.SetUpAt skipping mount, dir already mounted [%s]", dir))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
csi, err := c.csiClientGetter.Get()
|
csi, err := c.csiClientGetter.Get()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return volumetypes.NewTransientOperationFailure(log("mounter.SetUpAt failed to get CSI client: %v", err))
|
return volumetypes.NewTransientOperationFailure(log("mounter.SetUpAt failed to get CSI client: %v", err))
|
||||||
@ -219,10 +203,11 @@ func (c *csiMountMgr) SetUpAt(dir string, mounterArgs volume.MounterArgs) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create target_dir before call to NodePublish
|
// create target_dir before call to NodePublish
|
||||||
if err := os.MkdirAll(dir, 0750); err != nil && !corruptedDir {
|
parentDir := filepath.Dir(dir)
|
||||||
return errors.New(log("mounter.SetUpAt failed to create dir %#v: %v", dir, err))
|
if err := os.MkdirAll(parentDir, 0750); err != nil {
|
||||||
|
return errors.New(log("mounter.SetUpAt failed to create dir %#v: %v", parentDir, err))
|
||||||
}
|
}
|
||||||
klog.V(4).Info(log("created target path successfully [%s]", dir))
|
klog.V(4).Info(log("created target path successfully [%s]", parentDir))
|
||||||
|
|
||||||
nodePublishSecrets = map[string]string{}
|
nodePublishSecrets = map[string]string{}
|
||||||
if secretRef != nil {
|
if secretRef != nil {
|
||||||
|
@ -571,7 +571,7 @@ func (og *operationGenerator) GenerateMountVolumeFunc(
|
|||||||
DevicePath: devicePath,
|
DevicePath: devicePath,
|
||||||
}
|
}
|
||||||
|
|
||||||
if volumeDeviceMounter != nil {
|
if volumeDeviceMounter != nil && actualStateOfWorld.GetDeviceMountState(volumeToMount.VolumeName) != DeviceGloballyMounted {
|
||||||
deviceMountPath, err :=
|
deviceMountPath, err :=
|
||||||
volumeDeviceMounter.GetDeviceMountPath(volumeToMount.VolumeSpec)
|
volumeDeviceMounter.GetDeviceMountPath(volumeToMount.VolumeSpec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -615,6 +615,17 @@ func (og *operationGenerator) GenerateMountVolumeFunc(
|
|||||||
|
|
||||||
if resizeError != nil {
|
if resizeError != nil {
|
||||||
klog.Errorf("MountVolume.NodeExpandVolume failed with %v", resizeError)
|
klog.Errorf("MountVolume.NodeExpandVolume failed with %v", resizeError)
|
||||||
|
|
||||||
|
// Resize failed. To make sure NodeExpand is re-tried again on the next attempt
|
||||||
|
// *before* SetUp(), mark the mounted device as uncertain.
|
||||||
|
markDeviceUncertainErr := actualStateOfWorld.MarkDeviceAsUncertain(
|
||||||
|
volumeToMount.VolumeName, devicePath, deviceMountPath)
|
||||||
|
if markDeviceUncertainErr != nil {
|
||||||
|
// just log, return the resizeError error instead
|
||||||
|
klog.Infof(volumeToMount.GenerateMsgDetailed(
|
||||||
|
"MountVolume.MountDevice failed to mark volume as uncertain",
|
||||||
|
markDeviceUncertainErr.Error()))
|
||||||
|
}
|
||||||
return volumeToMount.GenerateError("MountVolume.MountDevice failed while expanding volume", resizeError)
|
return volumeToMount.GenerateError("MountVolume.MountDevice failed while expanding volume", resizeError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user