From 8f80bd505fd3ef4b41e82b62bc29018c7986f1e8 Mon Sep 17 00:00:00 2001 From: Piotr Kazmierczak <470696+pkazmierczak@users.noreply.github.com> Date: Fri, 21 Jun 2024 13:22:59 +0000 Subject: [PATCH] scheduler: fix a bug where we subtract reserved node resources twice (#23386) Fixes a bug in the nodeResources.Comparable method, where CPU resources were accidentally offset with reserved resources, whereas functions that use this field expect total CPU resources. --- .changelog/23386.txt | 3 +++ nomad/structs/funcs_test.go | 1 + nomad/structs/structs.go | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 .changelog/23386.txt diff --git a/.changelog/23386.txt b/.changelog/23386.txt new file mode 100644 index 000000000..49bac071a --- /dev/null +++ b/.changelog/23386.txt @@ -0,0 +1,3 @@ +```release-note:bug +scheduler: Fix a bug where reserved resources are not calculated correctly +``` diff --git a/nomad/structs/funcs_test.go b/nomad/structs/funcs_test.go index 1944ed659..c73d01720 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{ diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 1d1294ccd..b5b0a1ec1 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{