diff --git a/src/common/k8s-api/__tests__/horizontal-pod-autoscaler.api.test.ts b/src/common/k8s-api/__tests__/horizontal-pod-autoscaler.api.test.ts index 254dd1fc22..1bbe1f0cc8 100644 --- a/src/common/k8s-api/__tests__/horizontal-pod-autoscaler.api.test.ts +++ b/src/common/k8s-api/__tests__/horizontal-pod-autoscaler.api.test.ts @@ -21,7 +21,7 @@ const hpaV2 = { } describe("HorizontalPodAutoscalerApi", () => { - describe("HPA v1", () => { + describe("HPA v2", () => { it("should return correct empty metrics", () => { const hpa = new HorizontalPodAutoscaler(hpaV2); @@ -103,5 +103,32 @@ describe("HorizontalPodAutoscalerApi", () => { expect(hpa.getMetricValues(hpa.getMetrics()[0])).toEqual("unknown / 1k"); }); + + it("should return correct object metrics", () => { + const hpa = new HorizontalPodAutoscaler( + { + ...hpaV2, + spec: { + ...hpaV2.spec, + metrics: [ + { + type: HpaMetricType.Object, + object: { + metric: { + name: "requests-per-second" + }, + target: { + type: "Value", + value: "10k" + } + } + } + ] + } + } + ); + + expect(hpa.getMetricValues(hpa.getMetrics()[0])).toEqual("unknown / 10k"); + }); }); }); \ No newline at end of file diff --git a/src/common/k8s-api/endpoints/horizontal-pod-autoscaler.api.ts b/src/common/k8s-api/endpoints/horizontal-pod-autoscaler.api.ts index c6df807a70..9219fd3284 100644 --- a/src/common/k8s-api/endpoints/horizontal-pod-autoscaler.api.ts +++ b/src/common/k8s-api/endpoints/horizontal-pod-autoscaler.api.ts @@ -45,10 +45,19 @@ export interface ExternalMetricSource { export interface ObjectMetricSource { averageValue?: string; - metricName: string; + metricName?: string; selector?: LabelSelector; - target: CrossVersionObjectReference; - targetValue: string; + targetValue?: string; + + // autoscaling/v2 + metric?: { + name?: string; + }, + target: { + type?: string; + value?: string; + }; + describedObject?: CrossVersionObjectReference; } export interface PodsMetricSource { @@ -344,10 +353,7 @@ function getObjectMetricValue(currentMetric: ObjectMetricStatus | undefined, tar currentMetric?.currentValue ?? currentMetric?.averageValue ), - target: ( - targetMetric?.targetValue - ?? targetMetric?.averageValue - ), + target: targetMetric?.target?.value }; }