From cdb1293eeab249e27ad55b00249a2424b77016e0 Mon Sep 17 00:00:00 2001 From: Drew Erny Date: Fri, 23 Jun 2023 11:44:54 -0500 Subject: [PATCH] Fix missing Topology in NodeCSIInfo Added code to correctly retrieve and convert the Topology from the gRPC Swarm Node. Signed-off-by: Drew Erny --- daemon/cluster/convert/node.go | 19 ++++++--- daemon/cluster/convert/node_test.go | 60 +++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 daemon/cluster/convert/node_test.go diff --git a/daemon/cluster/convert/node.go b/daemon/cluster/convert/node.go index 4ba9c62609..2019b8cfad 100644 --- a/daemon/cluster/convert/node.go +++ b/daemon/cluster/convert/node.go @@ -58,13 +58,20 @@ func NodeFromGRPC(n swarmapi.Node) types.Node { } for _, csi := range n.Description.CSIInfo { if csi != nil { + convertedInfo := types.NodeCSIInfo{ + PluginName: csi.PluginName, + NodeID: csi.NodeID, + MaxVolumesPerNode: csi.MaxVolumesPerNode, + } + + if csi.AccessibleTopology != nil { + convertedInfo.AccessibleTopology = &types.Topology{ + Segments: csi.AccessibleTopology.Segments, + } + } + node.Description.CSIInfo = append( - node.Description.CSIInfo, - types.NodeCSIInfo{ - PluginName: csi.PluginName, - NodeID: csi.NodeID, - MaxVolumesPerNode: csi.MaxVolumesPerNode, - }, + node.Description.CSIInfo, convertedInfo, ) } } diff --git a/daemon/cluster/convert/node_test.go b/daemon/cluster/convert/node_test.go new file mode 100644 index 0000000000..2c003851af --- /dev/null +++ b/daemon/cluster/convert/node_test.go @@ -0,0 +1,60 @@ +package convert + +import ( + "testing" + + types "github.com/docker/docker/api/types/swarm" + swarmapi "github.com/moby/swarmkit/v2/api" + "gotest.tools/v3/assert" +) + +// TestNodeCSIInfoFromGRPC tests that conversion of the NodeCSIInfo from the +// gRPC to the Docker types is correct. +func TestNodeCSIInfoFromGRPC(t *testing.T) { + node := &swarmapi.Node{ + ID: "someID", + Description: &swarmapi.NodeDescription{ + CSIInfo: []*swarmapi.NodeCSIInfo{ + &swarmapi.NodeCSIInfo{ + PluginName: "plugin1", + NodeID: "p1n1", + MaxVolumesPerNode: 1, + }, + &swarmapi.NodeCSIInfo{ + PluginName: "plugin2", + NodeID: "p2n1", + MaxVolumesPerNode: 2, + AccessibleTopology: &swarmapi.Topology{ + Segments: map[string]string{ + "a": "1", + "b": "2", + }, + }, + }, + }, + }, + } + + expected := []types.NodeCSIInfo{ + { + PluginName: "plugin1", + NodeID: "p1n1", + MaxVolumesPerNode: 1, + }, + { + PluginName: "plugin2", + NodeID: "p2n1", + MaxVolumesPerNode: 2, + AccessibleTopology: &types.Topology{ + Segments: map[string]string{ + "a": "1", + "b": "2", + }, + }, + }, + } + + actual := NodeFromGRPC(*node) + + assert.DeepEqual(t, actual.Description.CSIInfo, expected) +}