Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[24.0 backport] Fix missing Topology in NodeCSIInfo #45810

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 13 additions & 6 deletions daemon/cluster/convert/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
}
Expand Down
60 changes: 60 additions & 0 deletions daemon/cluster/convert/node_test.go
Original file line number Diff line number Diff line change
@@ -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)
}