Bump Horizontal Pod Autoscaler apiBase version (#6906)

* Change HPA apiBase and add fallback bases

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Add HPA Behavior types from v2

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Linter fixes

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Fix whitespace differences

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev authored and GitHub committed 2023-01-11 08:45:10 -05:00
1 parent 5ba88b1400
commit 34e6cf263f
1 file changed
+31 -2
@@ -72,6 +72,27 @@ export type HorizontalPodAutoscalerMetricSpec =
| OptionVarient<HpaMetricType.Pods, BaseHorizontalPodAutoscalerMetricSpec, "pods">
| OptionVarient<HpaMetricType.ContainerResource, BaseHorizontalPodAutoscalerMetricSpec, "containerResource">;
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<HorizontalPodAutoscaler> {
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",
],
});
}
}