]> git.feebdaed.xyz Git - 0xmirror/kubernetes.git/commitdiff
Fix VolumeAttachment cleanup when AttachRequired changes
authorhongkang <mzhkcj50@gmail.com>
Sat, 11 Jan 2025 16:10:02 +0000 (00:10 +0800)
committerhongkang <mzhkcj50@gmail.com>
Fri, 19 Dec 2025 07:51:45 +0000 (15:51 +0800)
When CSI's AttachRequired changes from true to false after a successful
volume attach, MarkVolumeAsAttached fails because it attempts to look up
the plugin by spec, which fails verification.
This patch passes the VolumeName directly to MarkVolumeAsAttached.
This allows the function to skip the plugin lookup and correctly mark
the volume as attached in the Actual State of World, ensuring
VolumeAttachment cleanup can proceed.

Signed-off-by: hongkang <mzhkcj50@gmail.com>
pkg/volume/util/operationexecutor/operation_generator.go

index 9d5c937d95372a5ad0bb1caaae9b1bddffc80bef..2707f7034483d6379dba83d8504dac0a3e5b0086 100644 (file)
@@ -290,22 +290,22 @@ func (og *operationGenerator) GenerateAttachVolumeFunc(
                        return volumetypes.NewOperationContext(eventErr, detailedErr, migrated)
                }
 
-               // Successful attach event is useful for user debugging
-               simpleMsg, _ := volumeToAttach.GenerateMsg("AttachVolume.Attach succeeded", "")
-               for _, pod := range volumeToAttach.ScheduledPods {
-                       og.recorder.Eventf(pod, v1.EventTypeNormal, kevents.SuccessfulAttachVolume, simpleMsg)
-               }
-               klog.Info(volumeToAttach.GenerateMsgDetailed("AttachVolume.Attach succeeded", ""))
-
                // Update actual state of world
                addVolumeNodeErr := actualStateOfWorld.MarkVolumeAsAttached(
-                       logger, v1.UniqueVolumeName(""), volumeToAttach.VolumeSpec, volumeToAttach.NodeName, devicePath)
+                       logger, volumeToAttach.VolumeName, volumeToAttach.VolumeSpec, volumeToAttach.NodeName, devicePath)
                if addVolumeNodeErr != nil {
                        // On failure, return error. Caller will log and retry.
                        eventErr, detailedErr := volumeToAttach.GenerateError("AttachVolume.MarkVolumeAsAttached failed", addVolumeNodeErr)
                        return volumetypes.NewOperationContext(eventErr, detailedErr, migrated)
                }
 
+               // Successful attach event is useful for user debugging
+               simpleMsg, _ := volumeToAttach.GenerateMsg("AttachVolume.Attach succeeded", "")
+               for _, pod := range volumeToAttach.ScheduledPods {
+                       og.recorder.Eventf(pod, v1.EventTypeNormal, kevents.SuccessfulAttachVolume, simpleMsg)
+               }
+               klog.Info(volumeToAttach.GenerateMsgDetailed("AttachVolume.Attach succeeded", ""))
+
                return volumetypes.NewOperationContext(nil, nil, migrated)
        }