mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
clean up, debugging
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
33d7036939
commit
8bb3954700
@ -55,10 +55,6 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
||||
return Array.from(this.clusters.values());
|
||||
}
|
||||
|
||||
@computed get inactiveClusters() {
|
||||
return Array.from(this.clusters.values()).filter(cluster => !cluster.initialized);
|
||||
}
|
||||
|
||||
getById(id: ClusterId): Cluster {
|
||||
return this.clusters.get(id);
|
||||
}
|
||||
|
||||
@ -3,3 +3,4 @@
|
||||
export * from "./base64"
|
||||
export * from "./camelCase"
|
||||
export * from "./splitArray"
|
||||
export * from "./randomFileName"
|
||||
|
||||
@ -1,10 +1,4 @@
|
||||
import fs from "fs"
|
||||
|
||||
export function ensureDir(dirname: string) {
|
||||
if (!fs.existsSync(dirname)) {
|
||||
fs.mkdirSync(dirname)
|
||||
}
|
||||
}
|
||||
// Creates system valid random filename
|
||||
|
||||
export function randomFileName(name: string) {
|
||||
return `${Math.random().toString(36).substring(2, 15)}-${Math.random().toString(36).substring(2, 15)}-${name}`
|
||||
@ -26,9 +26,10 @@ export class ClusterManager {
|
||||
}
|
||||
|
||||
constructor(public readonly proxyPort: number) {
|
||||
// auto-init fresh clusters
|
||||
// auto-init clusters
|
||||
autorun(() => {
|
||||
clusterStore.inactiveClusters.forEach(cluster => {
|
||||
const freshClusters = clusterStore.clustersList.filter(cluster => !cluster.initialized);
|
||||
freshClusters.forEach(cluster => {
|
||||
cluster.init().then(() => cluster.refreshCluster());
|
||||
});
|
||||
});
|
||||
|
||||
@ -42,7 +42,7 @@ export class Cluster implements ClusterModel {
|
||||
@observable kubeConfigPath: string;
|
||||
@observable contextName: string;
|
||||
@observable port: number;
|
||||
@observable url: string;
|
||||
@observable url: string; // cluster-api url
|
||||
@observable apiUrl: UrlWithStringQuery; // same as url, but parsed
|
||||
@observable kubeAuthProxyUrl: string;
|
||||
@observable webContentUrl: string;
|
||||
@ -66,6 +66,7 @@ export class Cluster implements ClusterModel {
|
||||
}
|
||||
|
||||
@action
|
||||
// fixme: completely broken
|
||||
async init() {
|
||||
try {
|
||||
this.contextHandler = new ContextHandler(this);
|
||||
@ -76,7 +77,7 @@ export class Cluster implements ClusterModel {
|
||||
this.kubeconfigManager = new KubeconfigManager(this);
|
||||
this.url = this.kubeconfigManager.getCurrentClusterServer();
|
||||
this.apiUrl = url.parse(this.url);
|
||||
logger.info(`[CLUSTER]: INIT`, {
|
||||
logger.info(`[CLUSTER]: init success`, {
|
||||
id: this.id,
|
||||
port: this.port,
|
||||
url: this.url,
|
||||
@ -85,7 +86,7 @@ export class Cluster implements ClusterModel {
|
||||
});
|
||||
this.initialized = true;
|
||||
} catch (err) {
|
||||
logger.error(`[CLUSTER]: INIT FAILED`, {
|
||||
logger.error(`[CLUSTER]: init error`, {
|
||||
id: this.id,
|
||||
error: err.stack,
|
||||
});
|
||||
@ -128,10 +129,6 @@ export class Cluster implements ClusterModel {
|
||||
return kc
|
||||
}
|
||||
|
||||
stopServer() {
|
||||
this.contextHandler.stopServer()
|
||||
}
|
||||
|
||||
async installFeature(name: string, config: any) {
|
||||
await installFeature(name, this, config)
|
||||
await this.refreshCluster()
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import type { Cluster } from "./cluster"
|
||||
import { app } from "electron"
|
||||
import fs from "fs"
|
||||
import fs from "fs-extra"
|
||||
import { KubeConfig } from "@kubernetes/client-node"
|
||||
import { ensureDir, randomFileName } from "./file-helpers"
|
||||
import { randomFileName } from "../common/utils"
|
||||
import { dumpConfigYaml, loadKubeConfig } from "./k8s"
|
||||
import logger from "./logger"
|
||||
|
||||
@ -34,7 +34,7 @@ export class KubeconfigManager {
|
||||
* This way any user of the config does not need to know anything about the auth etc. details.
|
||||
*/
|
||||
protected createTemporaryKubeconfig(): string {
|
||||
ensureDir(this.configDir);
|
||||
fs.ensureDir(this.configDir);
|
||||
const path = `${this.configDir}/${randomFileName("kubeconfig")}`;
|
||||
const { contextName, kubeAuthProxyUrl } = this.cluster;
|
||||
const kubeConfig = this.loadConfig();
|
||||
@ -57,7 +57,7 @@ export class KubeconfigManager {
|
||||
}
|
||||
];
|
||||
fs.writeFileSync(path, dumpConfigYaml(kubeConfig));
|
||||
logger.info(`Created temp kube-config file at "${path}"`);
|
||||
logger.info(`Created temp kube-config file for context "${this.cluster.contextName}" at "${path}"`);
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
@ -29,8 +29,8 @@ export class LensProxy {
|
||||
listen(): this {
|
||||
const proxyServer = this.buildProxyServer();
|
||||
const { proxyPort } = this.clusterManager;
|
||||
this.proxyServer = proxyServer.listen(proxyPort, "127.0.0.1");
|
||||
logger.info(`Lens proxy server started at ${proxyPort}`);
|
||||
this.proxyServer = proxyServer.listen(proxyPort);
|
||||
logger.info(`LensProxy server has started http://localhost:${proxyPort}`);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user