From 93dcfcf53c9c2052910b993ebcaf299b084138b4 Mon Sep 17 00:00:00 2001 From: vsoch Date: Wed, 6 Mar 2024 18:28:32 -0700 Subject: [PATCH] fix: bug in containment name for node Problem: there is a small bug that the node is using the uid (larger number) instead of the name. Solution: get the name explicitly from the node to use. Signed-off-by: vsoch --- go.mod | 2 +- go.sum | 4 ++-- pkg/graph/cluster.go | 2 +- plugins/creators/cluster/cluster.go | 22 +++++++++++++++++++--- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index fa2dfa5..1a3beb1 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( github.com/akamensky/argparse v1.4.0 - github.com/converged-computing/jsongraph-go v0.0.0-20240225004212-223ddffb7565 + github.com/converged-computing/jsongraph-go v0.0.0-20240229082022-c6887a5a00fe github.com/converged-computing/nfd-source v0.0.0-20240224025007-20d686e64926 github.com/jedib0t/go-pretty/v6 v6.5.4 github.com/moby/moby v25.0.3+incompatible diff --git a/go.sum b/go.sum index 377d95e..49b26f1 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/akamensky/argparse v1.4.0 h1:YGzvsTqCvbEZhL8zZu2AiA5nq805NZh75JNj4ajn github.com/akamensky/argparse v1.4.0/go.mod h1:S5kwC7IuDcEr5VeXtGPRVZ5o/FdhcMlQz4IZQuw64xA= github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo= -github.com/converged-computing/jsongraph-go v0.0.0-20240225004212-223ddffb7565 h1:ZwJngPrF1yvM4ZGEyoT1b8h5e0qUumOxeDZLN37pPTk= -github.com/converged-computing/jsongraph-go v0.0.0-20240225004212-223ddffb7565/go.mod h1:+DhVyLXGVfBsfta4185jd33jqa94inshCcdvsXK2Irk= +github.com/converged-computing/jsongraph-go v0.0.0-20240229082022-c6887a5a00fe h1:Tk//RW3uKn4A7N8gpHRXs+ZGlR7Fxkwh+4/Iml0GBV4= +github.com/converged-computing/jsongraph-go v0.0.0-20240229082022-c6887a5a00fe/go.mod h1:+DhVyLXGVfBsfta4185jd33jqa94inshCcdvsXK2Irk= github.com/converged-computing/nfd-source v0.0.0-20240224025007-20d686e64926 h1:VZmgK3t4564vdHNpE//q6kuPlugOrojkDHP4Gqd4A1g= github.com/converged-computing/nfd-source v0.0.0-20240224025007-20d686e64926/go.mod h1:I15nBsQqBTUsc3A4a6cuQmZjQ8lYUZSZ2a7UAE5SZ3g= github.com/coreos/go-systemd/v22 v22.3.2 h1:D9/bQk5vlXQFZ6Kwuu6zaiXJ9oTPe68++AzAJc1DzSI= diff --git a/pkg/graph/cluster.go b/pkg/graph/cluster.go index 41b56ad..e20cf49 100644 --- a/pkg/graph/cluster.go +++ b/pkg/graph/cluster.go @@ -116,7 +116,7 @@ func (c *ClusterGraph) getNode( // The resource name is the type + the resource counter // path should be assembled from parents up to this node - resourceName := fmt.Sprintf("%s/%s%d", path, name, counter) + resourceName := fmt.Sprintf("%s/%s", path, nameWithCount) // New Metadata with expected fluxion data m := metadata.Metadata{} diff --git a/plugins/creators/cluster/cluster.go b/plugins/creators/cluster/cluster.go index 70088a3..31033fc 100644 --- a/plugins/creators/cluster/cluster.go +++ b/plugins/creators/cluster/cluster.go @@ -148,6 +148,14 @@ func (c ClusterCreator) Create(options plugin.PluginOptions) error { // First add the rack -> node // We only have one rack here, so hard coded id for now node := *g.AddNode("node", "node", 1, false, "", "rack0") + nodeName, err := node.Metadata.GetStringElement("name") + + // This should not happen, we just added it! + if err != nil { + fmt.Printf("node %s cannot derive name, skipping\n", nodeFile) + continue + } + g.AddEdge(rack, node, "contains") g.AddEdge(node, rack, "in") @@ -181,14 +189,22 @@ func (c ClusterCreator) Create(options plugin.PluginOptions) error { // Create each socket attached to the node // rack -> node -> socket - path := fmt.Sprintf("rack0/node%s", *node.Label) + path := fmt.Sprintf("rack0/%s", nodeName) socketNode := *g.AddNode("socket", "socket", 1, false, "", path) + socketName, err := socketNode.Metadata.GetStringElement("name") + + // This also is not going to happen + if err != nil { + fmt.Printf("socket %x cannot derive name, skipping\n", socketNode) + continue + } + g.AddEdge(node, socketNode, "contains") g.AddEdge(socketNode, node, "in") // Create each core attached to the socket - for _, _ = range chunk { - path := fmt.Sprintf("rack0/node%s/socket%s", *node.Label, *socketNode.Label) + for range chunk { + path := fmt.Sprintf("rack0/%s/%s", nodeName, socketName) coreNode := *g.AddNode("core", "core", 1, false, "", path) g.AddEdge(socketNode, coreNode, "contains") g.AddEdge(coreNode, socketNode, "in")