Skip to content

Commit

Permalink
Bump Horizontal Pod Autoscaler apiBase version (#6906)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
aleksfront authored Jan 11, 2023
1 parent 5ba88b1 commit 34e6cf2
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/common/k8s-api/endpoints/horizontal-pod-autoscaler.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -132,6 +153,7 @@ export interface HorizontalPodAutoscalerSpec {
minReplicas?: number;
maxReplicas: number;
metrics?: HorizontalPodAutoscalerMetricSpec[];
behavior?: HorizontalPodAutoscalerBehavior;
}

export interface HorizontalPodAutoscalerStatus {
Expand All @@ -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;
Expand Down Expand Up @@ -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",
],
});
}
}
Expand Down

0 comments on commit 34e6cf2

Please sign in to comment.