mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #80866 from ethan-daocloud/dev-ethan-csi-log
cleanup: remove package csi duplicated error log
This commit is contained in:
commit
1bc3d1abde
@ -66,8 +66,7 @@ func (c *csiAttacher) Attach(spec *volume.Spec, nodeName types.NodeName) (string
|
||||
|
||||
pvSrc, err := getPVSourceFromSpec(spec)
|
||||
if err != nil {
|
||||
klog.Error(log("attacher.Attach failed to get CSIPersistentVolumeSource: %v", err))
|
||||
return "", err
|
||||
return "", errors.New(log("attacher.Attach failed to get CSIPersistentVolumeSource: %v", err))
|
||||
}
|
||||
|
||||
node := string(nodeName)
|
||||
@ -107,8 +106,7 @@ func (c *csiAttacher) Attach(spec *volume.Spec, nodeName types.NodeName) (string
|
||||
alreadyExist := false
|
||||
if err != nil {
|
||||
if !apierrs.IsAlreadyExists(err) {
|
||||
klog.Error(log("attacher.Attach failed: %v", err))
|
||||
return "", err
|
||||
return "", errors.New(log("attacher.Attach failed: %v", err))
|
||||
}
|
||||
alreadyExist = true
|
||||
}
|
||||
@ -132,8 +130,7 @@ func (c *csiAttacher) Attach(spec *volume.Spec, nodeName types.NodeName) (string
|
||||
func (c *csiAttacher) WaitForAttach(spec *volume.Spec, _ string, pod *v1.Pod, timeout time.Duration) (string, error) {
|
||||
source, err := getPVSourceFromSpec(spec)
|
||||
if err != nil {
|
||||
klog.Error(log("attacher.WaitForAttach failed to extract CSI volume source: %v", err))
|
||||
return "", err
|
||||
return "", errors.New(log("attacher.WaitForAttach failed to extract CSI volume source: %v", err))
|
||||
}
|
||||
|
||||
attachID := getAttachmentName(source.VolumeHandle, source.Driver, string(c.plugin.host.GetNodeName()))
|
||||
@ -275,8 +272,7 @@ func (c *csiAttacher) GetDeviceMountPath(spec *volume.Spec) (string, error) {
|
||||
klog.V(4).Info(log("attacher.GetDeviceMountPath(%v)", spec))
|
||||
deviceMountPath, err := makeDeviceMountPath(c.plugin, spec)
|
||||
if err != nil {
|
||||
klog.Error(log("attacher.GetDeviceMountPath failed to make device mount path: %v", err))
|
||||
return "", err
|
||||
return "", errors.New(log("attacher.GetDeviceMountPath failed to make device mount path: %v", err))
|
||||
}
|
||||
klog.V(4).Infof("attacher.GetDeviceMountPath succeeded, deviceMountPath: %s", deviceMountPath)
|
||||
return deviceMountPath, nil
|
||||
@ -307,15 +303,13 @@ func (c *csiAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMo
|
||||
}
|
||||
csiSource, err := getPVSourceFromSpec(spec)
|
||||
if err != nil {
|
||||
klog.Error(log("attacher.MountDevice failed to get CSIPersistentVolumeSource: %v", err))
|
||||
return err
|
||||
return errors.New(log("attacher.MountDevice failed to get CSIPersistentVolumeSource: %v", err))
|
||||
}
|
||||
|
||||
// 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 {
|
||||
klog.Error(log("attacher.MountDevice failed to create dir %#v: %v", deviceMountPath, err))
|
||||
return 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))
|
||||
dataDir := filepath.Dir(deviceMountPath)
|
||||
@ -343,8 +337,7 @@ func (c *csiAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMo
|
||||
if c.csiClient == nil {
|
||||
c.csiClient, err = newCsiDriverClient(csiDriverName(csiSource.Driver))
|
||||
if err != nil {
|
||||
klog.Errorf(log("attacher.MountDevice failed to create newCsiDriverClient: %v", err))
|
||||
return err
|
||||
return errors.New(log("attacher.MountDevice failed to create newCsiDriverClient: %v", err))
|
||||
}
|
||||
}
|
||||
csi := c.csiClient
|
||||
@ -449,8 +442,7 @@ func (c *csiAttacher) Detach(volumeName string, nodeName types.NodeName) error {
|
||||
klog.V(4).Info(log("VolumeAttachment object [%v] for volume [%v] not found, object deleted", attachID, volID))
|
||||
return nil
|
||||
}
|
||||
klog.Error(log("detacher.Detach failed to delete VolumeAttachment [%s]: %v", attachID, err))
|
||||
return err
|
||||
return errors.New(log("detacher.Detach failed to delete VolumeAttachment [%s]: %v", attachID, err))
|
||||
}
|
||||
|
||||
klog.V(4).Info(log("detacher deleted ok VolumeAttachment.ID=%s", attachID))
|
||||
@ -476,8 +468,7 @@ func (c *csiAttacher) waitForVolumeDetachmentInternal(volumeHandle, attachID str
|
||||
klog.V(4).Info(log("VolumeAttachment object [%v] for volume [%v] not found, object deleted", attachID, volumeHandle))
|
||||
return nil
|
||||
}
|
||||
klog.Error(log("detacher.WaitForDetach failed for volume [%s] (will continue to try): %v", volumeHandle, err))
|
||||
return err
|
||||
return errors.New(log("detacher.WaitForDetach failed for volume [%s] (will continue to try): %v", volumeHandle, err))
|
||||
}
|
||||
// driver reports attach error
|
||||
detachErr := attach.Status.DetachError
|
||||
@ -558,8 +549,7 @@ func (c *csiAttacher) UnmountDevice(deviceMountPath string) error {
|
||||
if c.csiClient == nil {
|
||||
c.csiClient, err = newCsiDriverClient(csiDriverName(driverName))
|
||||
if err != nil {
|
||||
klog.Errorf(log("attacher.UnmountDevice failed to create newCsiDriverClient: %v", err))
|
||||
return err
|
||||
return errors.New(log("attacher.UnmountDevice failed to create newCsiDriverClient: %v", err))
|
||||
}
|
||||
}
|
||||
csi := c.csiClient
|
||||
@ -569,8 +559,7 @@ func (c *csiAttacher) UnmountDevice(deviceMountPath string) error {
|
||||
// Check whether "STAGE_UNSTAGE_VOLUME" is set
|
||||
stageUnstageSet, err := csi.NodeSupportsStageUnstage(ctx)
|
||||
if err != nil {
|
||||
klog.Errorf(log("attacher.UnmountDevice failed to check whether STAGE_UNSTAGE_VOLUME set: %v", err))
|
||||
return err
|
||||
return errors.New(log("attacher.UnmountDevice failed to check whether STAGE_UNSTAGE_VOLUME set: %v", err))
|
||||
}
|
||||
if !stageUnstageSet {
|
||||
klog.Infof(log("attacher.UnmountDevice STAGE_UNSTAGE_VOLUME capability not set. Skipping UnmountDevice..."))
|
||||
@ -588,8 +577,7 @@ func (c *csiAttacher) UnmountDevice(deviceMountPath string) error {
|
||||
deviceMountPath)
|
||||
|
||||
if err != nil {
|
||||
klog.Errorf(log("attacher.UnmountDevice failed: %v", err))
|
||||
return err
|
||||
return errors.New(log("attacher.UnmountDevice failed: %v", err))
|
||||
}
|
||||
|
||||
// Delete the global directory + json file
|
||||
|
@ -97,8 +97,7 @@ func (m *csiBlockMapper) stageVolumeForBlock(
|
||||
// Check whether "STAGE_UNSTAGE_VOLUME" is set
|
||||
stageUnstageSet, err := csi.NodeSupportsStageUnstage(ctx)
|
||||
if err != nil {
|
||||
klog.Error(log("blockMapper.stageVolumeForBlock failed to check STAGE_UNSTAGE_VOLUME capability: %v", err))
|
||||
return "", err
|
||||
return "", errors.New(log("blockMapper.stageVolumeForBlock failed to check STAGE_UNSTAGE_VOLUME capability: %v", err))
|
||||
}
|
||||
if !stageUnstageSet {
|
||||
klog.Infof(log("blockMapper.stageVolumeForBlock STAGE_UNSTAGE_VOLUME capability not set. Skipping MountDevice..."))
|
||||
@ -119,8 +118,7 @@ func (m *csiBlockMapper) stageVolumeForBlock(
|
||||
|
||||
// Creating a stagingPath directory before call to NodeStageVolume
|
||||
if err := os.MkdirAll(stagingPath, 0750); err != nil {
|
||||
klog.Error(log("blockMapper.stageVolumeForBlock failed to create dir %s: %v", stagingPath, err))
|
||||
return "", err
|
||||
return "", errors.New(log("blockMapper.stageVolumeForBlock failed to create dir %s: %v", stagingPath, err))
|
||||
}
|
||||
klog.V(4).Info(log("blockMapper.stageVolumeForBlock created stagingPath directory successfully [%s]", stagingPath))
|
||||
|
||||
@ -138,8 +136,7 @@ func (m *csiBlockMapper) stageVolumeForBlock(
|
||||
nil /* MountOptions */)
|
||||
|
||||
if err != nil {
|
||||
klog.Error(log("blockMapper.stageVolumeForBlock failed: %v", err))
|
||||
return "", err
|
||||
return "", errors.New(log("blockMapper.stageVolumeForBlock failed: %v", err))
|
||||
}
|
||||
|
||||
klog.V(4).Infof(log("blockMapper.stageVolumeForBlock successfully requested NodeStageVolume [%s]", stagingPath))
|
||||
@ -167,9 +164,8 @@ func (m *csiBlockMapper) publishVolumeForBlock(
|
||||
if csiSource.NodePublishSecretRef != nil {
|
||||
nodePublishSecrets, err = getCredentialsFromSecret(m.k8s, csiSource.NodePublishSecretRef)
|
||||
if err != nil {
|
||||
klog.Errorf("blockMapper.publishVolumeForBlock failed to get NodePublishSecretRef %s/%s: %v",
|
||||
csiSource.NodePublishSecretRef.Namespace, csiSource.NodePublishSecretRef.Name, err)
|
||||
return "", err
|
||||
return "", errors.New(log("blockMapper.publishVolumeForBlock failed to get NodePublishSecretRef %s/%s: %v",
|
||||
csiSource.NodePublishSecretRef.Namespace, csiSource.NodePublishSecretRef.Name, err))
|
||||
}
|
||||
}
|
||||
|
||||
@ -177,8 +173,7 @@ func (m *csiBlockMapper) publishVolumeForBlock(
|
||||
// Setup a parent directory for publishPath before call to NodePublishVolume
|
||||
publishDir := filepath.Dir(publishPath)
|
||||
if err := os.MkdirAll(publishDir, 0750); err != nil {
|
||||
klog.Error(log("blockMapper.publishVolumeForBlock failed to create dir %s: %v", publishDir, err))
|
||||
return "", err
|
||||
return "", errors.New(log("blockMapper.publishVolumeForBlock failed to create dir %s: %v", publishDir, err))
|
||||
}
|
||||
klog.V(4).Info(log("blockMapper.publishVolumeForBlock created directory for publishPath successfully [%s]", publishDir))
|
||||
|
||||
@ -202,8 +197,7 @@ func (m *csiBlockMapper) publishVolumeForBlock(
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
klog.Errorf(log("blockMapper.publishVolumeForBlock failed: %v", err))
|
||||
return "", err
|
||||
return "", errors.New(log("blockMapper.publishVolumeForBlock failed: %v", err))
|
||||
}
|
||||
|
||||
return publishPath, nil
|
||||
@ -218,21 +212,18 @@ func (m *csiBlockMapper) SetUpDevice() (string, error) {
|
||||
|
||||
// Get csiSource from spec
|
||||
if m.spec == nil {
|
||||
klog.Error(log("blockMapper.SetUpDevice spec is nil"))
|
||||
return "", fmt.Errorf("spec is nil")
|
||||
return "", errors.New(log("blockMapper.SetUpDevice spec is nil"))
|
||||
}
|
||||
|
||||
csiSource, err := getCSISourceFromSpec(m.spec)
|
||||
if err != nil {
|
||||
klog.Error(log("blockMapper.SetUpDevice failed to get CSI persistent source: %v", err))
|
||||
return "", err
|
||||
return "", errors.New(log("blockMapper.SetUpDevice failed to get CSI persistent source: %v", err))
|
||||
}
|
||||
|
||||
driverName := csiSource.Driver
|
||||
skip, err := m.plugin.skipAttach(driverName)
|
||||
if err != nil {
|
||||
klog.Error(log("blockMapper.SetupDevice failed to check CSIDriver for %s: %v", driverName, err))
|
||||
return "", err
|
||||
return "", errors.New(log("blockMapper.SetupDevice failed to check CSIDriver for %s: %v", driverName, err))
|
||||
}
|
||||
|
||||
var attachment *storage.VolumeAttachment
|
||||
@ -242,8 +233,7 @@ func (m *csiBlockMapper) SetUpDevice() (string, error) {
|
||||
attachID := getAttachmentName(csiSource.VolumeHandle, csiSource.Driver, nodeName)
|
||||
attachment, err = m.k8s.StorageV1().VolumeAttachments().Get(attachID, meta.GetOptions{})
|
||||
if err != nil {
|
||||
klog.Error(log("blockMapper.SetupDevice failed to get volume attachment [id=%v]: %v", attachID, err))
|
||||
return "", err
|
||||
return "", errors.New(log("blockMapper.SetupDevice failed to get volume attachment [id=%v]: %v", attachID, err))
|
||||
}
|
||||
}
|
||||
|
||||
@ -258,8 +248,7 @@ func (m *csiBlockMapper) SetUpDevice() (string, error) {
|
||||
|
||||
csiClient, err := m.csiClientGetter.Get()
|
||||
if err != nil {
|
||||
klog.Error(log("blockMapper.SetUpDevice failed to get CSI client: %v", err))
|
||||
return "", err
|
||||
return "", errors.New(log("blockMapper.SetUpDevice failed to get CSI client: %v", err))
|
||||
}
|
||||
|
||||
// Call NodeStageVolume
|
||||
@ -291,8 +280,7 @@ func (m *csiBlockMapper) unpublishVolumeForBlock(ctx context.Context, csi csiCli
|
||||
// Driver is responsible for deleting publishPath itself.
|
||||
// If driver doesn't implement NodeUnstageVolume, detaching the block volume from the node may be done, here.
|
||||
if err := csi.NodeUnpublishVolume(ctx, m.volumeID, publishPath); err != nil {
|
||||
klog.Error(log("blockMapper.unpublishVolumeForBlock failed: %v", err))
|
||||
return err
|
||||
return errors.New(log("blockMapper.unpublishVolumeForBlock failed: %v", err))
|
||||
}
|
||||
klog.V(4).Infof(log("blockMapper.unpublishVolumeForBlock NodeUnpublished successfully [%s]", publishPath))
|
||||
|
||||
@ -304,8 +292,7 @@ func (m *csiBlockMapper) unstageVolumeForBlock(ctx context.Context, csi csiClien
|
||||
// Check whether "STAGE_UNSTAGE_VOLUME" is set
|
||||
stageUnstageSet, err := csi.NodeSupportsStageUnstage(ctx)
|
||||
if err != nil {
|
||||
klog.Error(log("blockMapper.unstageVolumeForBlock failed to check STAGE_UNSTAGE_VOLUME capability: %v", err))
|
||||
return err
|
||||
return errors.New(log("blockMapper.unstageVolumeForBlock failed to check STAGE_UNSTAGE_VOLUME capability: %v", err))
|
||||
}
|
||||
if !stageUnstageSet {
|
||||
klog.Infof(log("blockMapper.unstageVolumeForBlock STAGE_UNSTAGE_VOLUME capability not set. Skipping unstageVolumeForBlock ..."))
|
||||
@ -316,15 +303,13 @@ func (m *csiBlockMapper) unstageVolumeForBlock(ctx context.Context, csi csiClien
|
||||
// Expected implementation for driver is removing driver specific resource in stagingPath and
|
||||
// detaching the block volume from the node.
|
||||
if err := csi.NodeUnstageVolume(ctx, m.volumeID, stagingPath); err != nil {
|
||||
klog.Errorf(log("blockMapper.unstageVolumeForBlock failed: %v", err))
|
||||
return err
|
||||
return errors.New(log("blockMapper.unstageVolumeForBlock failed: %v", err))
|
||||
}
|
||||
klog.V(4).Infof(log("blockMapper.unstageVolumeForBlock NodeUnstageVolume successfully [%s]", stagingPath))
|
||||
|
||||
// Remove stagingPath directory and its contents
|
||||
if err := os.RemoveAll(stagingPath); err != nil {
|
||||
klog.Error(log("blockMapper.unstageVolumeForBlock failed to remove staging path after NodeUnstageVolume() error [%s]: %v", stagingPath, err))
|
||||
return err
|
||||
return errors.New(log("blockMapper.unstageVolumeForBlock failed to remove staging path after NodeUnstageVolume() error [%s]: %v", stagingPath, err))
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -343,8 +328,7 @@ func (m *csiBlockMapper) TearDownDevice(globalMapPath, devicePath string) error
|
||||
|
||||
csiClient, err := m.csiClientGetter.Get()
|
||||
if err != nil {
|
||||
klog.Error(log("blockMapper.TearDownDevice failed to get CSI client: %v", err))
|
||||
return err
|
||||
return errors.New(log("blockMapper.TearDownDevice failed to get CSI client: %v", err))
|
||||
}
|
||||
|
||||
// Call NodeUnpublishVolume
|
||||
|
@ -118,9 +118,7 @@ func (h *RegistrationHandler) ValidatePlugin(pluginName string, endpoint string,
|
||||
// The deprecated dir will only be allowed for a whitelisted set of old versions.
|
||||
// CSI 1.x drivers should use the /var/lib/kubelet/plugins_registry
|
||||
if !isDeprecatedSocketDirAllowed(versions) {
|
||||
err := fmt.Errorf("socket for CSI driver %q versions %v was found in a deprecated dir. Drivers implementing CSI 1.x+ must use the new dir", pluginName, versions)
|
||||
klog.Error(err)
|
||||
return err
|
||||
return errors.New(log("socket for CSI driver %q versions %v was found in a deprecated dir. Drivers implementing CSI 1.x+ must use the new dir", pluginName, versions))
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,25 +172,19 @@ func (h *RegistrationHandler) RegisterPlugin(pluginName string, endpoint string,
|
||||
|
||||
func (h *RegistrationHandler) validateVersions(callerName, pluginName string, endpoint string, versions []string) (*utilversion.Version, error) {
|
||||
if len(versions) == 0 {
|
||||
err := fmt.Errorf("%s for CSI driver %q failed. Plugin returned an empty list for supported versions", callerName, pluginName)
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
return nil, errors.New(log("%s for CSI driver %q failed. Plugin returned an empty list for supported versions", callerName, pluginName))
|
||||
}
|
||||
|
||||
// Validate version
|
||||
newDriverHighestVersion, err := highestSupportedVersion(versions)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("%s for CSI driver %q failed. None of the versions specified %q are supported. err=%v", callerName, pluginName, versions, err)
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
return nil, errors.New(log("%s for CSI driver %q failed. None of the versions specified %q are supported. err=%v", callerName, pluginName, versions, err))
|
||||
}
|
||||
|
||||
existingDriver, driverExists := csiDrivers.Get(pluginName)
|
||||
if driverExists {
|
||||
if !existingDriver.highestSupportedVersion.LessThan(newDriverHighestVersion) {
|
||||
err := fmt.Errorf("%s for CSI driver %q failed. Another driver with the same name is already registered with a higher supported version: %q", callerName, pluginName, existingDriver.highestSupportedVersion)
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
return nil, errors.New(log("%s for CSI driver %q failed. Another driver with the same name is already registered with a higher supported version: %q", callerName, pluginName, existingDriver.highestSupportedVersion))
|
||||
}
|
||||
}
|
||||
|
||||
@ -254,7 +246,7 @@ func (p *csiPlugin) Init(host volume.VolumeHost) error {
|
||||
// This function prevents Kubelet from posting Ready status until CSINodeInfo
|
||||
// is both installed and initialized
|
||||
if err := initializeCSINode(host); err != nil {
|
||||
return fmt.Errorf("failed to initialize CSINodeInfo: %v", err)
|
||||
return errors.New(log("failed to initialize CSINodeInfo: %v", err))
|
||||
}
|
||||
}
|
||||
|
||||
@ -321,8 +313,7 @@ func (p *csiPlugin) GetPluginName() string {
|
||||
func (p *csiPlugin) GetVolumeName(spec *volume.Spec) (string, error) {
|
||||
csi, err := getPVSourceFromSpec(spec)
|
||||
if err != nil {
|
||||
klog.Error(log("plugin.GetVolumeName failed to extract volume source from spec: %v", err))
|
||||
return "", err
|
||||
return "", errors.New(log("plugin.GetVolumeName failed to extract volume source from spec: %v", err))
|
||||
}
|
||||
|
||||
// return driverName<separator>volumeHandle
|
||||
@ -379,7 +370,7 @@ func (p *csiPlugin) NewMounter(
|
||||
volumeHandle = pvSrc.VolumeHandle
|
||||
readOnly = spec.ReadOnly
|
||||
default:
|
||||
return nil, fmt.Errorf("volume source not found in volume.Spec")
|
||||
return nil, errors.New(log("volume source not found in volume.Spec"))
|
||||
}
|
||||
|
||||
csiVolumeMode, err := p.getCSIVolumeMode(spec)
|
||||
@ -394,14 +385,12 @@ func (p *csiPlugin) NewMounter(
|
||||
|
||||
k8s := p.host.GetKubeClient()
|
||||
if k8s == nil {
|
||||
klog.Error(log("failed to get a kubernetes client"))
|
||||
return nil, errors.New("failed to get a Kubernetes client")
|
||||
return nil, errors.New(log("failed to get a kubernetes client"))
|
||||
}
|
||||
|
||||
kvh, ok := p.host.(volume.KubeletVolumeHost)
|
||||
if !ok {
|
||||
klog.Error(log("cast from VolumeHost to KubeletVolumeHost failed"))
|
||||
return nil, errors.New("cast from VolumeHost to KubeletVolumeHost failed")
|
||||
return nil, errors.New(log("cast from VolumeHost to KubeletVolumeHost failed"))
|
||||
}
|
||||
|
||||
mounter := &csiMountMgr{
|
||||
@ -424,8 +413,7 @@ func (p *csiPlugin) NewMounter(
|
||||
dataDir := path.Dir(dir) // dropoff /mount at end
|
||||
|
||||
if err := os.MkdirAll(dataDir, 0750); err != nil {
|
||||
klog.Error(log("failed to create dir %#v: %v", dataDir, err))
|
||||
return nil, err
|
||||
return nil, errors.New(log("failed to create dir %#v: %v", dataDir, err))
|
||||
}
|
||||
klog.V(4).Info(log("created path successfully [%s]", dataDir))
|
||||
|
||||
@ -445,11 +433,10 @@ func (p *csiPlugin) NewMounter(
|
||||
volData[volDataKey.attachmentID] = attachID
|
||||
|
||||
if err := saveVolumeData(dataDir, volDataFileName, volData); err != nil {
|
||||
klog.Error(log("failed to save volume info data: %v", err))
|
||||
if removeErr := os.RemoveAll(dataDir); removeErr != nil {
|
||||
klog.Error(log("failed to remove dir after error [%s]: %v", dataDir, removeErr))
|
||||
}
|
||||
return nil, err
|
||||
return nil, errors.New(log("failed to save volume info data: %v", err))
|
||||
}
|
||||
|
||||
klog.V(4).Info(log("mounter created successfully"))
|
||||
@ -462,8 +449,7 @@ func (p *csiPlugin) NewUnmounter(specName string, podUID types.UID) (volume.Unmo
|
||||
|
||||
kvh, ok := p.host.(volume.KubeletVolumeHost)
|
||||
if !ok {
|
||||
klog.Error(log("cast from VolumeHost to KubeletVolumeHost failed"))
|
||||
return nil, errors.New("cast from VolumeHost to KubeletVolumeHost failed")
|
||||
return nil, errors.New(log("cast from VolumeHost to KubeletVolumeHost failed"))
|
||||
}
|
||||
|
||||
unmounter := &csiMountMgr{
|
||||
@ -478,8 +464,7 @@ func (p *csiPlugin) NewUnmounter(specName string, podUID types.UID) (volume.Unmo
|
||||
dataDir := path.Dir(dir) // dropoff /mount at end
|
||||
data, err := loadVolumeData(dataDir, volDataFileName)
|
||||
if err != nil {
|
||||
klog.Error(log("unmounter failed to load volume data file [%s]: %v", dir, err))
|
||||
return nil, err
|
||||
return nil, errors.New(log("unmounter failed to load volume data file [%s]: %v", dir, err))
|
||||
}
|
||||
unmounter.driverName = csiDriverName(data[volDataKey.driverName])
|
||||
unmounter.volumeID = data[volDataKey.volHandle]
|
||||
@ -493,8 +478,7 @@ func (p *csiPlugin) ConstructVolumeSpec(volumeName, mountPath string) (*volume.S
|
||||
|
||||
volData, err := loadVolumeData(mountPath, volDataFileName)
|
||||
if err != nil {
|
||||
klog.Error(log("plugin.ConstructVolumeSpec failed loading volume data using [%s]: %v", mountPath, err))
|
||||
return nil, err
|
||||
return nil, errors.New(log("plugin.ConstructVolumeSpec failed loading volume data using [%s]: %v", mountPath, err))
|
||||
}
|
||||
|
||||
klog.V(4).Info(log("plugin.ConstructVolumeSpec extracted [%#v]", volData))
|
||||
@ -659,8 +643,7 @@ func (p *csiPlugin) NewBlockVolumeMapper(spec *volume.Spec, podRef *api.Pod, opt
|
||||
|
||||
k8s := p.host.GetKubeClient()
|
||||
if k8s == nil {
|
||||
klog.Error(log("failed to get a kubernetes client"))
|
||||
return nil, errors.New("failed to get a Kubernetes client")
|
||||
return nil, errors.New(log("failed to get a kubernetes client"))
|
||||
}
|
||||
|
||||
mapper := &csiBlockMapper{
|
||||
@ -679,8 +662,7 @@ func (p *csiPlugin) NewBlockVolumeMapper(spec *volume.Spec, podRef *api.Pod, opt
|
||||
dataDir := getVolumeDeviceDataDir(spec.Name(), p.host)
|
||||
|
||||
if err := os.MkdirAll(dataDir, 0750); err != nil {
|
||||
klog.Error(log("failed to create data dir %s: %v", dataDir, err))
|
||||
return nil, err
|
||||
return nil, errors.New(log("failed to create data dir %s: %v", dataDir, err))
|
||||
}
|
||||
klog.V(4).Info(log("created path successfully [%s]", dataDir))
|
||||
|
||||
@ -696,11 +678,10 @@ func (p *csiPlugin) NewBlockVolumeMapper(spec *volume.Spec, podRef *api.Pod, opt
|
||||
}
|
||||
|
||||
if err := saveVolumeData(dataDir, volDataFileName, volData); err != nil {
|
||||
klog.Error(log("failed to save volume info data: %v", err))
|
||||
if removeErr := os.RemoveAll(dataDir); removeErr != nil {
|
||||
klog.Error(log("failed to remove dir after error [%s]: %v", dataDir, removeErr))
|
||||
}
|
||||
return nil, err
|
||||
return nil, errors.New(log("failed to save volume info data: %v", err))
|
||||
}
|
||||
|
||||
return mapper, nil
|
||||
@ -722,8 +703,7 @@ func (p *csiPlugin) NewBlockVolumeUnmapper(volName string, podUID types.UID) (vo
|
||||
dataDir := getVolumeDeviceDataDir(unmapper.specName, p.host)
|
||||
data, err := loadVolumeData(dataDir, volDataFileName)
|
||||
if err != nil {
|
||||
klog.Error(log("unmapper failed to load volume data file [%s]: %v", dataDir, err))
|
||||
return nil, err
|
||||
return nil, errors.New(log("unmapper failed to load volume data file [%s]: %v", dataDir, err))
|
||||
}
|
||||
unmapper.driverName = csiDriverName(data[volDataKey.driverName])
|
||||
unmapper.volumeID = data[volDataKey.volHandle]
|
||||
@ -742,8 +722,7 @@ func (p *csiPlugin) ConstructBlockVolumeSpec(podUID types.UID, specVolName, mapP
|
||||
dataDir := getVolumeDeviceDataDir(specVolName, p.host)
|
||||
volData, err := loadVolumeData(dataDir, volDataFileName)
|
||||
if err != nil {
|
||||
klog.Error(log("plugin.ConstructBlockVolumeSpec failed loading volume data using [%s]: %v", mapPath, err))
|
||||
return nil, err
|
||||
return nil, errors.New(log("plugin.ConstructBlockVolumeSpec failed loading volume data using [%s]: %v", mapPath, err))
|
||||
}
|
||||
|
||||
klog.V(4).Info(log("plugin.ConstructBlockVolumeSpec extracted [%#v]", volData))
|
||||
@ -841,8 +820,7 @@ func (p *csiPlugin) getPublishContext(client clientset.Interface, handle, driver
|
||||
func (p *csiPlugin) newAttacherDetacher() (*csiAttacher, error) {
|
||||
k8s := p.host.GetKubeClient()
|
||||
if k8s == nil {
|
||||
klog.Error(log("unable to get kubernetes client from host"))
|
||||
return nil, errors.New("unable to get Kubernetes client")
|
||||
return nil, errors.New(log("unable to get kubernetes client from host"))
|
||||
}
|
||||
|
||||
return &csiAttacher{
|
||||
@ -856,8 +834,7 @@ func unregisterDriver(driverName string) error {
|
||||
csiDrivers.Delete(driverName)
|
||||
|
||||
if err := nim.UninstallCSIDriver(driverName); err != nil {
|
||||
klog.Errorf("Error uninstalling CSI driver: %v", err)
|
||||
return err
|
||||
return errors.New(log("Error uninstalling CSI driver: %v", err))
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -866,7 +843,7 @@ func unregisterDriver(driverName string) error {
|
||||
// Return the highest supported version
|
||||
func highestSupportedVersion(versions []string) (*utilversion.Version, error) {
|
||||
if len(versions) == 0 {
|
||||
return nil, fmt.Errorf("CSI driver reporting empty array for supported versions")
|
||||
return nil, errors.New(log("CSI driver reporting empty array for supported versions"))
|
||||
}
|
||||
|
||||
// Sort by lowest to highest version
|
||||
@ -897,7 +874,7 @@ func highestSupportedVersion(versions []string) (*utilversion.Version, error) {
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("None of the CSI versions reported by this driver are supported")
|
||||
return nil, errors.New(log("None of the CSI versions reported by this driver are supported"))
|
||||
}
|
||||
|
||||
// Only drivers that implement CSI 0.x are allowed to use deprecated socket dir.
|
||||
|
@ -18,6 +18,7 @@ package csi
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -44,8 +45,7 @@ func getCredentialsFromSecret(k8s kubernetes.Interface, secretRef *api.SecretRef
|
||||
credentials := map[string]string{}
|
||||
secret, err := k8s.CoreV1().Secrets(secretRef.Namespace).Get(secretRef.Name, meta.GetOptions{})
|
||||
if err != nil {
|
||||
klog.Errorf("failed to find the secret %s in the namespace %s with error: %v\n", secretRef.Name, secretRef.Namespace, err)
|
||||
return credentials, err
|
||||
return credentials, errors.New(log("failed to find the secret %s in the namespace %s with error: %v", secretRef.Name, secretRef.Namespace, err))
|
||||
}
|
||||
for key, value := range secret.Data {
|
||||
credentials[key] = string(value)
|
||||
@ -60,13 +60,11 @@ func saveVolumeData(dir string, fileName string, data map[string]string) error {
|
||||
klog.V(4).Info(log("saving volume data file [%s]", dataFilePath))
|
||||
file, err := os.Create(dataFilePath)
|
||||
if err != nil {
|
||||
klog.Error(log("failed to save volume data file %s: %v", dataFilePath, err))
|
||||
return err
|
||||
return errors.New(log("failed to save volume data file %s: %v", dataFilePath, err))
|
||||
}
|
||||
defer file.Close()
|
||||
if err := json.NewEncoder(file).Encode(data); err != nil {
|
||||
klog.Error(log("failed to save volume data file %s: %v", dataFilePath, err))
|
||||
return err
|
||||
return errors.New(log("failed to save volume data file %s: %v", dataFilePath, err))
|
||||
}
|
||||
klog.V(4).Info(log("volume data file saved successfully [%s]", dataFilePath))
|
||||
return nil
|
||||
@ -80,14 +78,12 @@ func loadVolumeData(dir string, fileName string) (map[string]string, error) {
|
||||
|
||||
file, err := os.Open(dataFileName)
|
||||
if err != nil {
|
||||
klog.Error(log("failed to open volume data file [%s]: %v", dataFileName, err))
|
||||
return nil, err
|
||||
return nil, errors.New(log("failed to open volume data file [%s]: %v", dataFileName, err))
|
||||
}
|
||||
defer file.Close()
|
||||
data := map[string]string{}
|
||||
if err := json.NewDecoder(file).Decode(&data); err != nil {
|
||||
klog.Error(log("failed to parse volume data file [%s]: %v", dataFileName, err))
|
||||
return nil, err
|
||||
return nil, errors.New(log("failed to parse volume data file [%s]: %v", dataFileName, err))
|
||||
}
|
||||
|
||||
return data, nil
|
||||
|
@ -18,6 +18,7 @@ package csi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
api "k8s.io/api/core/v1"
|
||||
@ -44,8 +45,7 @@ func (c *csiPlugin) NodeExpand(resizeOptions volume.NodeResizeOptions) (bool, er
|
||||
klog.V(4).Infof(log("Expander.NodeExpand(%s)", resizeOptions.DeviceMountPath))
|
||||
csiSource, err := getCSISourceFromSpec(resizeOptions.VolumeSpec)
|
||||
if err != nil {
|
||||
klog.Error(log("Expander.NodeExpand failed to get CSI persistent source: %v", err))
|
||||
return false, err
|
||||
return false, errors.New(log("Expander.NodeExpand failed to get CSI persistent source: %v", err))
|
||||
}
|
||||
|
||||
csClient, err := newCsiDriverClient(csiDriverName(csiSource.Driver))
|
||||
|
Loading…
Reference in New Issue
Block a user