From f17f00363b278c00767a050be464d167a09be458 Mon Sep 17 00:00:00 2001 From: Roman Bednar Date: Tue, 8 Mar 2022 12:14:56 +0100 Subject: [PATCH] csi_attacher: improve attach/detach timeout message If we time out waiting for volume to be attached the message given to user is not informative enough: "Attach timeout for volume vol-123" It would be better if we provide more information on what's going on and even include name of the driver that's causing the problem, e.g.: "timed out waiting for external-attacher of ebs.csi.aws.com CSI driver to attach volume vol-123" --- pkg/volume/csi/csi_attacher.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/pkg/volume/csi/csi_attacher.go b/pkg/volume/csi/csi_attacher.go index 621cd3ce894..11de3c558bc 100644 --- a/pkg/volume/csi/csi_attacher.go +++ b/pkg/volume/csi/csi_attacher.go @@ -133,7 +133,7 @@ func (c *csiAttacher) Attach(spec *volume.Spec, nodeName types.NodeName) (string // Attach and detach functionality is exclusive to the CSI plugin that runs in the AttachDetachController, // and has access to a VolumeAttachment lister that can be polled for the current status. - if err := c.waitForVolumeAttachmentWithLister(pvSrc.VolumeHandle, attachID, c.watchTimeout); err != nil { + if err := c.waitForVolumeAttachmentWithLister(spec, pvSrc.VolumeHandle, attachID, c.watchTimeout); err != nil { return "", err } @@ -178,7 +178,7 @@ func (c *csiAttacher) waitForVolumeAttachmentInternal(volumeHandle, attachID str return attach.Name, nil } -func (c *csiAttacher) waitForVolumeAttachmentWithLister(volumeHandle, attachID string, timeout time.Duration) error { +func (c *csiAttacher) waitForVolumeAttachmentWithLister(spec *volume.Spec, volumeHandle, attachID string, timeout time.Duration) error { klog.V(4).Info(log("probing VolumeAttachment [id=%v]", attachID)) verifyStatus := func() (bool, error) { @@ -201,7 +201,7 @@ func (c *csiAttacher) waitForVolumeAttachmentWithLister(volumeHandle, attachID s return successful, nil } - return c.waitForVolumeAttachDetachStatusWithLister(volumeHandle, attachID, timeout, verifyStatus, "Attach") + return c.waitForVolumeAttachDetachStatusWithLister(spec, volumeHandle, attachID, timeout, verifyStatus, "Attach") } func (c *csiAttacher) VolumesAreAttached(specs []*volume.Spec, nodeName types.NodeName) (map[*volume.Spec]bool, error) { @@ -473,10 +473,10 @@ func (c *csiAttacher) waitForVolumeDetachmentWithLister(volumeHandle, attachID s return successful, nil } - return c.waitForVolumeAttachDetachStatusWithLister(volumeHandle, attachID, timeout, verifyStatus, "Detach") + return c.waitForVolumeAttachDetachStatusWithLister(nil, volumeHandle, attachID, timeout, verifyStatus, "Detach") } -func (c *csiAttacher) waitForVolumeAttachDetachStatusWithLister(volumeHandle, attachID string, timeout time.Duration, verifyStatus func() (bool, error), operation string) error { +func (c *csiAttacher) waitForVolumeAttachDetachStatusWithLister(spec *volume.Spec, volumeHandle, attachID string, timeout time.Duration, verifyStatus func() (bool, error), operation string) error { var ( initBackoff = 500 * time.Millisecond // This is approximately the duration between consecutive ticks after two minutes (CSI timeout). @@ -491,6 +491,13 @@ func (c *csiAttacher) waitForVolumeAttachDetachStatusWithLister(volumeHandle, at ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() + // Get driver name from spec for better log messages. During detach spec can be nil, and it's ok for driver to be unknown. + csiDriverName, err := GetCSIDriverName(spec) + if err != nil { + csiDriverName = "unknown" + klog.V(4).Info(log("Could not find CSI driver name in spec for volume [%v]", volumeHandle)) + } + for { t := backoffMgr.Backoff() select { @@ -505,7 +512,7 @@ func (c *csiAttacher) waitForVolumeAttachDetachStatusWithLister(volumeHandle, at case <-ctx.Done(): t.Stop() klog.Error(log("%s timeout after %v [volume=%v; attachment.ID=%v]", operation, timeout, volumeHandle, attachID)) - return fmt.Errorf("%s timeout for volume %v", operation, volumeHandle) + return fmt.Errorf("timed out waiting for external-attacher of %v CSI driver to %v volume %v", csiDriverName, strings.ToLower(operation), volumeHandle) } } }