Skip to content

Commit cbe4b86

Browse files
fix(csi): return gRPC errors when post-Publish VMI readiness check cannot run
The fallback branches in publishHotplugVolume silently returned the upstream success response when the node ID failed to parse or the VMI get call returned an error. external-attacher then set Attached=true without VolumeReady proof, which recreates the false-positive attach this wrapper exists to prevent. Fail loudly instead: - parseErr -> codes.Internal: external-attacher is expected to provide a well-formed "namespace/name" node ID per the CSI contract; if it does not, surface the contract violation rather than mask it. - getErr -> codes.Unavailable: this is the same code returned for the not-Ready and not-present cases just below, so the retry behavior on the attacher side stays consistent. By the time we reach this branch the upstream Publish call already succeeded, which means it just looked the VMI up; a transient get error here is a race or API hiccup and a retry is safe. Also add a one-line comment on GetVirtualMachine: in the upstream kubevirt.io/csi-driver client this method returns a VirtualMachineInstance despite its name, so accessing vmi.Status.VolumeStatus on the result is type-correct. Assisted-By: Claude <[email protected]> Signed-off-by: Myasnikov Daniil <[email protected]>
1 parent 5bb5e95 commit cbe4b86

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

‎packages/apps/kubernetes/images/kubevirt-csi-driver/controller.go‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,17 @@ func (w *WrappedControllerService) publishHotplugVolume(ctx context.Context, req
257257

258258
vmNamespace, vmName, parseErr := cache.SplitMetaNamespaceKey(req.GetNodeId())
259259
if parseErr != nil {
260-
klog.Warningf("Cannot verify VMI readiness after publish: failed to parse node ID %q: %v", req.GetNodeId(), parseErr)
261-
return resp, nil
260+
return nil, status.Errorf(codes.Internal,
261+
"cannot verify VMI readiness after publish: failed to parse node ID %q: %v",
262+
req.GetNodeId(), parseErr)
262263
}
263264
dvName := req.GetVolumeId()
265+
// GetVirtualMachine on this client returns a VirtualMachineInstance, not a VM.
264266
vmi, getErr := w.virtClient.GetVirtualMachine(ctx, vmNamespace, vmName)
265267
if getErr != nil {
266-
klog.Warningf("Cannot verify VMI %s/%s readiness after publish of %s: %v", vmNamespace, vmName, dvName, getErr)
267-
return resp, nil
268+
return nil, status.Errorf(codes.Unavailable,
269+
"cannot verify VMI %s/%s readiness after publish of %s: %v",
270+
vmNamespace, vmName, dvName, getErr)
268271
}
269272
for _, vs := range vmi.Status.VolumeStatus {
270273
if vs.Name != dvName {

0 commit comments

Comments
 (0)