From 0c81a2f6b01aafd11e7658bf7469b2ec9d42dc91 Mon Sep 17 00:00:00 2001 From: andyzhangx Date: Tue, 3 Mar 2020 11:55:48 +0000 Subject: [PATCH] fix: ignore dir check in csi node stage/publish --- pkg/volume/csi/csi_attacher.go | 27 +++++---------------------- pkg/volume/csi/csi_mounter.go | 22 ---------------------- 2 files changed, 5 insertions(+), 44 deletions(-) diff --git a/pkg/volume/csi/csi_attacher.go b/pkg/volume/csi/csi_attacher.go index fc5c3a28bb8..c9e3b4b780e 100644 --- a/pkg/volume/csi/csi_attacher.go +++ b/pkg/volume/csi/csi_attacher.go @@ -228,23 +228,6 @@ func (c *csiAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMo 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 if spec == nil { return errors.New(log("attacher.MountDevice failed, spec is nil")) @@ -293,11 +276,11 @@ func (c *csiAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMo // Store volume metadata for UnmountDevice. Keep it around even if the // driver does not support NodeStage, UnmountDevice still needs it. - if err = os.MkdirAll(deviceMountPath, 0750); err != nil && !corruptedDir { - 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)) dataDir := filepath.Dir(deviceMountPath) + if err = os.MkdirAll(dataDir, 0750); err != nil { + return errors.New(log("attacher.MountDevice failed to create dir %#v: %v", dataDir, err)) + } + klog.V(4).Info(log("created target parent path successfully [%s]", dataDir)) data := map[string]string{ volDataKey.volHandle: csiSource.VolumeHandle, volDataKey.driverName: csiSource.Driver, @@ -315,7 +298,7 @@ func (c *csiAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMo if err != nil && volumetypes.IsOperationFinishedError(err) { // clean up metadata klog.Errorf(log("attacher.MountDevice failed: %v", err)) - if err := removeMountDir(c.plugin, deviceMountPath); err != nil { + if err := removeMountDir(c.plugin, dataDir); err != nil { klog.Error(log("attacher.MountDevice failed to remove mount dir after error [%s]: %v", deviceMountPath, err)) } } diff --git a/pkg/volume/csi/csi_mounter.go b/pkg/volume/csi/csi_mounter.go index b807326cf72..7626234ac83 100644 --- a/pkg/volume/csi/csi_mounter.go +++ b/pkg/volume/csi/csi_mounter.go @@ -106,22 +106,6 @@ func (c *csiMountMgr) SetUp(mounterArgs volume.MounterArgs) error { func (c *csiMountMgr) SetUpAt(dir string, mounterArgs volume.MounterArgs) error { 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() if err != nil { return volumetypes.NewTransientOperationFailure(log("mounter.SetUpAt failed to get CSI client: %v", err)) @@ -217,12 +201,6 @@ func (c *csiMountMgr) SetUpAt(dir string, mounterArgs volume.MounterArgs) error return fmt.Errorf("volume source not found in volume.Spec") } - // create target_dir before call to NodePublish - if err := os.MkdirAll(dir, 0750); err != nil && !corruptedDir { - return errors.New(log("mounter.SetUpAt failed to create dir %#v: %v", dir, err)) - } - klog.V(4).Info(log("created target path successfully [%s]", dir)) - nodePublishSecrets = map[string]string{} if secretRef != nil { nodePublishSecrets, err = getCredentialsFromSecret(c.k8s, secretRef)