Skip to content

Commit c7787c0

Browse files
committed
fix: auto-register nodes on ControllerPublishVolume
With attachRequired=true, kubelet calls ControllerPublishVolume before the node plugin registers via NodeGetInfo. The controller was rejecting these with NotFound, preventing any volume from mounting. Instead of rejecting unknown nodes, register them on first publish. The kubelet guarantees the node exists — it's the one making the call.
1 parent d907342 commit c7787c0

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

pkg/driver/controller.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -678,10 +678,11 @@ func (s *ControllerService) ControllerPublishVolume(_ context.Context, req *csi.
678678
return nil, status.Error(codes.InvalidArgument, "Volume capability is required")
679679
}
680680

681-
// Validate node exists in registry
682-
// Per CSI spec: return NotFound if node doesn't exist
683-
if s.nodeRegistry != nil && !s.nodeRegistry.IsRegistered(nodeID) {
684-
return nil, status.Errorf(codes.NotFound, "node %s not found", nodeID)
681+
// Register node on first publish — with attachRequired=true, ControllerPublishVolume
682+
// is called before the node plugin has had a chance to register via NodeGetInfo.
683+
// The kubelet guarantees the node exists (it's the one making the call).
684+
if s.nodeRegistry != nil {
685+
s.nodeRegistry.Register(nodeID)
685686
}
686687

687688
// Check if volume is already published to this node with different readonly state

pkg/driver/controller_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ func TestControllerPublishVolume(t *testing.T) {
518518
wantCode: codes.InvalidArgument,
519519
},
520520
{
521-
name: "node not found",
521+
name: "unknown node auto-registers on publish",
522522
req: &csi.ControllerPublishVolumeRequest{
523523
VolumeId: volumeID,
524524
NodeId: "unknown-node",
@@ -528,9 +528,8 @@ func TestControllerPublishVolume(t *testing.T) {
528528
},
529529
},
530530
},
531-
nodeReg: NewNodeRegistry(),
532-
wantErr: true,
533-
wantCode: codes.NotFound,
531+
nodeReg: NewNodeRegistry(),
532+
wantErr: false,
534533
},
535534
}
536535

0 commit comments

Comments
 (0)