/** * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ import type { NamespaceScopedMetadata } from "../kube-object"; import { KubeObject } from "../kube-object"; import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api"; import { KubeApi } from "../kube-api"; export enum LimitType { CONTAINER = "Container", POD = "Pod", PVC = "PersistentVolumeClaim", } export enum Resource { MEMORY = "memory", CPU = "cpu", STORAGE = "storage", EPHEMERAL_STORAGE = "ephemeral-storage", } export enum LimitPart { MAX = "max", MIN = "min", DEFAULT = "default", DEFAULT_REQUEST = "defaultRequest", MAX_LIMIT_REQUEST_RATIO = "maxLimitRequestRatio", } type LimitRangeParts = Partial>>; export interface LimitRangeItem extends LimitRangeParts { type: string; } export interface LimitRangeSpec { limits: LimitRangeItem[]; } export class LimitRange extends KubeObject< NamespaceScopedMetadata, void, LimitRangeSpec > { static readonly kind = "LimitRange"; static readonly namespaced = true; static readonly apiBase = "/api/v1/limitranges"; getContainerLimits() { return this.spec.limits.filter(limit => limit.type === LimitType.CONTAINER); } getPodLimits() { return this.spec.limits.filter(limit => limit.type === LimitType.POD); } getPVCLimits() { return this.spec.limits.filter(limit => limit.type === LimitType.PVC); } } export class LimitRangeApi extends KubeApi { constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) { super(deps, { objectConstructor: LimitRange, ...opts ?? {}, }); } }