mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
introducing vpa resources (#7004)
* introducing vpa resources (as hpa resources to start) vpa spec (WIP) adding real vpa fields scss files, and updates after rebase on master scss update tweaks to vpa api definition putting more fields into the vpa list adding vpa details, fixing vpa spec implementation (WIP) vpa details page done merge conflicts Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com> * moved files after monorepo merge Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com> * address review comments, added vpa endpoint to endpoints export list Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com> * deprecate HPAStore in favour of HorizontalPodAuotoscalerStore Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com> --------- Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com>
This commit is contained in:
1 parent
e196ca56eb
commit
a8a59ff191
41 files changed
+796
-9
No files matched your search
+20
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import verticalPodAutoscalersRouteInjectable from "./vertical-pod-autoscalers-route.injectable";
|
||||
import { navigateToRouteInjectionToken } from "../../../../navigate-to-route-injection-token";
|
||||
|
||||
const navigateToVerticalPodAutoscalersInjectable = getInjectable({
|
||||
id: "navigate-to-vertical-pod-autoscalers",
|
||||
|
||||
instantiate: (di) => {
|
||||
const navigateToRoute = di.inject(navigateToRouteInjectionToken);
|
||||
const route = di.inject(verticalPodAutoscalersRouteInjectable);
|
||||
|
||||
return () => navigateToRoute(route);
|
||||
},
|
||||
});
|
||||
|
||||
export default navigateToVerticalPodAutoscalersInjectable;
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token";
|
||||
import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token";
|
||||
|
||||
const verticalPodAutoscalersRouteInjectable = getInjectable({
|
||||
id: "vertical-pod-autoscalers-route",
|
||||
|
||||
instantiate: (di) => ({
|
||||
path: "/vpa",
|
||||
clusterFrame: true,
|
||||
isEnabled: di.inject(shouldShowResourceInjectionToken, {
|
||||
apiName: "verticalpodautoscalers",
|
||||
group: "autoscaling.k8s.io",
|
||||
}),
|
||||
}),
|
||||
|
||||
injectionToken: frontEndRouteInjectionToken,
|
||||
});
|
||||
|
||||
export default verticalPodAutoscalersRouteInjectable;
|
||||
@@ -8,6 +8,7 @@ import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { BaseKubeObjectCondition, LabelSelector, NamespaceScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { CrossVersionObjectReference } from "./types/cross-version-object-reference";
|
||||
|
||||
export enum HpaMetricType {
|
||||
Resource = "Resource",
|
||||
@@ -299,12 +300,6 @@ export type HorizontalPodAutoscalerMetricStatus =
|
||||
| OptionVarient<HpaMetricType.Pods, BaseHorizontalPodAutoscalerMetricStatus, "pods">
|
||||
| OptionVarient<HpaMetricType.ContainerResource, BaseHorizontalPodAutoscalerMetricStatus, "containerResource">;
|
||||
|
||||
export interface CrossVersionObjectReference {
|
||||
kind: string;
|
||||
name: string;
|
||||
apiVersion: string;
|
||||
}
|
||||
|
||||
export interface HorizontalPodAutoscalerSpec {
|
||||
scaleTargetRef: CrossVersionObjectReference;
|
||||
minReplicas?: number;
|
||||
|
||||
@@ -44,3 +44,4 @@ export * from "./service-account.api";
|
||||
export * from "./stateful-set.api";
|
||||
export * from "./storage-class.api";
|
||||
export * from "./types";
|
||||
export * from "./vertical-pod-autoscaler.api";
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
export interface CrossVersionObjectReference {
|
||||
kind: string;
|
||||
name: string;
|
||||
apiVersion: string;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ export * from "./aggregation-rule";
|
||||
export * from "./capabilities";
|
||||
export * from "./container";
|
||||
export * from "./container-port";
|
||||
export * from "./cross-version-object-reference";
|
||||
export * from "./env-from-source";
|
||||
export * from "./env-source";
|
||||
export * from "./env-var-key-selector";
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { VerticalPodAutoscalerApi } from "./vertical-pod-autoscaler.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const verticalPodAutoscalerApiInjectable = getInjectable({
|
||||
id: "vertical-pod-autoscaler-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "verticalPodAutoscalerApi is only available in certain environments");
|
||||
|
||||
return new VerticalPodAutoscalerApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
});
|
||||
|
||||
export default verticalPodAutoscalerApiInjectable;
|
||||
@@ -0,0 +1,149 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { BaseKubeObjectCondition, NamespaceScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { CrossVersionObjectReference } from "./types/cross-version-object-reference";
|
||||
|
||||
export enum ResourceName {
|
||||
ResourceCPU = "cpu",
|
||||
ResourceMemory = "memory",
|
||||
ResourceStorage = "storage",
|
||||
}
|
||||
|
||||
export type ResourceList = Partial<Record<string, string>>;
|
||||
|
||||
export interface RecommendedContainerResources {
|
||||
containerName?: string;
|
||||
target: ResourceList;
|
||||
lowerBound?: ResourceList;
|
||||
upperBound?: ResourceList;
|
||||
uncappedTarget?: ResourceList;
|
||||
}
|
||||
export interface RecommendedPodResources {
|
||||
containerRecommendations?: RecommendedContainerResources[];
|
||||
}
|
||||
|
||||
export interface VerticalPodAutoscalerStatus {
|
||||
conditions?: BaseKubeObjectCondition[];
|
||||
recommendation?: RecommendedPodResources;
|
||||
}
|
||||
|
||||
export interface VerticalPodAutoscalerRecommenderSelector {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export enum ContainerScalingMode {
|
||||
ContainerScalingModeAuto = "Auto",
|
||||
ContainerScalingModeOff = "Off",
|
||||
}
|
||||
|
||||
export enum ControlledValues {
|
||||
ControlledValueRequestsAndLimits = "RequestsAndLimits",
|
||||
ControlledValueRequestsOnly = "RequestsOnly",
|
||||
}
|
||||
|
||||
/**
|
||||
* ContainerResourcePolicy controls how autoscaler computes the recommended resources for
|
||||
* a specific container.
|
||||
*/
|
||||
export interface ContainerResourcePolicy {
|
||||
containerName?: string;
|
||||
mode?: ContainerScalingMode;
|
||||
minAllowed?: ResourceList;
|
||||
maxAllowed?: ResourceList;
|
||||
controlledResources?: ResourceName[];
|
||||
controlledValues?: ControlledValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Controls how the autoscaler computes recommended resources.
|
||||
* The resource policy may be used to set constraints on the recommendations for individual
|
||||
* containers.
|
||||
* If not specified, the autoscaler computes recommended resources for all containers in the
|
||||
* pod, without additional constraints.
|
||||
*/
|
||||
export interface PodResourcePolicy {
|
||||
containerPolicies?: ContainerResourcePolicy[]; // Per-container resource policies.
|
||||
}
|
||||
|
||||
export enum UpdateMode {
|
||||
/**
|
||||
* UpdateModeOff means that autoscaler never changes Pod resources.
|
||||
* The recommender still sets the recommended resources in the
|
||||
* VerticalPodAutoscaler object. This can be used for a "dry run".
|
||||
*/
|
||||
UpdateModeOff = "Off",
|
||||
/**
|
||||
* UpdateModeInitial means that autoscaler only assigns resources on pod
|
||||
* creation and does not change them during the lifetime of the pod.
|
||||
*/
|
||||
UpdateModeInitial = "Initial",
|
||||
/**
|
||||
* UpdateModeRecreate means that autoscaler assigns resources on pod
|
||||
* creation and additionally can update them during the lifetime of the
|
||||
* pod by deleting and recreating the pod.
|
||||
*/
|
||||
UpdateModeRecreate = "Recreate",
|
||||
/**
|
||||
* UpdateModeAuto means that autoscaler assigns resources on pod creation
|
||||
* and additionally can update them during the lifetime of the pod,
|
||||
* using any available update method. Currently this is equivalent to
|
||||
* Recreate, which is the only available update method.
|
||||
*/
|
||||
UpdateModeAuto = "Auto",
|
||||
}
|
||||
export interface PodUpdatePolicy {
|
||||
minReplicas?: number;
|
||||
updateMode?: UpdateMode;
|
||||
}
|
||||
|
||||
export interface VerticalPodAutoscalerSpec {
|
||||
targetRef: CrossVersionObjectReference;
|
||||
updatePolicy?: PodUpdatePolicy;
|
||||
resourcePolicy?: PodResourcePolicy;
|
||||
recommenders?: VerticalPodAutoscalerRecommenderSelector[];
|
||||
}
|
||||
|
||||
export class VerticalPodAutoscaler extends KubeObject<
|
||||
NamespaceScopedMetadata,
|
||||
VerticalPodAutoscalerStatus,
|
||||
VerticalPodAutoscalerSpec
|
||||
> {
|
||||
static readonly kind = "VerticalPodAutoscaler";
|
||||
static readonly namespaced = true;
|
||||
static readonly apiBase = "/apis/autoscaling.k8s.io/v1/verticalpodautoscalers";
|
||||
|
||||
getReadyConditions() {
|
||||
return this.getConditions().filter(({ isReady }) => isReady);
|
||||
}
|
||||
|
||||
getConditions() {
|
||||
return this.status?.conditions?.map(condition => {
|
||||
const { message, reason, lastTransitionTime, status } = condition;
|
||||
|
||||
return {
|
||||
...condition,
|
||||
isReady: status === "True",
|
||||
tooltip: `${message || reason || ""} (${lastTransitionTime})`,
|
||||
};
|
||||
}) ?? [];
|
||||
}
|
||||
|
||||
getMode() {
|
||||
return this.spec.updatePolicy?.updateMode ?? UpdateMode.UpdateModeAuto;
|
||||
}
|
||||
}
|
||||
|
||||
export class VerticalPodAutoscalerApi extends KubeApi<VerticalPodAutoscaler> {
|
||||
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
|
||||
super(deps, {
|
||||
...opts ?? {},
|
||||
objectConstructor: VerticalPodAutoscaler,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ export type KubeResource =
|
||||
"namespaces" | "nodes" | "events" | "resourcequotas" | "services" | "limitranges" | "leases" |
|
||||
"secrets" | "configmaps" | "ingresses" | "ingressclasses" | "networkpolicies" | "persistentvolumeclaims" | "persistentvolumes" | "storageclasses" |
|
||||
"pods" | "daemonsets" | "deployments" | "statefulsets" | "replicasets" | "jobs" | "cronjobs" |
|
||||
"endpoints" | "customresourcedefinitions" | "horizontalpodautoscalers" | "podsecuritypolicies" | "poddisruptionbudgets" |
|
||||
"endpoints" | "customresourcedefinitions" | "horizontalpodautoscalers" | "verticalpodautoscalers" | "podsecuritypolicies" | "poddisruptionbudgets" |
|
||||
"priorityclasses" | "runtimeclasses" |
|
||||
"roles" | "clusterroles" | "rolebindings" | "clusterrolebindings" | "serviceaccounts";
|
||||
|
||||
@@ -206,4 +206,9 @@ export const apiResourceRecord: Record<KubeResource, KubeApiResourceData> = {
|
||||
group: "storage.k8s.io",
|
||||
namespaced: false,
|
||||
},
|
||||
verticalpodautoscalers: {
|
||||
kind: "VerticalPodAutoscaler",
|
||||
group: "autoscaling.k8s.io",
|
||||
namespaced: true,
|
||||
},
|
||||
};
|
||||
Reference in new issue
Block a user