mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
3
.changelog/11744.txt
Normal file
3
.changelog/11744.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
```release-note:bug
|
||||||
|
core: Fix missing fields in Node.Copy()
|
||||||
|
```
|
||||||
@@ -1531,9 +1531,7 @@ func TestClientEndpoint_GetNode(t *testing.T) {
|
|||||||
node.StatusUpdatedAt = resp2.Node.StatusUpdatedAt
|
node.StatusUpdatedAt = resp2.Node.StatusUpdatedAt
|
||||||
node.SecretID = ""
|
node.SecretID = ""
|
||||||
node.Events = resp2.Node.Events
|
node.Events = resp2.Node.Events
|
||||||
if !reflect.DeepEqual(node, resp2.Node) {
|
require.Equal(t, node, resp2.Node)
|
||||||
t.Fatalf("bad: %#v \n %#v", node, resp2.Node)
|
|
||||||
}
|
|
||||||
|
|
||||||
// assert that the node register event was set correctly
|
// assert that the node register event was set correctly
|
||||||
if len(resp2.Node.Events) != 1 {
|
if len(resp2.Node.Events) != 1 {
|
||||||
|
|||||||
@@ -2025,20 +2025,20 @@ func (n *Node) Copy() *Node {
|
|||||||
nn := new(Node)
|
nn := new(Node)
|
||||||
*nn = *n
|
*nn = *n
|
||||||
nn.Attributes = helper.CopyMapStringString(nn.Attributes)
|
nn.Attributes = helper.CopyMapStringString(nn.Attributes)
|
||||||
nn.Resources = nn.Resources.Copy()
|
|
||||||
nn.Reserved = nn.Reserved.Copy()
|
|
||||||
nn.NodeResources = nn.NodeResources.Copy()
|
nn.NodeResources = nn.NodeResources.Copy()
|
||||||
nn.ReservedResources = nn.ReservedResources.Copy()
|
nn.ReservedResources = nn.ReservedResources.Copy()
|
||||||
|
nn.Resources = nn.Resources.Copy()
|
||||||
|
nn.Reserved = nn.Reserved.Copy()
|
||||||
nn.Links = helper.CopyMapStringString(nn.Links)
|
nn.Links = helper.CopyMapStringString(nn.Links)
|
||||||
nn.Meta = helper.CopyMapStringString(nn.Meta)
|
nn.Meta = helper.CopyMapStringString(nn.Meta)
|
||||||
nn.Events = copyNodeEvents(n.Events)
|
|
||||||
nn.DrainStrategy = nn.DrainStrategy.Copy()
|
nn.DrainStrategy = nn.DrainStrategy.Copy()
|
||||||
nn.LastDrain = nn.LastDrain.Copy()
|
nn.Events = copyNodeEvents(n.Events)
|
||||||
|
nn.Drivers = copyNodeDrivers(n.Drivers)
|
||||||
nn.CSIControllerPlugins = copyNodeCSI(nn.CSIControllerPlugins)
|
nn.CSIControllerPlugins = copyNodeCSI(nn.CSIControllerPlugins)
|
||||||
nn.CSINodePlugins = copyNodeCSI(nn.CSINodePlugins)
|
nn.CSINodePlugins = copyNodeCSI(nn.CSINodePlugins)
|
||||||
nn.Drivers = copyNodeDrivers(n.Drivers)
|
|
||||||
nn.HostVolumes = copyNodeHostVolumes(n.HostVolumes)
|
nn.HostVolumes = copyNodeHostVolumes(n.HostVolumes)
|
||||||
nn.HostNetworks = copyNodeHostNetworks(n.HostNetworks)
|
nn.HostNetworks = copyNodeHostNetworks(n.HostNetworks)
|
||||||
|
nn.LastDrain = nn.LastDrain.Copy()
|
||||||
return nn
|
return nn
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2657,6 +2657,7 @@ func (n *NetworkResource) Copy() *NetworkResource {
|
|||||||
}
|
}
|
||||||
newR := new(NetworkResource)
|
newR := new(NetworkResource)
|
||||||
*newR = *n
|
*newR = *n
|
||||||
|
newR.DNS = n.DNS.Copy()
|
||||||
if n.ReservedPorts != nil {
|
if n.ReservedPorts != nil {
|
||||||
newR.ReservedPorts = make([]Port, len(n.ReservedPorts))
|
newR.ReservedPorts = make([]Port, len(n.ReservedPorts))
|
||||||
copy(newR.ReservedPorts, n.ReservedPorts)
|
copy(newR.ReservedPorts, n.ReservedPorts)
|
||||||
@@ -2874,8 +2875,7 @@ func (n *NodeResources) Copy() *NodeResources {
|
|||||||
|
|
||||||
newN := new(NodeResources)
|
newN := new(NodeResources)
|
||||||
*newN = *n
|
*newN = *n
|
||||||
|
newN.Cpu = n.Cpu.Copy()
|
||||||
// Copy the networks
|
|
||||||
newN.Networks = n.Networks.Copy()
|
newN.Networks = n.Networks.Copy()
|
||||||
|
|
||||||
// Copy the devices
|
// Copy the devices
|
||||||
@@ -3062,6 +3062,16 @@ type NodeCpuResources struct {
|
|||||||
ReservableCpuCores []uint16
|
ReservableCpuCores []uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n NodeCpuResources) Copy() NodeCpuResources {
|
||||||
|
newN := n
|
||||||
|
if n.ReservableCpuCores != nil {
|
||||||
|
newN.ReservableCpuCores = make([]uint16, len(n.ReservableCpuCores))
|
||||||
|
copy(newN.ReservableCpuCores, n.ReservableCpuCores)
|
||||||
|
}
|
||||||
|
|
||||||
|
return newN
|
||||||
|
}
|
||||||
|
|
||||||
func (n *NodeCpuResources) Merge(o *NodeCpuResources) {
|
func (n *NodeCpuResources) Merge(o *NodeCpuResources) {
|
||||||
if o == nil {
|
if o == nil {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1672,6 +1672,15 @@ func TestNetworkResource_Copy(t *testing.T) {
|
|||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
output := tc.inputNetworkResource.Copy()
|
output := tc.inputNetworkResource.Copy()
|
||||||
assert.Equal(t, tc.inputNetworkResource, output, tc.name)
|
assert.Equal(t, tc.inputNetworkResource, output, tc.name)
|
||||||
|
|
||||||
|
if output == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assert changes to the copy aren't propagated to the
|
||||||
|
// original
|
||||||
|
output.DNS.Servers[1] = "foo"
|
||||||
|
assert.NotEqual(t, tc.inputNetworkResource, output, tc.name)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5971,6 +5980,31 @@ func TestMultiregion_CopyCanonicalize(t *testing.T) {
|
|||||||
require.False(old.Diff(nonEmptyOld))
|
require.False(old.Diff(nonEmptyOld))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNodeResources_Copy(t *testing.T) {
|
||||||
|
orig := &NodeResources{
|
||||||
|
Cpu: NodeCpuResources{
|
||||||
|
CpuShares: int64(32000),
|
||||||
|
TotalCpuCores: 32,
|
||||||
|
ReservableCpuCores: []uint16{1, 2, 3, 9},
|
||||||
|
},
|
||||||
|
Memory: NodeMemoryResources{
|
||||||
|
MemoryMB: int64(64000),
|
||||||
|
},
|
||||||
|
Networks: Networks{
|
||||||
|
{
|
||||||
|
Device: "foo",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
kopy := orig.Copy()
|
||||||
|
assert.Equal(t, orig, kopy)
|
||||||
|
|
||||||
|
// Make sure slices aren't shared
|
||||||
|
kopy.Cpu.ReservableCpuCores[1] = 9000
|
||||||
|
assert.NotEqual(t, orig, kopy)
|
||||||
|
}
|
||||||
|
|
||||||
func TestNodeResources_Merge(t *testing.T) {
|
func TestNodeResources_Merge(t *testing.T) {
|
||||||
res := &NodeResources{
|
res := &NodeResources{
|
||||||
Cpu: NodeCpuResources{
|
Cpu: NodeCpuResources{
|
||||||
|
|||||||
Reference in New Issue
Block a user