diff --git a/pkg/volume/csi/csi_attacher.go b/pkg/volume/csi/csi_attacher.go index 494e46d8eb0..c3f2213558c 100644 --- a/pkg/volume/csi/csi_attacher.go +++ b/pkg/volume/csi/csi_attacher.go @@ -413,30 +413,17 @@ func (c *csiAttacher) Detach(volumeName string, nodeName types.NodeName) error { return errors.New("missing expected parameter volumeName") } - if isAttachmentName(volumeName) { - // Detach can also be called with the attach ID as the `volumeName`. This codepath is - // hit only when we have migrated an in-tree volume to CSI and the A/D Controller is shut - // down, the pod with the volume is deleted, and the A/D Controller starts back up in that - // order. - attachID = volumeName - - // Vol ID should be the volume handle, except that is not available here. - // It is only used in log messages so in the event that this happens log messages will be - // printing out the attachID instead of the volume handle. - volID = volumeName - } else { - // volumeName in format driverNamevolumeHandle generated by plugin.GetVolumeName() - parts := strings.Split(volumeName, volNameSep) - if len(parts) != 2 { - klog.Error(log("detacher.Detach insufficient info encoded in volumeName")) - return errors.New("volumeName missing expected data") - } - - driverName := parts[0] - volID = parts[1] - attachID = getAttachmentName(volID, driverName, string(nodeName)) + // volumeName in format driverNamevolumeHandle generated by plugin.GetVolumeName() + parts := strings.Split(volumeName, volNameSep) + if len(parts) != 2 { + klog.Error(log("detacher.Detach insufficient info encoded in volumeName")) + return errors.New("volumeName missing expected data") } + driverName := parts[0] + volID = parts[1] + attachID = getAttachmentName(volID, driverName, string(nodeName)) + if err := c.k8s.StorageV1().VolumeAttachments().Delete(context.TODO(), attachID, metav1.DeleteOptions{}); err != nil { if apierrors.IsNotFound(err) { // object deleted or never existed, done @@ -641,13 +628,6 @@ func getAttachmentName(volName, csiDriverName, nodeName string) string { return fmt.Sprintf("csi-%x", result) } -// isAttachmentName returns true if the string given is of the form of an Attach ID -// and false otherwise -func isAttachmentName(unknownString string) bool { - // 68 == "csi-" + len(sha256hash) - return strings.HasPrefix(unknownString, "csi-") && len(unknownString) == 68 -} - func makeDeviceMountPath(plugin *csiPlugin, spec *volume.Spec) (string, error) { if spec == nil { return "", errors.New(log("makeDeviceMountPath failed, spec is nil"))