mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
part 1
Signed-off-by: Roman <ixrock@gmail.com> Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
1 parent
1f5acdb9cd
commit
7d3e87685b
38 files changed
+260
-435
No files matched your search
@@ -1,10 +1,8 @@
|
||||
import type { WorkspaceId } from "./workspace-store";
|
||||
import path from "path";
|
||||
import filenamify from "filenamify";
|
||||
import { app, ipcRenderer, remote } from "electron";
|
||||
import { copyFile, ensureDir, unlink } from "fs-extra";
|
||||
import { unlink } from "fs-extra";
|
||||
import { action, computed, observable, toJS } from "mobx";
|
||||
import { appProto, noClustersHost } from "./vars";
|
||||
import { BaseStore } from "./base-store";
|
||||
import { Cluster, ClusterState } from "../main/cluster";
|
||||
import migrations from "../migrations/cluster-store"
|
||||
@@ -177,12 +175,11 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
||||
|
||||
export const clusterStore = ClusterStore.getInstance<ClusterStore>();
|
||||
|
||||
export function isNoClustersView() {
|
||||
return location.hostname === noClustersHost
|
||||
}
|
||||
|
||||
export function getHostedClusterId() {
|
||||
return location.hostname.split(".")[0];
|
||||
export function getHostedClusterId(): ClusterId {
|
||||
const clusterHost = location.hostname.match(/^(.*?)\.localhost/);
|
||||
if (clusterHost) {
|
||||
return clusterHost[1]
|
||||
}
|
||||
}
|
||||
|
||||
export function getHostedCluster(): Cluster {
|
||||
|
||||
@@ -156,7 +156,7 @@ export function saveConfigToAppFiles(clusterId: string, kubeConfig: KubeConfig |
|
||||
|
||||
export async function getKubeConfigLocal(): Promise<string> {
|
||||
try {
|
||||
const configFile = path.join(process.env.HOME, '.kube', 'config');
|
||||
const configFile = path.join(os.homedir(), '.kube', 'config');
|
||||
const file = await readFile(configFile, "utf8");
|
||||
const obj = yaml.safeLoad(file);
|
||||
if (obj.contexts) {
|
||||
|
||||
@@ -71,11 +71,12 @@ export class UserStore extends BaseStore<UserStoreModel> {
|
||||
if (kubeConfig) {
|
||||
this.newContexts.clear();
|
||||
const localContexts = loadConfig(kubeConfig).getContexts();
|
||||
console.log(localContexts)
|
||||
localContexts
|
||||
.filter(ctx => ctx.cluster)
|
||||
.filter(ctx => !this.seenContexts.has(ctx.name))
|
||||
.forEach(ctx => this.newContexts.add(ctx.name));
|
||||
localContexts.forEach(({ cluster, name }) => {
|
||||
if (!cluster) return;
|
||||
if (!this.seenContexts.has(name)) {
|
||||
this.newContexts.add(name)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,6 @@ export const isDevelopment = isDebugging || !isProduction;
|
||||
export const isTestEnv = !!process.env.JEST_WORKER_ID;
|
||||
|
||||
export const appName = `${packageInfo.productName}${isDevelopment ? "Dev" : ""}`
|
||||
export const appProto = "lens" // app.getPath("userData") folder
|
||||
export const staticProto = "static" // static folder (e.g. "static://RELEASE_NOTES.md")
|
||||
|
||||
// System paths
|
||||
export const contextDir = process.cwd();
|
||||
@@ -22,9 +20,6 @@ export const rendererDir = path.join(contextDir, "src/renderer");
|
||||
export const htmlTemplate = path.resolve(rendererDir, "template.html");
|
||||
export const sassCommonVars = path.resolve(rendererDir, "components/vars.scss");
|
||||
|
||||
// System pages
|
||||
export const noClustersHost = "no-clusters.localhost"
|
||||
|
||||
// Apis
|
||||
export const apiPrefix = "/api" // local router apis
|
||||
export const apiKubePrefix = "/api-kube" // k8s cluster apis
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { action, computed, observable, toJS } from "mobx";
|
||||
import { action, computed, observable, reaction, toJS } from "mobx";
|
||||
import { BaseStore } from "./base-store";
|
||||
import { clusterStore } from "./cluster-store"
|
||||
|
||||
@@ -22,6 +22,15 @@ export class WorkspaceStore extends BaseStore<WorkspaceStoreModel> {
|
||||
super({
|
||||
configName: "lens-workspace-store",
|
||||
});
|
||||
|
||||
// switch to first available cluster in current workspace
|
||||
reaction(() => this.currentWorkspaceId, workspaceId => {
|
||||
const clusters = clusterStore.getByWorkspaceId(workspaceId);
|
||||
const activeClusterInWorkspace = clusters.some(cluster => cluster.id === clusterStore.activeClusterId);
|
||||
if (!activeClusterInWorkspace) {
|
||||
clusterStore.activeClusterId = clusters.length ? clusters[0].id : null;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@observable currentWorkspaceId = WorkspaceStore.defaultId;
|
||||
|
||||
Reference in new issue
Block a user