Remove AttachID matching from Detach

Detach() always gets CSI volume unique ID and never attachment ID. Related
code has been removed from Kubernetes in
129f15328b.
This commit is contained in:
Jan Safranek 2021-12-14 15:35:14 +01:00
parent c83a94da72
commit 516633d67f

View File

@ -413,18 +413,6 @@ 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 driverName<SEP>volumeHandle generated by plugin.GetVolumeName()
parts := strings.Split(volumeName, volNameSep)
if len(parts) != 2 {
@ -435,7 +423,6 @@ func (c *csiAttacher) Detach(volumeName string, nodeName types.NodeName) error {
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) {
@ -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"))