mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 01:40:07 +00:00
fix some log typos in csi_mounter.go
cleanup: remove logging duplicated error message fix error msg, include err in new returned errors. Signed-off-by: ethan <guangming.wang@daocloud.io>
This commit is contained in:
parent
030274eba3
commit
ec2c5dff43
@ -19,6 +19,7 @@ package csi
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@ -103,8 +104,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 {
|
||||||
@ -114,16 +114,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
|
||||||
@ -183,15 +181,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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,8 +207,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))
|
||||||
|
|
||||||
@ -229,8 +224,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 {
|
||||||
@ -257,11 +251,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
|
||||||
@ -356,22 +349,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))
|
||||||
|
|
||||||
@ -437,22 +427,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