diff --git a/agent/csi/plugin/plugin.go b/agent/csi/plugin/plugin.go index a721ac25a8..e81521c77e 100644 --- a/agent/csi/plugin/plugin.go +++ b/agent/csi/plugin/plugin.go @@ -394,10 +394,18 @@ func (np *nodePlugin) makeSecrets(v *api.VolumeAssignment) map[string]string { // makeNodeInfo converts a csi.NodeGetInfoResponse object into a swarmkit NodeCSIInfo // object. func makeNodeInfo(csiNodeInfo *csi.NodeGetInfoResponse) *api.NodeCSIInfo { - return &api.NodeCSIInfo{ - NodeID: csiNodeInfo.NodeId, - MaxVolumesPerNode: csiNodeInfo.MaxVolumesPerNode, - } + nodeInfo := &api.NodeCSIInfo{ + NodeID: csiNodeInfo.NodeId, + MaxVolumesPerNode: csiNodeInfo.MaxVolumesPerNode, + } + + if topology := csiNodeInfo.GetAccessibleTopology(); topology != nil { + nodeInfo.AccessibleTopology = &api.Topology{ + Segments: topology.GetSegments(), + } + } + + return nodeInfo } // stagePath returns the staging path for a given volume assignment diff --git a/agent/csi/plugin/plugin_test.go b/agent/csi/plugin/plugin_test.go index 0e312c5080..be2c4bd09f 100644 --- a/agent/csi/plugin/plugin_test.go +++ b/agent/csi/plugin/plugin_test.go @@ -5,6 +5,7 @@ import ( "net" "testing" + "github.com/container-storage-interface/spec/lib/go/csi" "github.com/moby/swarmkit/v2/api" "github.com/moby/swarmkit/v2/testutils" @@ -27,6 +28,30 @@ func newVolumeClient(name string, nodeID string) *nodePlugin { return n } +func TestMakeNodeInfo(t *testing.T) { + csiNodeInfo := &csi.NodeGetInfoResponse{ + NodeId: "node-1", + MaxVolumesPerNode: 26, + AccessibleTopology: &csi.Topology{ + Segments: map[string]string{ + "topology.kubernetes.io/zone": "eu-central-1a", + }, + }, + } + + expected := &api.NodeCSIInfo{ + NodeID: "node-1", + MaxVolumesPerNode: 26, + AccessibleTopology: &api.Topology{ + Segments: map[string]string{ + "topology.kubernetes.io/zone": "eu-central-1a", + }, + }, + } + + assert.Equal(t, expected, makeNodeInfo(csiNodeInfo)) +} + func TestNodeStageVolume(t *testing.T) { plugin := "plugin-1" node := "node-1"