diff --git a/.changelog/11744.txt b/.changelog/11744.txt new file mode 100644 index 000000000000..f8a3fb52e0a0 --- /dev/null +++ b/.changelog/11744.txt @@ -0,0 +1,3 @@ +```release-note:bug +core: Fix missing fields in Node.Copy() +``` diff --git a/nomad/node_endpoint_test.go b/nomad/node_endpoint_test.go index 36969ddd2a0b..22022181f958 100644 --- a/nomad/node_endpoint_test.go +++ b/nomad/node_endpoint_test.go @@ -1316,9 +1316,7 @@ func TestClientEndpoint_GetNode(t *testing.T) { node.StatusUpdatedAt = resp2.Node.StatusUpdatedAt node.SecretID = "" node.Events = resp2.Node.Events - if !reflect.DeepEqual(node, resp2.Node) { - t.Fatalf("bad: %#v \n %#v", node, resp2.Node) - } + require.Equal(t, node, resp2.Node) // assert that the node register event was set correctly if len(resp2.Node.Events) != 1 { diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 2caeebdffa5d..3e50a43cf00d 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -1971,17 +1971,17 @@ func (n *Node) Copy() *Node { nn := new(Node) *nn = *n nn.Attributes = helper.CopyMapStringString(nn.Attributes) - nn.Resources = nn.Resources.Copy() - nn.Reserved = nn.Reserved.Copy() nn.NodeResources = nn.NodeResources.Copy() nn.ReservedResources = nn.ReservedResources.Copy() + nn.Resources = nn.Resources.Copy() + nn.Reserved = nn.Reserved.Copy() nn.Links = helper.CopyMapStringString(nn.Links) nn.Meta = helper.CopyMapStringString(nn.Meta) - nn.Events = copyNodeEvents(n.Events) nn.DrainStrategy = nn.DrainStrategy.Copy() + nn.Events = copyNodeEvents(n.Events) + nn.Drivers = copyNodeDrivers(n.Drivers) nn.CSIControllerPlugins = copyNodeCSI(nn.CSIControllerPlugins) nn.CSINodePlugins = copyNodeCSI(nn.CSINodePlugins) - nn.Drivers = copyNodeDrivers(n.Drivers) nn.HostVolumes = copyNodeHostVolumes(n.HostVolumes) return nn } @@ -2580,6 +2580,7 @@ func (n *NetworkResource) Copy() *NetworkResource { } newR := new(NetworkResource) *newR = *n + newR.DNS = n.DNS.Copy() if n.ReservedPorts != nil { newR.ReservedPorts = make([]Port, len(n.ReservedPorts)) copy(newR.ReservedPorts, n.ReservedPorts) @@ -2794,8 +2795,7 @@ func (n *NodeResources) Copy() *NodeResources { newN := new(NodeResources) *newN = *n - - // Copy the networks + newN.Cpu = n.Cpu.Copy() newN.Networks = n.Networks.Copy() if n.NodeNetworks != nil { @@ -2979,6 +2979,11 @@ type NodeCpuResources struct { CpuShares int64 } +func (n NodeCpuResources) Copy() NodeCpuResources { + newN := n + return newN +} + func (n *NodeCpuResources) Merge(o *NodeCpuResources) { if o == nil { return