1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Spreading types to V2 and V2Beta1

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2023-01-20 13:44:03 +03:00
parent c2bcbe9edc
commit fc1aa513f4
3 changed files with 127 additions and 40 deletions

View File

@ -28,11 +28,9 @@ export interface HorizontalPodAutoscalerMetricTarget {
apiVersion: string; apiVersion: string;
} }
export interface ContainerResourceMetricSource { export interface V2ContainerResourceMetricSource {
container: string; container: string;
name: string; name: string;
targetAverageUtilization?: number;
targetAverageValue?: string;
target?: { target?: {
averageUtilization?: number; averageUtilization?: number;
averageValue?: string; averageValue?: string;
@ -40,11 +38,20 @@ export interface ContainerResourceMetricSource {
}; };
} }
export interface ExternalMetricSource { export interface V2Beta1ContainerResourceMetricSource {
container: string;
name: string;
targetAverageUtilization?: number;
targetAverageValue?: string;
}
export type ContainerResourceMetricSource =
| V2ContainerResourceMetricSource
| V2Beta1ContainerResourceMetricSource;
export interface V2ExternalMetricSource {
metricName?: string; metricName?: string;
metricSelector?: LabelSelector; metricSelector?: LabelSelector;
targetAverageValue?: string;
targetValue?: string;
metric?: { metric?: {
name?: string; name?: string;
selector?: LabelSelector; selector?: LabelSelector;
@ -56,13 +63,24 @@ export interface ExternalMetricSource {
}; };
} }
export interface ObjectMetricSource { export interface V2Beta1ExternalMetricSource {
averageValue?: string;
metricName?: string; metricName?: string;
selector?: LabelSelector; metricSelector?: LabelSelector;
targetAverageValue?: string;
targetValue?: string; targetValue?: string;
metric?: {
selector?: LabelSelector;
}
}
export type ExternalMetricSource =
| V2Beta1ExternalMetricSource
| V2ExternalMetricSource;
export interface V2ObjectMetricSource {
metric?: { metric?: {
name?: string; name?: string;
selector?: LabelSelector;
}; };
target?: { target?: {
type?: string; type?: string;
@ -72,12 +90,22 @@ export interface ObjectMetricSource {
describedObject?: CrossVersionObjectReference; describedObject?: CrossVersionObjectReference;
} }
export interface PodsMetricSource { export interface V2Beta1ObjectMetricSource {
averageValue?: string;
metricName?: string; metricName?: string;
selector?: LabelSelector; selector?: LabelSelector;
targetAverageValue?: string; targetValue?: string;
describedObject?: CrossVersionObjectReference;
}
export type ObjectMetricSource =
| V2ObjectMetricSource
| V2Beta1ObjectMetricSource;
export interface V2PodsMetricSource {
metric?: { metric?: {
name?: string; name?: string;
selector?: LabelSelector;
}; };
target?: { target?: {
averageValue?: string; averageValue?: string;
@ -85,10 +113,18 @@ export interface PodsMetricSource {
}; };
} }
export interface ResourceMetricSource { export interface V2Beta1PodsMetricSource {
name: string; metricName?: string;
targetAverageUtilization?: number; selector?: LabelSelector;
targetAverageValue?: string; targetAverageValue?: string;
}
export type PodsMetricSource =
| V2PodsMetricSource
| V2Beta1PodsMetricSource;
export interface V2ResourceMetricSource {
name: string;
target?: { target?: {
averageUtilization?: number; averageUtilization?: number;
averageValue?: string; averageValue?: string;
@ -96,6 +132,16 @@ export interface ResourceMetricSource {
}; };
} }
export interface V2Beta1ResourceMetricSource {
name: string;
targetAverageUtilization?: number;
targetAverageValue?: string;
}
export type ResourceMetricSource =
| V2ResourceMetricSource
| V2Beta1ResourceMetricSource;
export interface BaseHorizontalPodAutoscalerMetricSpec { export interface BaseHorizontalPodAutoscalerMetricSpec {
containerResource: ContainerResourceMetricSource; containerResource: ContainerResourceMetricSource;
external: ExternalMetricSource; external: ExternalMetricSource;
@ -132,10 +178,8 @@ interface HPAScalingPolicy {
type HPAScalingPolicyType = string; type HPAScalingPolicyType = string;
export interface ContainerResourceMetricStatus { export interface V2ContainerResourceMetricStatus {
container?: string; container?: string;
currentAverageUtilization?: number;
currentAverageValue?: string;
name: string; name: string;
current?: { current?: {
averageUtilization?: number; averageUtilization?: number;
@ -143,11 +187,18 @@ export interface ContainerResourceMetricStatus {
}; };
} }
export interface ExternalMetricStatus { export interface V2Beta1ContainerResourceMetricStatus {
container?: string;
currentAverageUtilization?: number;
currentAverageValue?: string; currentAverageValue?: string;
currentValue?: string; name: string;
metricName?: string; }
metricSelector?: LabelSelector;
export type ContainerResourceMetricStatus =
| V2ContainerResourceMetricStatus
| V2Beta1ContainerResourceMetricStatus;
export interface V2ExternalMetricStatus {
metric?: { metric?: {
name?: string; name?: string;
selector?: LabelSelector; selector?: LabelSelector;
@ -158,11 +209,18 @@ export interface ExternalMetricStatus {
}; };
} }
export interface ObjectMetricStatus { export interface V2Beta1ExternalMetricStatus {
averageValue?: string; currentAverageValue?: string;
currentValue?: string; currentValue?: string;
metricName?: string; metricName?: string;
selector?: LabelSelector; metricSelector?: LabelSelector;
}
export type ExternalMetricStatus =
| V2Beta1ExternalMetricStatus
| V2ExternalMetricStatus;
export interface V2ObjectMetricStatus {
metric?: { metric?: {
name?: string; name?: string;
selector?: LabelSelector; selector?: LabelSelector;
@ -175,21 +233,40 @@ export interface ObjectMetricStatus {
describedObject?: CrossVersionObjectReference; describedObject?: CrossVersionObjectReference;
} }
export interface PodsMetricStatus { export interface V2Beta1ObjectMetricStatus {
currentAverageValue?: string; averageValue?: string;
currentValue?: string;
metricName?: string; metricName?: string;
selector?: LabelSelector;
describedObject?: CrossVersionObjectReference;
}
export type ObjectMetricStatus =
| V2Beta1ObjectMetricStatus
| V2ObjectMetricStatus;
export interface V2PodsMetricStatus {
selector?: LabelSelector; selector?: LabelSelector;
metric?: { metric?: {
name?: string; name?: string;
selector?: LabelSelector;
}; };
current?: { current?: {
averageValue?: string; averageValue?: string;
}; };
} }
export interface ResourceMetricStatus { export interface V2Beta1PodsMetricStatus {
currentAverageUtilization?: number;
currentAverageValue?: string; currentAverageValue?: string;
metricName?: string;
selector?: LabelSelector;
}
export type PodsMetricStatus =
| V2Beta1PodsMetricStatus
| V2PodsMetricStatus;
export interface V2ResourceMetricStatus {
name: string; name: string;
current?: { current?: {
averageUtilization?: number; averageUtilization?: number;
@ -197,6 +274,16 @@ export interface ResourceMetricStatus {
}; };
} }
export interface V2Beta1ResourceMetricStatus {
currentAverageUtilization?: number;
currentAverageValue?: string;
name: string;
}
export type ResourceMetricStatus =
| V2Beta1ResourceMetricStatus
| V2ResourceMetricStatus;
export interface BaseHorizontalPodAutoscalerMetricStatus { export interface BaseHorizontalPodAutoscalerMetricStatus {
containerResource: ContainerResourceMetricStatus; containerResource: ContainerResourceMetricStatus;
external: ExternalMetricStatus; external: ExternalMetricStatus;

View File

@ -2,10 +2,10 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { ContainerResourceMetricSource, ContainerResourceMetricStatus, ExternalMetricSource, ExternalMetricStatus, MetricCurrentTarget, ObjectMetricSource, ObjectMetricStatus, PodsMetricSource, PodsMetricStatus, ResourceMetricSource, ResourceMetricStatus } from "../../../common/k8s-api/endpoints"; import type { MetricCurrentTarget, V2Beta1ContainerResourceMetricSource, V2Beta1ContainerResourceMetricStatus, V2Beta1ExternalMetricSource, V2Beta1ExternalMetricStatus, V2Beta1ObjectMetricSource, V2Beta1ObjectMetricStatus, V2Beta1PodsMetricSource, V2Beta1PodsMetricStatus, V2Beta1ResourceMetricSource, V2Beta1ResourceMetricStatus } from "../../../common/k8s-api/endpoints";
export class HorizontalPodAutoscalerV1MetricParser { export class HorizontalPodAutoscalerV1MetricParser {
public getResource({ current, target }: { current: ResourceMetricStatus | undefined; target: ResourceMetricSource }): MetricCurrentTarget { public getResource({ current, target }: { current: V2Beta1ResourceMetricStatus | undefined; target: V2Beta1ResourceMetricSource }): MetricCurrentTarget {
return { return {
current: ( current: (
typeof current?.currentAverageUtilization === "number" typeof current?.currentAverageUtilization === "number"
@ -20,14 +20,14 @@ export class HorizontalPodAutoscalerV1MetricParser {
}; };
} }
public getPods({ current, target }: { current: PodsMetricStatus | undefined; target: PodsMetricSource }): MetricCurrentTarget { public getPods({ current, target }: { current: V2Beta1PodsMetricStatus | undefined; target: V2Beta1PodsMetricSource }): MetricCurrentTarget {
return { return {
current: current?.currentAverageValue, current: current?.currentAverageValue,
target: target?.targetAverageValue, target: target?.targetAverageValue,
}; };
} }
public getObject({ current, target }: { current: ObjectMetricStatus | undefined; target: ObjectMetricSource }): MetricCurrentTarget { public getObject({ current, target }: { current: V2Beta1ObjectMetricStatus | undefined; target: V2Beta1ObjectMetricSource }): MetricCurrentTarget {
return { return {
current: ( current: (
current?.currentValue current?.currentValue
@ -40,7 +40,7 @@ export class HorizontalPodAutoscalerV1MetricParser {
}; };
} }
public getExternal({ current, target }: { current: ExternalMetricStatus | undefined; target: ExternalMetricSource }): MetricCurrentTarget { public getExternal({ current, target }: { current: V2Beta1ExternalMetricStatus | undefined; target: V2Beta1ExternalMetricSource }): MetricCurrentTarget {
return { return {
current: ( current: (
current?.currentValue current?.currentValue
@ -53,7 +53,7 @@ export class HorizontalPodAutoscalerV1MetricParser {
}; };
} }
public getContainerResource({ current, target }: { current: ContainerResourceMetricStatus | undefined; target: ContainerResourceMetricSource }): MetricCurrentTarget { public getContainerResource({ current, target }: { current: V2Beta1ContainerResourceMetricStatus | undefined; target: V2Beta1ContainerResourceMetricSource }): MetricCurrentTarget {
return { return {
current: ( current: (
typeof current?.currentAverageUtilization === "number" typeof current?.currentAverageUtilization === "number"

View File

@ -2,10 +2,10 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { ContainerResourceMetricSource, ContainerResourceMetricStatus, ExternalMetricSource, ExternalMetricStatus, MetricCurrentTarget, ObjectMetricSource, ObjectMetricStatus, PodsMetricSource, PodsMetricStatus, ResourceMetricSource, ResourceMetricStatus } from "../../../common/k8s-api/endpoints"; import type { MetricCurrentTarget, V2ContainerResourceMetricSource, V2ContainerResourceMetricStatus, V2ExternalMetricSource, V2ExternalMetricStatus, V2ObjectMetricSource, V2ObjectMetricStatus, V2PodsMetricSource, V2PodsMetricStatus, V2ResourceMetricSource, V2ResourceMetricStatus } from "../../../common/k8s-api/endpoints";
export class HorizontalPodAutoscalerV2MetricParser { export class HorizontalPodAutoscalerV2MetricParser {
public getResource({ current, target }: { current: ResourceMetricStatus | undefined; target: ResourceMetricSource }): MetricCurrentTarget { public getResource({ current, target }: { current: V2ResourceMetricStatus | undefined; target: V2ResourceMetricSource }): MetricCurrentTarget {
return { return {
current: ( current: (
typeof current?.current?.averageUtilization === "number" typeof current?.current?.averageUtilization === "number"
@ -18,14 +18,14 @@ export class HorizontalPodAutoscalerV2MetricParser {
}; };
} }
public getPods({ current, target }: { current: PodsMetricStatus | undefined; target: PodsMetricSource }): MetricCurrentTarget { public getPods({ current, target }: { current: V2PodsMetricStatus | undefined; target: V2PodsMetricSource }): MetricCurrentTarget {
return { return {
current: current?.current?.averageValue, current: current?.current?.averageValue,
target: target?.target?.averageValue, target: target?.target?.averageValue,
}; };
} }
public getObject({ current, target }: { current: ObjectMetricStatus | undefined; target: ObjectMetricSource }): MetricCurrentTarget { public getObject({ current, target }: { current: V2ObjectMetricStatus | undefined; target: V2ObjectMetricSource }): MetricCurrentTarget {
return { return {
current: ( current: (
current?.current?.value current?.current?.value
@ -38,7 +38,7 @@ export class HorizontalPodAutoscalerV2MetricParser {
}; };
} }
public getExternal({ current, target }: { current: ExternalMetricStatus | undefined; target: ExternalMetricSource }): MetricCurrentTarget { public getExternal({ current, target }: { current: V2ExternalMetricStatus | undefined; target: V2ExternalMetricSource }): MetricCurrentTarget {
const currentAverage = current?.current?.averageValue ? `${current?.current?.averageValue} (avg)` : undefined; const currentAverage = current?.current?.averageValue ? `${current?.current?.averageValue} (avg)` : undefined;
const targetAverage = target?.target?.averageValue ? `${target?.target?.averageValue} (avg)` : undefined; const targetAverage = target?.target?.averageValue ? `${target?.target?.averageValue} (avg)` : undefined;
@ -54,7 +54,7 @@ export class HorizontalPodAutoscalerV2MetricParser {
}; };
} }
public getContainerResource({ current, target }: { current: ContainerResourceMetricStatus | undefined; target: ContainerResourceMetricSource }): MetricCurrentTarget { public getContainerResource({ current, target }: { current: V2ContainerResourceMetricStatus | undefined; target: V2ContainerResourceMetricSource }): MetricCurrentTarget {
return { return {
current: ( current: (
current?.current?.averageValue current?.current?.averageValue