From a0a717342775bce914aeb7ef052e59d3cb6dc41c Mon Sep 17 00:00:00 2001 From: pkazmierczak <470696+pkazmierczak@users.noreply.github.com> Date: Wed, 19 Jun 2024 18:39:43 +0200 Subject: [PATCH 1/4] scheduler: fix a bug where we subtract reserved node resources twice --- nomad/structs/funcs.go | 1 - 1 file changed, 1 deletion(-) diff --git a/nomad/structs/funcs.go b/nomad/structs/funcs.go index 25333fc800e..4c8c73d239f 100644 --- a/nomad/structs/funcs.go +++ b/nomad/structs/funcs.go @@ -172,7 +172,6 @@ func AllocsFit(node *Node, allocs []*Allocation, netIdx *NetworkIndex, checkDevi // Check that the node resources (after subtracting reserved) are a // super set of those that are being allocated available := node.NodeResources.Comparable() - available.Subtract(node.ReservedResources.Comparable()) if superset, dimension := available.Superset(used); !superset { return false, dimension, used, nil } From e0dcac3d1ae8834a877ebc36811d00eec68193b5 Mon Sep 17 00:00:00 2001 From: pkazmierczak <470696+pkazmierczak@users.noreply.github.com> Date: Wed, 19 Jun 2024 19:29:03 +0200 Subject: [PATCH 2/4] nodeResources.Comparable() should in fact return total resources --- nomad/structs/funcs.go | 1 + nomad/structs/structs.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/nomad/structs/funcs.go b/nomad/structs/funcs.go index 4c8c73d239f..25333fc800e 100644 --- a/nomad/structs/funcs.go +++ b/nomad/structs/funcs.go @@ -172,6 +172,7 @@ func AllocsFit(node *Node, allocs []*Allocation, netIdx *NetworkIndex, checkDevi // Check that the node resources (after subtracting reserved) are a // super set of those that are being allocated available := node.NodeResources.Comparable() + available.Subtract(node.ReservedResources.Comparable()) if superset, dimension := available.Superset(used); !superset { return false, dimension, used, nil } diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 1d1294ccd37..b5b0a1ec1f8 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -3191,7 +3191,7 @@ func (n *NodeResources) Comparable() *ComparableResources { c := &ComparableResources{ Flattened: AllocatedTaskResources{ Cpu: AllocatedCpuResources{ - CpuShares: int64(n.Processors.Topology.UsableCompute()), + CpuShares: int64(n.Processors.Topology.TotalCompute()), ReservedCores: reservableCores, }, Memory: AllocatedMemoryResources{ From 10131ea5814e81feb209b41e80d246fe5236f9ef Mon Sep 17 00:00:00 2001 From: pkazmierczak <470696+pkazmierczak@users.noreply.github.com> Date: Wed, 19 Jun 2024 19:29:40 +0200 Subject: [PATCH 3/4] cl --- .changelog/23386.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/23386.txt diff --git a/.changelog/23386.txt b/.changelog/23386.txt new file mode 100644 index 00000000000..49bac071a99 --- /dev/null +++ b/.changelog/23386.txt @@ -0,0 +1,3 @@ +```release-note:bug +scheduler: Fix a bug where reserved resources are not calculated correctly +``` From a73965f95f2c305d55f578b70cfc4c24dab82b59 Mon Sep 17 00:00:00 2001 From: pkazmierczak <470696+pkazmierczak@users.noreply.github.com> Date: Fri, 21 Jun 2024 15:04:00 +0200 Subject: [PATCH 4/4] mocked Node correction --- nomad/structs/funcs_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/nomad/structs/funcs_test.go b/nomad/structs/funcs_test.go index 1944ed659d5..c73d01720f1 100644 --- a/nomad/structs/funcs_test.go +++ b/nomad/structs/funcs_test.go @@ -105,6 +105,7 @@ func node2k() *Node { Grade: numalib.Performance, BaseSpeed: 1000, }}, + OverrideWitholdCompute: 1000, // set by client reserved field }, }, Memory: NodeMemoryResources{