1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/common/k8s-api/endpoints/namespaces.api.ts
Sebastian Malton f594bf03f3 Turn on strict mode in tsconfig.json
- Add route, clusterRoute, and payloadValidatedClusterRoute helper
  functions to improve types with backend routes

- Turn on the following new lints:
  - react/jsx-first-prop-new-line
  - react/jsx-wrap-multilines
  - react/jsx-one-expression-per-line
  - react/jsx-max-props-per-line
  - react/jsx-indent
  - react/jsx-indent-props

Signed-off-by: Sebastian Malton <sebastian@malton.name>
2022-05-04 08:45:50 -04:00

66 lines
1.6 KiB
TypeScript

/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { KubeApi } from "../kube-api";
import type { KubeObjectStatus } from "../kube-object";
import { KubeObject } from "../kube-object";
import { metricsApi } from "./metrics.api";
import type { PodMetricData } from "./pods.api";
import { isClusterPageContext } from "../../utils/cluster-id-url-parsing";
export enum NamespaceStatusKind {
ACTIVE = "Active",
TERMINATING = "Terminating",
}
export interface NamespaceSpec {
finalizers?: string[];
}
export interface NamespaceStatus extends KubeObjectStatus {
phase?: string;
}
export class Namespace extends KubeObject<NamespaceStatus, NamespaceSpec, "cluster-scoped"> {
static readonly kind = "Namespace";
static readonly namespaced = false;
static readonly apiBase = "/api/v1/namespaces";
getStatus() {
return this.status?.phase ?? "-";
}
}
export class NamespaceApi extends KubeApi<Namespace> {
}
export function getMetricsForNamespace(namespace: string, selector = ""): Promise<PodMetricData> {
const opts = { category: "pods", pods: ".*", namespace, selector };
return metricsApi.getMetrics({
cpuUsage: opts,
memoryUsage: opts,
fsUsage: opts,
fsWrites: opts,
fsReads: opts,
networkReceive: opts,
networkTransmit: opts,
}, {
namespace,
});
}
let namespacesApi: NamespaceApi;
if (isClusterPageContext()) {
namespacesApi = new NamespaceApi({
objectConstructor: Namespace,
});
}
export {
namespacesApi,
};