Correctly handle HorizontalPodAutoscaler metrics with 0 usage (#5986)

(cherry picked from commit 8dea3ad8bc)
This commit is contained in:
Sebastian Malton authored and Janne Savolainen committed 2022-08-09 10:19:48 +03:00
1 parent bfb054dcfd
commit b7f620f3f0
1 file changed
+4 -6
@@ -210,8 +210,6 @@ export class HorizontalPodAutoscalerApi extends KubeApi<HorizontalPodAutoscaler>
}
}
function getMetricName(metric: HorizontalPodAutoscalerMetricSpec | HorizontalPodAutoscalerMetricStatus): string | undefined {
switch (metric.type) {
case HpaMetricType.Resource:
@@ -232,12 +230,12 @@ function getMetricName(metric: HorizontalPodAutoscalerMetricSpec | HorizontalPod
function getResourceMetricValue(currentMetric: ResourceMetricStatus | undefined, targetMetric: ResourceMetricSource): MetricCurrentTarget {
return {
current: (
currentMetric?.currentAverageUtilization
typeof currentMetric?.currentAverageUtilization === "number"
? `${currentMetric.currentAverageUtilization}%`
: currentMetric?.currentAverageValue
),
target: (
targetMetric?.targetAverageUtilization
typeof targetMetric?.targetAverageUtilization === "number"
? `${targetMetric.targetAverageUtilization}%`
: targetMetric?.targetAverageValue
),
@@ -280,12 +278,12 @@ function getExternalMetricValue(currentMetric: ExternalMetricStatus | undefined,
function getContainerResourceMetricValue(currentMetric: ContainerResourceMetricStatus | undefined, targetMetric: ContainerResourceMetricSource): MetricCurrentTarget {
return {
current: (
currentMetric?.currentAverageUtilization
typeof currentMetric?.currentAverageUtilization === "number"
? `${currentMetric.currentAverageUtilization}%`
: currentMetric?.currentAverageValue
),
target: (
targetMetric?.targetAverageUtilization
typeof targetMetric?.targetAverageUtilization === "number"
? `${targetMetric.targetAverageUtilization}%`
: targetMetric?.targetAverageValue
),