diff --git a/client/client.go b/client/client.go index d993903c2..12799161f 100644 --- a/client/client.go +++ b/client/client.go @@ -1569,6 +1569,12 @@ func (c *Client) setupNode() error { node.NodeResources.MinDynamicPort = newConfig.MinDynamicPort node.NodeResources.MaxDynamicPort = newConfig.MaxDynamicPort node.NodeResources.Processors = newConfig.Node.NodeResources.Processors + + if node.NodeResources.Processors.Empty() { + node.NodeResources.Processors = structs.NodeProcessorResources{ + Topology: &numalib.Topology{}, + } + } } if node.ReservedResources == nil { node.ReservedResources = &structs.NodeReservedResources{} diff --git a/client/lib/numalib/detect.go b/client/lib/numalib/detect.go index c3cc54113..e370fdf50 100644 --- a/client/lib/numalib/detect.go +++ b/client/lib/numalib/detect.go @@ -18,7 +18,7 @@ type SystemScanner interface { // a single Topology, which can then be used to answer questions about the CPU // topology of the system. func Scan(scanners []SystemScanner) *Topology { - top := new(Topology) + top := &Topology{} for _, scanner := range scanners { scanner.ScanSystem(top) } diff --git a/nomad/structs/cpucompat_default.go b/nomad/structs/cpucompat_default.go index ce971e77e..b906ebcc1 100644 --- a/nomad/structs/cpucompat_default.go +++ b/nomad/structs/cpucompat_default.go @@ -28,7 +28,7 @@ func (n *NodeResources) Compatibility() { // the LegacyNodeCpuResources field, and so we synthesize a pseudo // NodeProcessorResources field n.Processors.Topology = topologyFromLegacy(n.Cpu) - } else if !n.Processors.empty() { + } else if !n.Processors.Empty() { // When we receive a node update from a 1.7+ client it contains a // NodeProcessorResources field, and we populate the LegacyNodeCpuResources // field using that information. diff --git a/nomad/structs/cpucompat_linux.go b/nomad/structs/cpucompat_linux.go index 26d8b195b..99a47f352 100644 --- a/nomad/structs/cpucompat_linux.go +++ b/nomad/structs/cpucompat_linux.go @@ -31,7 +31,7 @@ func (n *NodeResources) Compatibility() { // the LegacyNodeCpuResources field, and so we synthesize a pseudo // NodeProcessorResources field n.Processors.Topology = topologyFromLegacy(n.Cpu) - } else if !n.Processors.empty() { + } else if !n.Processors.Empty() { // When we receive a node update from a 1.7+ client it contains a // NodeProcessorResources field, and we populate the LegacyNodeCpuResources // field using that information. diff --git a/nomad/structs/numa.go b/nomad/structs/numa.go index 7eccb1b13..8b79282ec 100644 --- a/nomad/structs/numa.go +++ b/nomad/structs/numa.go @@ -128,7 +128,7 @@ type NodeProcessorResources struct { // partial struct serialization / copy / merge sadness means this struct can // exist with no data, which is a condition we must detect during the upgrade path -func (r NodeProcessorResources) empty() bool { +func (r NodeProcessorResources) Empty() bool { return r.Topology == nil || len(r.Topology.Cores) == 0 } diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 6f08d54e5..008649d80 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -36,6 +36,7 @@ import ( "github.com/hashicorp/go-version" "github.com/hashicorp/nomad/acl" "github.com/hashicorp/nomad/client/lib/idset" + "github.com/hashicorp/nomad/client/lib/numalib" "github.com/hashicorp/nomad/client/lib/numalib/hw" "github.com/hashicorp/nomad/command/agent/host" "github.com/hashicorp/nomad/command/agent/pprof" @@ -2258,6 +2259,12 @@ func (n *Node) Canonicalize() { n.NodeResources.NodeNetworks = append(n.NodeResources.NodeNetworks, nnr) } } + + if n.NodeResources.Processors.Empty() { + n.NodeResources.Processors = NodeProcessorResources{ + Topology: &numalib.Topology{}, + } + } } }