From ee85b6a579f4d2c45705038c766833ecfc212a66 Mon Sep 17 00:00:00 2001 From: Jan Safranek Date: Fri, 13 Dec 2019 14:54:55 +0100 Subject: [PATCH] Don't report deletion of attached volume as warning It is part of normal cluster operation. When a pod and PVC are deleted at the same time (e.g. because of the whole namespace was deleted), PV controller may try to delete a volume that is still detached. "Warning" is too strong here, it is going to heal relatively quickly. --- .../src/k8s.io/cloud-provider/volume/errors/errors.go | 10 ++++++++++ staging/src/k8s.io/legacy-cloud-providers/aws/aws.go | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/staging/src/k8s.io/cloud-provider/volume/errors/errors.go b/staging/src/k8s.io/cloud-provider/volume/errors/errors.go index 5202b4eb310..2e5adb1769d 100644 --- a/staging/src/k8s.io/cloud-provider/volume/errors/errors.go +++ b/staging/src/k8s.io/cloud-provider/volume/errors/errors.go @@ -65,3 +65,13 @@ func NewDanglingError(msg string, node k8stypes.NodeName, devicePath string) err DevicePath: devicePath, } } + +// IsDanglingError returns true if an error is DanglingAttachError +func IsDanglingError(err error) bool { + switch err.(type) { + case *DanglingAttachError: + return true + default: + return false + } +} diff --git a/staging/src/k8s.io/legacy-cloud-providers/aws/aws.go b/staging/src/k8s.io/legacy-cloud-providers/aws/aws.go index fdb387f46e2..7dc271e5ac3 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/aws/aws.go +++ b/staging/src/k8s.io/legacy-cloud-providers/aws/aws.go @@ -2578,6 +2578,10 @@ func (c *Cloud) DeleteDisk(volumeName KubernetesVolumeID) (bool, error) { klog.V(2).Infof("Volume %s not found when deleting it, assuming it's deleted", awsDisk.awsID) return false, nil } + if volerr.IsDanglingError(err) { + // The volume is still attached somewhere + return false, volerr.NewDeletedVolumeInUseError(err.Error()) + } klog.Error(err) } @@ -2598,7 +2602,7 @@ func (c *Cloud) checkIfAvailable(disk *awsDisk, opName string, instance string) } volumeState := aws.StringValue(info.State) - opError := fmt.Sprintf("Error %s EBS volume %q", opName, disk.awsID) + opError := fmt.Sprintf("error %s EBS volume %q", opName, disk.awsID) if len(instance) != 0 { opError = fmt.Sprintf("%q to instance %q", opError, instance) }