From 833833d15f58a9d86006966ab9ff36d3e1c0b5b1 Mon Sep 17 00:00:00 2001 From: neogopher Date: Wed, 11 Dec 2024 15:16:16 +0530 Subject: [PATCH] bugfix: set allocatable resources to 0 when free capacity goes negative --- pkg/controllers/resources/nodes/translate.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/controllers/resources/nodes/translate.go b/pkg/controllers/resources/nodes/translate.go index 6b2c21f42..390a9913a 100644 --- a/pkg/controllers/resources/nodes/translate.go +++ b/pkg/controllers/resources/nodes/translate.go @@ -203,15 +203,23 @@ func (s *nodeSyncer) translateUpdateStatus(ctx *synccontext.SyncContext, pNode * pods -= nonVClusterPods if pods > 0 { translatedStatus.Allocatable[corev1.ResourcePods] = *resource.NewQuantity(pods, resource.DecimalSI) + } else { + translatedStatus.Allocatable[corev1.ResourcePods] = *resource.NewQuantity(0, resource.DecimalSI) } if cpu > 0 { translatedStatus.Allocatable[corev1.ResourceCPU] = *resource.NewMilliQuantity(cpu, resource.DecimalSI) + } else { + translatedStatus.Allocatable[corev1.ResourceCPU] = *resource.NewMilliQuantity(0, resource.DecimalSI) } if memory > 0 { translatedStatus.Allocatable[corev1.ResourceMemory] = *resource.NewQuantity(memory, resource.BinarySI) + } else { + translatedStatus.Allocatable[corev1.ResourceMemory] = *resource.NewQuantity(0, resource.BinarySI) } if storageEphemeral > 0 { translatedStatus.Allocatable[corev1.ResourceEphemeralStorage] = *resource.NewQuantity(storageEphemeral, resource.BinarySI) + } else { + translatedStatus.Allocatable[corev1.ResourceEphemeralStorage] = *resource.NewQuantity(0, resource.BinarySI) } }