mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Check for legacy targetCPUUtilizationPercentage
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
44a3ba38bf
commit
6f06d3645b
@ -224,6 +224,7 @@ export interface HorizontalPodAutoscalerSpec {
|
||||
maxReplicas: number;
|
||||
metrics?: HorizontalPodAutoscalerMetricSpec[];
|
||||
behavior?: HorizontalPodAutoscalerBehavior;
|
||||
targetCPUUtilizationPercentage?: number; // used only in autoscaling/v1
|
||||
}
|
||||
|
||||
export interface HorizontalPodAutoscalerStatus {
|
||||
@ -231,6 +232,7 @@ export interface HorizontalPodAutoscalerStatus {
|
||||
currentReplicas: number;
|
||||
desiredReplicas: number;
|
||||
currentMetrics?: HorizontalPodAutoscalerMetricStatus[];
|
||||
currentCPUUtilizationPercentage?: number; // used only in autoscaling/v1
|
||||
}
|
||||
|
||||
export class HorizontalPodAutoscaler extends KubeObject<
|
||||
@ -284,13 +286,13 @@ export class HorizontalPodAutoscalerApi extends KubeApi<HorizontalPodAutoscaler>
|
||||
super(deps, {
|
||||
...opts ?? {},
|
||||
objectConstructor: HorizontalPodAutoscaler,
|
||||
// checkPreferredVersion: true,
|
||||
// // Kubernetes < 1.26
|
||||
// fallbackApiBases: [
|
||||
// "/apis/autoscaling/v2beta2/horizontalpodautoscalers",
|
||||
// "/apis/autoscaling/v2beta1/horizontalpodautoscalers",
|
||||
// "/apis/autoscaling/v1/horizontalpodautoscalers",
|
||||
// ],
|
||||
checkPreferredVersion: true,
|
||||
// Kubernetes < 1.26
|
||||
fallbackApiBases: [
|
||||
"/apis/autoscaling/v2beta2/horizontalpodautoscalers",
|
||||
"/apis/autoscaling/v2beta1/horizontalpodautoscalers",
|
||||
"/apis/autoscaling/v1/horizontalpodautoscalers",
|
||||
],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,15 +11,27 @@ const getHorizontalPodAutoscalerMetrics = getInjectable({
|
||||
const hpaV2Parser = di.inject(horizonalPodAutoscalerV2MetricParser);
|
||||
const metrics = hpa.spec?.metrics ?? [];
|
||||
const currentMetrics = hpa.status?.currentMetrics ?? [];
|
||||
const cpuUtilization = hpa.spec?.targetCPUUtilizationPercentage;
|
||||
|
||||
if (cpuUtilization) {
|
||||
const utilizationCurrent = hpa.status?.currentCPUUtilizationPercentage ? `${hpa.status.currentCPUUtilizationPercentage}%` : "unknown";
|
||||
const utilizationTarget = cpuUtilization ? `${cpuUtilization}%` : "unknown";
|
||||
return [`${utilizationCurrent} / ${utilizationTarget}`];
|
||||
}
|
||||
|
||||
return metrics.map((metric) => {
|
||||
const currentMetric = currentMetrics.find(current =>
|
||||
current.type === metric.type
|
||||
&& getMetricName(current) === getMetricName(metric)
|
||||
);
|
||||
const parser = hpa.apiVersion.includes("v2") ? hpaV2Parser : hpaV1Parser;
|
||||
|
||||
const values = getMetricValues(parser, currentMetric, metric);
|
||||
const hpaV2ParserValues = getMetricValues(hpaV2Parser, currentMetric, metric);
|
||||
const hpaV1ParserValues = getMetricValues(hpaV1Parser, currentMetric, metric);
|
||||
let values = hpaV1ParserValues;
|
||||
|
||||
if (hpaV2ParserValues.current || hpaV2ParserValues.target) {
|
||||
values = hpaV2ParserValues;
|
||||
}
|
||||
|
||||
return `${values.current ?? "unknown"} / ${values.target ?? "unknown"}`;
|
||||
});
|
||||
|
||||
@ -43,7 +43,7 @@ class NonInjectedHorizontalPodAutoscalers extends React.Component<Dependencies>
|
||||
getTargets(hpa: HorizontalPodAutoscaler) {
|
||||
const metrics = hpa.getMetrics();
|
||||
|
||||
if (metrics.length === 0) {
|
||||
if (metrics.length === 0 && !hpa.spec?.targetCPUUtilizationPercentage) {
|
||||
return <p>--</p>;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user