Skip to content

Commit 6dc0c87

Browse files
committed
refactor(discover): move dedup maps outside node loop
Deduplication maps for BMC managers and Systems were declared within the loop that iterates over each node, which is where duplication checks happen. This is obviously futile, so the declarations are moved outside of the loop so that the checks occur properly. Most testing has used a single unique BMC per node, which is probably why this was not caught earlier. Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
1 parent b887949 commit 6dc0c87

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

pkg/discover/discover.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,11 @@ func DiscoveryInfoV2(baseURI string, nl NodeList) (smd.ComponentSlice, smd.Redfi
113113
return comps, rfes, ifaces, fmt.Errorf("invalid URI: %s", baseURI)
114114
}
115115

116-
// Deduplication map for Components
117-
compMap := make(map[string]string)
116+
var (
117+
compMap = make(map[string]string) // Deduplication map for SMD Components
118+
systemMap = make(map[string]string) // Deduplication map for BMC Systems
119+
managerMap = make(map[string]string) // Deduplication map for BMC Managers
120+
)
118121
for _, node := range nl.Nodes {
119122
log.Logger.Debug().Msgf("generating component structure for node with xname %s", node.Xname)
120123
if _, ok := compMap[node.Xname]; !ok {
@@ -150,10 +153,6 @@ func DiscoveryInfoV2(baseURI string, nl NodeList) (smd.ComponentSlice, smd.Redfi
150153
rfe.IPAddress = node.BMCIP
151154
rfe.SchemaVersion = 1 // Tells SMD to use new (v2) parsing code
152155

153-
// Deduplication maps for fake BMC Managers and Systems
154-
systemMap := make(map[string]string)
155-
managerMap := make(map[string]string)
156-
157156
// Create fake BMC "System" for node if it doesn't already exist
158157
if _, ok := systemMap[node.Xname]; !ok {
159158
log.Logger.Debug().Msgf("node %s: generating fake BMC System", node.Xname)

0 commit comments

Comments
 (0)