mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #107025 from jsafrane/remove-attach-match
Remove AttachID matching from Detach
This commit is contained in:
commit
489fb9bee3
@ -413,30 +413,17 @@ func (c *csiAttacher) Detach(volumeName string, nodeName types.NodeName) error {
|
|||||||
return errors.New("missing expected parameter volumeName")
|
return errors.New("missing expected parameter volumeName")
|
||||||
}
|
}
|
||||||
|
|
||||||
if isAttachmentName(volumeName) {
|
// volumeName in format driverName<SEP>volumeHandle generated by plugin.GetVolumeName()
|
||||||
// Detach can also be called with the attach ID as the `volumeName`. This codepath is
|
parts := strings.Split(volumeName, volNameSep)
|
||||||
// hit only when we have migrated an in-tree volume to CSI and the A/D Controller is shut
|
if len(parts) != 2 {
|
||||||
// down, the pod with the volume is deleted, and the A/D Controller starts back up in that
|
klog.Error(log("detacher.Detach insufficient info encoded in volumeName"))
|
||||||
// order.
|
return errors.New("volumeName missing expected data")
|
||||||
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 {
|
|
||||||
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))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 err := c.k8s.StorageV1().VolumeAttachments().Delete(context.TODO(), attachID, metav1.DeleteOptions{}); err != nil {
|
||||||
if apierrors.IsNotFound(err) {
|
if apierrors.IsNotFound(err) {
|
||||||
// object deleted or never existed, done
|
// object deleted or never existed, done
|
||||||
@ -641,13 +628,6 @@ func getAttachmentName(volName, csiDriverName, nodeName string) string {
|
|||||||
return fmt.Sprintf("csi-%x", result)
|
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) {
|
func makeDeviceMountPath(plugin *csiPlugin, spec *volume.Spec) (string, error) {
|
||||||
if spec == nil {
|
if spec == nil {
|
||||||
return "", errors.New(log("makeDeviceMountPath failed, spec is nil"))
|
return "", errors.New(log("makeDeviceMountPath failed, spec is nil"))
|
||||||
|
Loading…
Reference in New Issue
Block a user