From cf2b50f191222041227a0ee6b9d0123c76d64325 Mon Sep 17 00:00:00 2001 From: zwzhang Date: Wed, 22 Nov 2023 23:30:52 +0800 Subject: [PATCH] koord-manager: get node batch allocatable from extended resource (#1752) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 佑祎 --- .../noderesource/plugins/batchresource/plugin.go | 5 +++-- pkg/util/node.go | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/pkg/slo-controller/noderesource/plugins/batchresource/plugin.go b/pkg/slo-controller/noderesource/plugins/batchresource/plugin.go index b0b5e6c60..cdc3a9f26 100644 --- a/pkg/slo-controller/noderesource/plugins/batchresource/plugin.go +++ b/pkg/slo-controller/noderesource/plugins/batchresource/plugin.go @@ -115,8 +115,9 @@ func (p *Plugin) Prepare(_ *configuration.ColocationStrategy, node *corev1.Node, } // set origin batch allocatable - batchMilliCPU := util.GetBatchMilliCPUFromResourceList(node.Status.Allocatable) - batchMemory := util.GetBatchMemoryFromResourceList(node.Status.Allocatable) + batchMilliCPU := util.GetNodeAllocatableBatchMilliCPU(node) + //batchMilliCPU := util.GetBatchMilliCPUFromResourceList(node.Status.Allocatable) + batchMemory := util.GetNodeAllocatableBatchMemory(node) originBatchAllocatable := corev1.ResourceList{ extension.BatchCPU: *resource.NewQuantity(util.MaxInt64(batchMilliCPU, 0), resource.DecimalSI), extension.BatchMemory: *resource.NewQuantity(util.MaxInt64(batchMemory, 0), resource.BinarySI), diff --git a/pkg/util/node.go b/pkg/util/node.go index 1d34ec663..c86656ce1 100644 --- a/pkg/util/node.go +++ b/pkg/util/node.go @@ -160,3 +160,19 @@ func GetNodeAnnoReservedJson(reserved apiext.NodeReservation) string { return result } + +func GetNodeAllocatableBatchMilliCPU(node *corev1.Node) int64 { + // assert node != nil + if milliCPU, ok := node.Status.Allocatable[apiext.BatchCPU]; ok { + return milliCPU.Value() + } + return -1 +} + +func GetNodeAllocatableBatchMemory(node *corev1.Node) int64 { + // assert node != nil + if memory, ok := node.Status.Allocatable[apiext.BatchMemory]; ok { + return memory.Value() + } + return -1 +}