1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Use moved kc folder functions

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-07-29 15:27:12 -04:00
parent 97e8925c5c
commit 48009b7fc5
4 changed files with 11 additions and 23 deletions

View File

@ -19,13 +19,11 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
import path from "path"; import { ipcMain, ipcRenderer, webFrame } from "electron";
import { app, ipcMain, ipcRenderer, remote, webFrame } from "electron";
import { action, comparer, computed, makeObservable, observable, reaction } from "mobx"; import { action, comparer, computed, makeObservable, observable, reaction } from "mobx";
import { BaseStore } from "./base-store"; import { BaseStore } from "./base-store";
import { Cluster } from "../main/cluster"; import { Cluster } from "../main/cluster";
import migrations from "../migrations/cluster-store"; import migrations from "../migrations/cluster-store";
import * as uuid from "uuid";
import logger from "../main/logger"; import logger from "../main/logger";
import { appEventBus } from "./event-bus"; import { appEventBus } from "./event-bus";
import { ipcMainHandle, ipcMainOn, ipcRendererOn, requestMain } from "./ipc"; import { ipcMainHandle, ipcMainOn, ipcRendererOn, requestMain } from "./ipc";
@ -38,19 +36,9 @@ export interface ClusterStoreModel {
const initialStates = "cluster:states"; const initialStates = "cluster:states";
export const initialNodeShellImage = "docker.io/alpine:3.13";
export class ClusterStore extends BaseStore<ClusterStoreModel> { export class ClusterStore extends BaseStore<ClusterStoreModel> {
private static StateChannel = "cluster:state"; private static StateChannel = "cluster:state";
static get storedKubeConfigFolder(): string {
return path.resolve((app ?? remote.app).getPath("userData"), "kubeconfigs");
}
static getCustomKubeConfigPath(clusterId: ClusterId = uuid.v4()): string {
return path.resolve(ClusterStore.storedKubeConfigFolder, clusterId);
}
clusters = observable.map<ClusterId, Cluster>(); clusters = observable.map<ClusterId, Cluster>();
removedClusters = observable.map<ClusterId, Cluster>(); removedClusters = observable.map<ClusterId, Cluster>();

View File

@ -26,7 +26,7 @@ import { watch } from "chokidar";
import fs from "fs"; import fs from "fs";
import fse from "fs-extra"; import fse from "fs-extra";
import type stream from "stream"; import type stream from "stream";
import { Disposer, ExtendedObservableMap, iter, Singleton } from "../../common/utils"; import { Disposer, ExtendedObservableMap, iter, Singleton, storedKubeConfigFolder } from "../../common/utils";
import logger from "../logger"; import logger from "../logger";
import type { KubeConfig } from "@kubernetes/client-node"; import type { KubeConfig } from "@kubernetes/client-node";
import { loadConfigFromString, splitConfig } from "../../common/kube-helpers"; import { loadConfigFromString, splitConfig } from "../../common/kube-helpers";
@ -71,7 +71,7 @@ export class KubeconfigSyncManager extends Singleton {
))); )));
// This must be done so that c&p-ed clusters are visible // This must be done so that c&p-ed clusters are visible
this.startNewSync(ClusterStore.storedKubeConfigFolder); this.startNewSync(storedKubeConfigFolder());
for (const filePath of UserStore.getInstance().syncKubeconfigEntries.keys()) { for (const filePath of UserStore.getInstance().syncKubeconfigEntries.keys()) {
this.startNewSync(filePath); this.startNewSync(filePath);
@ -202,7 +202,7 @@ export function computeDiff(contents: string, source: RootSource, filePath: stri
const entity = catalogEntityFromCluster(cluster); const entity = catalogEntityFromCluster(cluster);
if (!filePath.startsWith(ClusterStore.storedKubeConfigFolder)) { if (!filePath.startsWith(storedKubeConfigFolder())) {
entity.metadata.labels.file = filePath.replace(homedir(), "~"); entity.metadata.labels.file = filePath.replace(homedir(), "~");
} }
source.set(contextName, [cluster, entity]); source.set(contextName, [cluster, entity]);

View File

@ -25,10 +25,10 @@
import path from "path"; import path from "path";
import { app } from "electron"; import { app } from "electron";
import fse from "fs-extra"; import fse from "fs-extra";
import { ClusterStore } from "../../common/cluster-store";
import { loadConfigFromFileSync } from "../../common/kube-helpers"; import { loadConfigFromFileSync } from "../../common/kube-helpers";
import { MigrationDeclaration, migrationLog } from "../helpers"; import { MigrationDeclaration, migrationLog } from "../helpers";
import type { ClusterModel } from "../../common/cluster-types"; import type { ClusterModel } from "../../common/cluster-types";
import { getCustomKubeConfigPath, storedKubeConfigFolder } from "../../common/utils";
interface Pre360ClusterModel extends ClusterModel { interface Pre360ClusterModel extends ClusterModel {
kubeConfig: string; kubeConfig: string;
@ -41,7 +41,7 @@ export default {
const storedClusters: Pre360ClusterModel[] = store.get("clusters") ?? []; const storedClusters: Pre360ClusterModel[] = store.get("clusters") ?? [];
const migratedClusters: ClusterModel[] = []; const migratedClusters: ClusterModel[] = [];
fse.ensureDirSync(ClusterStore.storedKubeConfigFolder); fse.ensureDirSync(storedKubeConfigFolder());
migrationLog("Number of clusters to migrate: ", storedClusters.length); migrationLog("Number of clusters to migrate: ", storedClusters.length);
@ -50,7 +50,7 @@ export default {
* migrate kubeconfig * migrate kubeconfig
*/ */
try { try {
const absPath = ClusterStore.getCustomKubeConfigPath(clusterModel.id); const absPath = getCustomKubeConfigPath(clusterModel.id);
// take the embedded kubeconfig and dump it into a file // take the embedded kubeconfig and dump it into a file
fse.writeFileSync(absPath, clusterModel.kubeConfig, { encoding: "utf-8", mode: 0o600 }); fse.writeFileSync(absPath, clusterModel.kubeConfig, { encoding: "utf-8", mode: 0o600 });

View File

@ -23,10 +23,10 @@ import { app } from "electron";
import { existsSync, readFileSync } from "fs"; import { existsSync, readFileSync } from "fs";
import path from "path"; import path from "path";
import os from "os"; import os from "os";
import { ClusterStore, ClusterStoreModel } from "../../common/cluster-store"; import type { ClusterStoreModel } from "../../common/cluster-store";
import type { KubeconfigSyncEntry, UserPreferencesModel } from "../../common/user-store"; import type { KubeconfigSyncEntry, UserPreferencesModel } from "../../common/user-store";
import { MigrationDeclaration, migrationLog } from "../helpers"; import { MigrationDeclaration, migrationLog } from "../helpers";
import { isLogicalChildPath } from "../../common/utils"; import { isLogicalChildPath, storedKubeConfigFolder } from "../../common/utils";
export default { export default {
version: "5.0.3-beta.1", version: "5.0.3-beta.1",
@ -42,8 +42,8 @@ export default {
for (const cluster of clusters) { for (const cluster of clusters) {
const dirOfKubeconfig = path.dirname(cluster.kubeConfigPath); const dirOfKubeconfig = path.dirname(cluster.kubeConfigPath);
if (dirOfKubeconfig === ClusterStore.storedKubeConfigFolder) { if (dirOfKubeconfig === storedKubeConfigFolder()) {
migrationLog(`Skipping ${cluster.id} because kubeConfigPath is under ClusterStore.storedKubeConfigFolder`); migrationLog(`Skipping ${cluster.id} because kubeConfigPath is under the stored KubeConfig folder`);
continue; continue;
} }