mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
make getRenderInfoByWorkspace private to Lens only, not extensions
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
76f0bdcaca
commit
2daff2da0b
2
Makefile
2
Makefile
@ -13,7 +13,7 @@ binaries/client:
|
|||||||
yarn download-bins
|
yarn download-bins
|
||||||
|
|
||||||
node_modules:
|
node_modules:
|
||||||
yarn install --frozen-lockfile --verbose
|
yarn install --frozen-lockfile
|
||||||
yarn check --verify-tree --integrity
|
yarn check --verify-tree --integrity
|
||||||
|
|
||||||
static/build/LensDev.html:
|
static/build/LensDev.html:
|
||||||
|
|||||||
2
extensions/example-extension/package-lock.json
generated
2
extensions/example-extension/package-lock.json
generated
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "extension-example",
|
"name": "example-extension",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
|
|||||||
@ -78,19 +78,17 @@ export interface ClusterPrometheusPreferences {
|
|||||||
|
|
||||||
export interface ClusterRenderInfo extends ClusterModel {
|
export interface ClusterRenderInfo extends ClusterModel {
|
||||||
DeadError?: LoadKubeError; // this != undefined => dead
|
DeadError?: LoadKubeError; // this != undefined => dead
|
||||||
isAdmin: boolean;
|
|
||||||
name: string;
|
name: string;
|
||||||
eventCount: number;
|
|
||||||
online: boolean;
|
online: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
export class LensClusterStoreImpl extends BaseStore<ClusterStoreModel> {
|
||||||
static getCustomKubeConfigPath(clusterId: ClusterId): string {
|
static getCustomKubeConfigPath(clusterId: ClusterId): string {
|
||||||
return path.resolve((app || remote.app).getPath("userData"), "kubeconfigs", clusterId);
|
return path.resolve((app || remote.app).getPath("userData"), "kubeconfigs", clusterId);
|
||||||
}
|
}
|
||||||
|
|
||||||
static embedCustomKubeConfig(clusterId: ClusterId, kubeConfig: KubeConfig | string): string {
|
static embedCustomKubeConfig(clusterId: ClusterId, kubeConfig: KubeConfig | string): string {
|
||||||
const filePath = ClusterStore.getCustomKubeConfigPath(clusterId);
|
const filePath = LensClusterStoreImpl.getCustomKubeConfigPath(clusterId);
|
||||||
const fileContents = typeof kubeConfig == "string" ? kubeConfig : dumpConfigYaml(kubeConfig);
|
const fileContents = typeof kubeConfig == "string" ? kubeConfig : dumpConfigYaml(kubeConfig);
|
||||||
saveToAppFiles(filePath, fileContents, { mode: 0o600 });
|
saveToAppFiles(filePath, fileContents, { mode: 0o600 });
|
||||||
return filePath;
|
return filePath;
|
||||||
@ -101,7 +99,7 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
|||||||
@observable clusters = observable.map<ClusterId, Cluster>();
|
@observable clusters = observable.map<ClusterId, Cluster>();
|
||||||
@observable deadClusters = observable.map<ClusterId, [ClusterModel, LoadKubeError]>();
|
@observable deadClusters = observable.map<ClusterId, [ClusterModel, LoadKubeError]>();
|
||||||
|
|
||||||
private constructor() {
|
protected constructor() {
|
||||||
super({
|
super({
|
||||||
configName: "lens-cluster-store",
|
configName: "lens-cluster-store",
|
||||||
accessPropertiesByDotNotation: false, // To make dots safe in cluster context names
|
accessPropertiesByDotNotation: false, // To make dots safe in cluster context names
|
||||||
@ -202,15 +200,13 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
|||||||
return this.deadClusters.get(id);
|
return this.deadClusters.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
getRendererInfoByWorkspace(workspaceId: string): ClusterRenderInfo[] {
|
protected getRendererInfoByWorkspace(workspaceId: string): ClusterRenderInfo[] {
|
||||||
const aliveClusters: ClusterRenderInfo[] = this.clustersList.filter(c => c.workspace === workspaceId);
|
const aliveClusters: ClusterRenderInfo[] = this.clustersList.filter(c => c.workspace === workspaceId);
|
||||||
const deadClusters: ClusterRenderInfo[] = this.deadClustersList
|
const deadClusters: ClusterRenderInfo[] = this.deadClustersList
|
||||||
.filter(([c]) => c.workspace === workspaceId)
|
.filter(([c]) => c.workspace === workspaceId)
|
||||||
.map(([cluster, error]) => ({
|
.map(([cluster, error]) => ({
|
||||||
DeadError: error,
|
DeadError: error,
|
||||||
name: cluster.contextName,
|
name: cluster.contextName,
|
||||||
isAdmin: false,
|
|
||||||
eventCount: 0,
|
|
||||||
online: false,
|
online: false,
|
||||||
...cluster,
|
...cluster,
|
||||||
}));
|
}));
|
||||||
@ -266,7 +262,7 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
|||||||
this.setActive(null);
|
this.setActive(null);
|
||||||
}
|
}
|
||||||
// remove only custom kubeconfigs (pasted as text)
|
// remove only custom kubeconfigs (pasted as text)
|
||||||
if (cluster.kubeConfigPath == ClusterStore.getCustomKubeConfigPath(clusterId)) {
|
if (cluster.kubeConfigPath == LensClusterStoreImpl.getCustomKubeConfigPath(clusterId)) {
|
||||||
unlink(cluster.kubeConfigPath).catch(() => null);
|
unlink(cluster.kubeConfigPath).catch(() => null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -352,7 +348,20 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class LensClusterStore extends LensClusterStoreImpl {
|
||||||
|
public getRendererInfoByWorkspace(workspaceId: string): ClusterRenderInfo[] {
|
||||||
|
return super.getRendererInfoByWorkspace(workspaceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ClusterStore extends LensClusterStoreImpl {
|
||||||
|
private constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const clusterStore = ClusterStore.getInstance<ClusterStore>();
|
export const clusterStore = ClusterStore.getInstance<ClusterStore>();
|
||||||
|
export const lensClusterStore = clusterStore as LensClusterStore;
|
||||||
|
|
||||||
export function getClusterIdFromHost(hostname: string): ClusterId {
|
export function getClusterIdFromHost(hostname: string): ClusterId {
|
||||||
const subDomains = hostname.split(":")[0].split(".");
|
const subDomains = hostname.split(":")[0].split(".");
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import { autorun } from "mobx";
|
|||||||
import { showAbout } from "./menu";
|
import { showAbout } from "./menu";
|
||||||
import { AppUpdater } from "./app-updater";
|
import { AppUpdater } from "./app-updater";
|
||||||
import { WindowManager } from "./window-manager";
|
import { WindowManager } from "./window-manager";
|
||||||
import { ClusterRenderInfo, clusterStore } from "../common/cluster-store";
|
import { ClusterRenderInfo, clusterStore, lensClusterStore } from "../common/cluster-store";
|
||||||
import { Workspace, workspaceStore } from "../common/workspace-store";
|
import { Workspace, workspaceStore } from "../common/workspace-store";
|
||||||
import { preferencesURL } from "../renderer/components/+preferences/preferences.route";
|
import { preferencesURL } from "../renderer/components/+preferences/preferences.route";
|
||||||
import { clusterViewURL } from "../renderer/components/cluster-manager/cluster-view.route";
|
import { clusterViewURL } from "../renderer/components/cluster-manager/cluster-view.route";
|
||||||
@ -82,7 +82,7 @@ export function createTrayMenu(windowManager: WindowManager): Menu {
|
|||||||
{
|
{
|
||||||
label: "Clusters",
|
label: "Clusters",
|
||||||
submenu: workspaceStore.enabledWorkspacesList
|
submenu: workspaceStore.enabledWorkspacesList
|
||||||
.map((workspace): [Workspace, ClusterRenderInfo[]] => [workspace, clusterStore.getRendererInfoByWorkspace(workspace.id)])
|
.map((workspace): [Workspace, ClusterRenderInfo[]] => [workspace, lensClusterStore.getRendererInfoByWorkspace(workspace.id)])
|
||||||
.filter(([, clusters]) => clusters.length > 0)
|
.filter(([, clusters]) => clusters.length > 0)
|
||||||
.map(([workspace, clusters]): MenuItemConstructorOptions => ({
|
.map(([workspace, clusters]): MenuItemConstructorOptions => ({
|
||||||
label: workspace.name,
|
label: workspace.name,
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import { observer } from "mobx-react";
|
|||||||
import { _i18n } from "../../i18n";
|
import { _i18n } from "../../i18n";
|
||||||
import { t, Trans } from "@lingui/macro";
|
import { t, Trans } from "@lingui/macro";
|
||||||
import { userStore } from "../../../common/user-store";
|
import { userStore } from "../../../common/user-store";
|
||||||
import { ClusterId, ClusterRenderInfo, clusterStore } from "../../../common/cluster-store";
|
import { ClusterId, ClusterRenderInfo, clusterStore, lensClusterStore } from "../../../common/cluster-store";
|
||||||
import { workspaceStore } from "../../../common/workspace-store";
|
import { workspaceStore } from "../../../common/workspace-store";
|
||||||
import { ClusterIcon } from "../cluster-icon";
|
import { ClusterIcon } from "../cluster-icon";
|
||||||
import { Icon } from "../icon";
|
import { Icon } from "../icon";
|
||||||
@ -105,7 +105,7 @@ export class ClusterMenu extends React.Component<Props> {
|
|||||||
const { className } = this.props;
|
const { className } = this.props;
|
||||||
const { newContexts } = userStore;
|
const { newContexts } = userStore;
|
||||||
const workspace = workspaceStore.getById(workspaceStore.currentWorkspaceId);
|
const workspace = workspaceStore.getById(workspaceStore.currentWorkspaceId);
|
||||||
const clusters = clusterStore.getRendererInfoByWorkspace(workspace.id);
|
const clusters = lensClusterStore.getRendererInfoByWorkspace(workspace.id);
|
||||||
const activeClusterId = clusterStore.activeCluster;
|
const activeClusterId = clusterStore.activeCluster;
|
||||||
return (
|
return (
|
||||||
<div className={cssNames("ClustersMenu flex column", className)}>
|
<div className={cssNames("ClustersMenu flex column", className)}>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user