1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/renderer/components/context.ts
Jari Kolehmainen 317c4cf072
Fix accessible namespaces functionality under restrictive RBAC (#2138)
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
2021-02-12 14:25:17 +02:00

39 lines
1.1 KiB
TypeScript
Executable File

import type { Cluster } from "../../main/cluster";
import { getHostedCluster } from "../../common/cluster-store";
import { namespaceStore } from "./+namespaces/namespace.store";
export interface ClusterContext {
cluster?: Cluster;
allNamespaces?: string[]; // available / allowed namespaces from cluster.ts
contextNamespaces?: string[]; // selected by user (see: namespace-select.tsx)
}
export const clusterContext: ClusterContext = {
get cluster(): Cluster | null {
return getHostedCluster();
},
get allNamespaces(): string[] {
if (!this.cluster) {
return [];
}
// user given list of namespaces
if (this.cluster?.accessibleNamespaces.length) {
return this.cluster.accessibleNamespaces;
}
if (namespaceStore.items.length > 0) {
// namespaces from kubernetes api
return namespaceStore.items.map((namespace) => namespace.getName());
} else {
// fallback to cluster resolved namespaces because we could not load list
return this.cluster.allowedNamespaces || [];
}
},
get contextNamespaces(): string[] {
return namespaceStore.contextNamespaces ?? [];
},
};