mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Merge pull request #80522 from ethan-daocloud/patch-3
cleanup: remove duplicated logging error message in csi_mounter.go, also some typos.
This commit is contained in:
commit
3a4cda9def
@ -19,6 +19,7 @@ package csi
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@ -104,8 +105,7 @@ func (c *csiMountMgr) SetUpAt(dir string, mounterArgs volume.MounterArgs) error
|
|||||||
|
|
||||||
mounted, err := isDirMounted(c.plugin, dir)
|
mounted, err := isDirMounted(c.plugin, dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Error(log("mounter.SetUpAt failed while checking mount status for dir [%s]", dir))
|
return errors.New(log("mounter.SetUpAt failed while checking mount status for dir [%s]: %v", dir, err))
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if mounted {
|
if mounted {
|
||||||
@ -115,16 +115,14 @@ func (c *csiMountMgr) SetUpAt(dir string, mounterArgs volume.MounterArgs) error
|
|||||||
|
|
||||||
csi, err := c.csiClientGetter.Get()
|
csi, err := c.csiClientGetter.Get()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Error(log("mounter.SetUpAt failed to get CSI client: %v", err))
|
return errors.New(log("mounter.SetUpAt failed to get CSI client: %v", err))
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), csiTimeout)
|
ctx, cancel := context.WithTimeout(context.Background(), csiTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
volSrc, pvSrc, err := getSourceFromSpec(c.spec)
|
volSrc, pvSrc, err := getSourceFromSpec(c.spec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Error(log("mounter.SetupAt failed to get CSI persistent source: %v", err))
|
return errors.New(log("mounter.SetupAt failed to get CSI persistent source: %v", err))
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
driverName := c.driverName
|
driverName := c.driverName
|
||||||
@ -184,15 +182,13 @@ func (c *csiMountMgr) SetUpAt(dir string, mounterArgs volume.MounterArgs) error
|
|||||||
// Check for STAGE_UNSTAGE_VOLUME set and populate deviceMountPath if so
|
// Check for STAGE_UNSTAGE_VOLUME set and populate deviceMountPath if so
|
||||||
stageUnstageSet, err := csi.NodeSupportsStageUnstage(ctx)
|
stageUnstageSet, err := csi.NodeSupportsStageUnstage(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Error(log("mounter.SetUpAt failed to check for STAGE_UNSTAGE_VOLUME capabilty: %v", err))
|
return errors.New(log("mounter.SetUpAt failed to check for STAGE_UNSTAGE_VOLUME capability: %v", err))
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if stageUnstageSet {
|
if stageUnstageSet {
|
||||||
deviceMountPath, err = makeDeviceMountPath(c.plugin, c.spec)
|
deviceMountPath, err = makeDeviceMountPath(c.plugin, c.spec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Error(log("mounter.SetUpAt failed to make device mount path: %v", err))
|
return errors.New(log("mounter.SetUpAt failed to make device mount path: %v", err))
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,8 +208,7 @@ 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 {
|
if err := os.MkdirAll(dir, 0750); err != nil {
|
||||||
klog.Error(log("mouter.SetUpAt failed to create dir %#v: %v", dir, err))
|
return errors.New(log("mounter.SetUpAt failed to create dir %#v: %v", dir, err))
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
klog.V(4).Info(log("created target path successfully [%s]", dir))
|
klog.V(4).Info(log("created target path successfully [%s]", dir))
|
||||||
|
|
||||||
@ -230,8 +225,7 @@ func (c *csiMountMgr) SetUpAt(dir string, mounterArgs volume.MounterArgs) error
|
|||||||
// Inject pod information into volume_attributes
|
// Inject pod information into volume_attributes
|
||||||
podAttrs, err := c.podAttributes()
|
podAttrs, err := c.podAttributes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Error(log("mouter.SetUpAt failed to assemble volume attributes: %v", err))
|
return errors.New(log("mounter.SetUpAt failed to assemble volume attributes: %v", err))
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
if podAttrs != nil {
|
if podAttrs != nil {
|
||||||
if volAttribs == nil {
|
if volAttribs == nil {
|
||||||
@ -258,11 +252,10 @@ func (c *csiMountMgr) SetUpAt(dir string, mounterArgs volume.MounterArgs) error
|
|||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf(log("mounter.SetupAt failed: %v", err))
|
|
||||||
if removeMountDirErr := removeMountDir(c.plugin, dir); removeMountDirErr != nil {
|
if removeMountDirErr := removeMountDir(c.plugin, dir); removeMountDirErr != nil {
|
||||||
klog.Error(log("mounter.SetupAt failed to remove mount dir after a NodePublish() error [%s]: %v", dir, removeMountDirErr))
|
klog.Error(log("mounter.SetupAt failed to remove mount dir after a NodePublish() error [%s]: %v", dir, removeMountDirErr))
|
||||||
}
|
}
|
||||||
return err
|
return errors.New(log("mounter.SetupAt failed: %v", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
// apply volume ownership
|
// apply volume ownership
|
||||||
@ -361,22 +354,19 @@ func (c *csiMountMgr) TearDownAt(dir string) error {
|
|||||||
volID := c.volumeID
|
volID := c.volumeID
|
||||||
csi, err := c.csiClientGetter.Get()
|
csi, err := c.csiClientGetter.Get()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Error(log("mounter.SetUpAt failed to get CSI client: %v", err))
|
return errors.New(log("mounter.SetUpAt failed to get CSI client: %v", err))
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), csiTimeout)
|
ctx, cancel := context.WithTimeout(context.Background(), csiTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
if err := csi.NodeUnpublishVolume(ctx, volID, dir); err != nil {
|
if err := csi.NodeUnpublishVolume(ctx, volID, dir); err != nil {
|
||||||
klog.Errorf(log("mounter.TearDownAt failed: %v", err))
|
return errors.New(log("mounter.TearDownAt failed: %v", err))
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// clean mount point dir
|
// clean mount point dir
|
||||||
if err := removeMountDir(c.plugin, dir); err != nil {
|
if err := removeMountDir(c.plugin, dir); err != nil {
|
||||||
klog.Error(log("mounter.TearDownAt failed to clean mount dir [%s]: %v", dir, err))
|
return errors.New(log("mounter.TearDownAt failed to clean mount dir [%s]: %v", dir, err))
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
klog.V(4).Infof(log("mounter.TearDownAt successfully unmounted dir [%s]", dir))
|
klog.V(4).Infof(log("mounter.TearDownAt successfully unmounted dir [%s]", dir))
|
||||||
|
|
||||||
@ -442,22 +432,19 @@ func removeMountDir(plug *csiPlugin, mountPath string) error {
|
|||||||
if !mnt {
|
if !mnt {
|
||||||
klog.V(4).Info(log("dir not mounted, deleting it [%s]", mountPath))
|
klog.V(4).Info(log("dir not mounted, deleting it [%s]", mountPath))
|
||||||
if err := os.Remove(mountPath); err != nil && !os.IsNotExist(err) {
|
if err := os.Remove(mountPath); err != nil && !os.IsNotExist(err) {
|
||||||
klog.Error(log("failed to remove dir [%s]: %v", mountPath, err))
|
return errors.New(log("failed to remove dir [%s]: %v", mountPath, err))
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
// remove volume data file as well
|
// remove volume data file as well
|
||||||
volPath := path.Dir(mountPath)
|
volPath := path.Dir(mountPath)
|
||||||
dataFile := filepath.Join(volPath, volDataFileName)
|
dataFile := filepath.Join(volPath, volDataFileName)
|
||||||
klog.V(4).Info(log("also deleting volume info data file [%s]", dataFile))
|
klog.V(4).Info(log("also deleting volume info data file [%s]", dataFile))
|
||||||
if err := os.Remove(dataFile); err != nil && !os.IsNotExist(err) {
|
if err := os.Remove(dataFile); err != nil && !os.IsNotExist(err) {
|
||||||
klog.Error(log("failed to delete volume data file [%s]: %v", dataFile, err))
|
return errors.New(log("failed to delete volume data file [%s]: %v", dataFile, err))
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
// remove volume path
|
// remove volume path
|
||||||
klog.V(4).Info(log("deleting volume path [%s]", volPath))
|
klog.V(4).Info(log("deleting volume path [%s]", volPath))
|
||||||
if err := os.Remove(volPath); err != nil && !os.IsNotExist(err) {
|
if err := os.Remove(volPath); err != nil && !os.IsNotExist(err) {
|
||||||
klog.Error(log("failed to delete volume path [%s]: %v", volPath, err))
|
return errors.New(log("failed to delete volume path [%s]: %v", volPath, err))
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user