From 34e6cf263fbd923f8dc888136c953c6d11c27a7c Mon Sep 17 00:00:00 2001 From: Alex Andreev Date: Wed, 11 Jan 2023 16:45:10 +0300 Subject: [PATCH] Bump Horizontal Pod Autoscaler apiBase version (#6906) * Change HPA apiBase and add fallback bases Signed-off-by: Alex Andreev * Add HPA Behavior types from v2 Signed-off-by: Alex Andreev * Linter fixes Signed-off-by: Alex Andreev * Fix whitespace differences Signed-off-by: Alex Andreev Signed-off-by: Alex Andreev --- .../horizontal-pod-autoscaler.api.ts | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) 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 71863d65ad..ee4fcfc63d 100644 --- a/src/common/k8s-api/endpoints/horizontal-pod-autoscaler.api.ts +++ b/src/common/k8s-api/endpoints/horizontal-pod-autoscaler.api.ts @@ -72,6 +72,27 @@ export type HorizontalPodAutoscalerMetricSpec = | OptionVarient | OptionVarient; +interface HorizontalPodAutoscalerBehavior { + scaleUp?: HPAScalingRules; + scaleDown?: HPAScalingRules; +} + +interface HPAScalingRules { + stabilizationWindowSecond?: number; + selectPolicy?: ScalingPolicySelect; + policies?: HPAScalingPolicy[]; +} + +type ScalingPolicySelect = string; + +interface HPAScalingPolicy { + type: HPAScalingPolicyType; + value: number; + periodSeconds: number; +} + +type HPAScalingPolicyType = string; + export interface ContainerResourceMetricStatus { container: string; currentAverageUtilization?: number; @@ -132,6 +153,7 @@ export interface HorizontalPodAutoscalerSpec { minReplicas?: number; maxReplicas: number; metrics?: HorizontalPodAutoscalerMetricSpec[]; + behavior?: HorizontalPodAutoscalerBehavior; } export interface HorizontalPodAutoscalerStatus { @@ -153,7 +175,7 @@ export class HorizontalPodAutoscaler extends KubeObject< > { static readonly kind = "HorizontalPodAutoscaler"; static readonly namespaced = true; - static readonly apiBase = "/apis/autoscaling/v2beta1/horizontalpodautoscalers"; + static readonly apiBase = "/apis/autoscaling/v2/horizontalpodautoscalers"; getMaxPods() { return this.spec.maxReplicas ?? 0; @@ -204,8 +226,15 @@ export class HorizontalPodAutoscaler extends KubeObject< export class HorizontalPodAutoscalerApi extends KubeApi { constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) { super(deps, { - objectConstructor: HorizontalPodAutoscaler, ...opts ?? {}, + objectConstructor: HorizontalPodAutoscaler, + checkPreferredVersion: true, + // Kubernetes < 1.26 + fallbackApiBases: [ + "/apis/autoscaling/v2beta2/horizontalpodautoscalers", + "/apis/autoscaling/v2beta1/horizontalpodautoscalers", + "/apis/autoscaling/v1/horizontalpodautoscalers", + ], }); } }