mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Display warning notification if invalid kubeconfig detected
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
parent
607ebb599b
commit
4a9d4610d5
@ -11,7 +11,7 @@ import { appEventBus } from "./event-bus";
|
|||||||
import { dumpConfigYaml } from "./kube-helpers";
|
import { dumpConfigYaml } from "./kube-helpers";
|
||||||
import { saveToAppFiles } from "./utils/saveToAppFiles";
|
import { saveToAppFiles } from "./utils/saveToAppFiles";
|
||||||
import { KubeConfig } from "@kubernetes/client-node";
|
import { KubeConfig } from "@kubernetes/client-node";
|
||||||
import { handleRequest, requestMain, subscribeToBroadcast, unsubscribeAllFromBroadcast } from "./ipc";
|
import { broadcastMessage, handleRequest, requestMain, subscribeToBroadcast, unsubscribeAllFromBroadcast, InvalidKubeconfigChannel } from "./ipc";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import move from "array-move";
|
import move from "array-move";
|
||||||
import type { WorkspaceId } from "./workspace-store";
|
import type { WorkspaceId } from "./workspace-store";
|
||||||
@ -372,3 +372,9 @@ export function getHostedClusterId() {
|
|||||||
export function getHostedCluster(): Cluster {
|
export function getHostedCluster(): Cluster {
|
||||||
return clusterStore.getById(getHostedClusterId());
|
return clusterStore.getById(getHostedClusterId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function reportDeadClusters() {
|
||||||
|
clusterStore.clustersList.filter(cluster => cluster.isDead).forEach(cluster => {
|
||||||
|
broadcastMessage(InvalidKubeconfigChannel, cluster.id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
export * from "./ipc";
|
export * from "./ipc";
|
||||||
|
export * from "./invalid-kubeconfig";
|
||||||
export * from "./update-available";
|
export * from "./update-available";
|
||||||
export * from "./type-enforced-ipc";
|
export * from "./type-enforced-ipc";
|
||||||
|
|||||||
3
src/common/ipc/invalid-kubeconfig/index.ts
Normal file
3
src/common/ipc/invalid-kubeconfig/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export const InvalidKubeconfigChannel = "invalid-kubeconfig";
|
||||||
|
|
||||||
|
export type InvalidKubeConfigArgs = [clusterId: string];
|
||||||
@ -15,7 +15,7 @@ import { getFreePort } from "./port";
|
|||||||
import { mangleProxyEnv } from "./proxy-env";
|
import { mangleProxyEnv } from "./proxy-env";
|
||||||
import { registerFileProtocol } from "../common/register-protocol";
|
import { registerFileProtocol } from "../common/register-protocol";
|
||||||
import logger from "./logger";
|
import logger from "./logger";
|
||||||
import { clusterStore } from "../common/cluster-store";
|
import { clusterStore, reportDeadClusters } from "../common/cluster-store";
|
||||||
import { userStore } from "../common/user-store";
|
import { userStore } from "../common/user-store";
|
||||||
import { workspaceStore } from "../common/workspace-store";
|
import { workspaceStore } from "../common/workspace-store";
|
||||||
import { appEventBus } from "../common/event-bus";
|
import { appEventBus } from "../common/event-bus";
|
||||||
@ -128,7 +128,10 @@ app.on("ready", async () => {
|
|||||||
|
|
||||||
logger.info("🖥️ Starting WindowManager");
|
logger.info("🖥️ Starting WindowManager");
|
||||||
windowManager = WindowManager.getInstance<WindowManager>(proxyPort);
|
windowManager = WindowManager.getInstance<WindowManager>(proxyPort);
|
||||||
windowManager.whenLoaded.then(() => startUpdateChecking());
|
windowManager.whenLoaded.then(() => {
|
||||||
|
startUpdateChecking();
|
||||||
|
reportDeadClusters();
|
||||||
|
});
|
||||||
|
|
||||||
logger.info("🧩 Initializing extensions");
|
logger.info("🧩 Initializing extensions");
|
||||||
|
|
||||||
|
|||||||
@ -52,7 +52,7 @@ export class CreateResource extends React.Component<Props> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (errors.length) {
|
if (errors.length) {
|
||||||
errors.forEach(Notifications.error);
|
errors.forEach(error => Notifications.error(error));
|
||||||
if (!createdResources.length) throw errors[0];
|
if (!createdResources.length) throw errors[0];
|
||||||
}
|
}
|
||||||
const successMessage = (
|
const successMessage = (
|
||||||
|
|||||||
@ -21,11 +21,12 @@ export class Notifications extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static error(message: NotificationMessage) {
|
static error(message: NotificationMessage, customOpts: Partial<Notification> = {}) {
|
||||||
notificationsStore.add({
|
notificationsStore.add({
|
||||||
message,
|
message,
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
status: NotificationStatus.ERROR
|
status: NotificationStatus.ERROR,
|
||||||
|
...customOpts
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import { Notifications, notificationsStore } from "../components/notifications";
|
|||||||
import { Button } from "../components/button";
|
import { Button } from "../components/button";
|
||||||
import { isMac } from "../../common/vars";
|
import { isMac } from "../../common/vars";
|
||||||
import * as uuid from "uuid";
|
import * as uuid from "uuid";
|
||||||
|
import { invalidKubeconfigHandler } from "./invalid-kubeconfig-handler";
|
||||||
|
|
||||||
function sendToBackchannel(backchannel: string, notificationId: string, data: BackchannelArg): void {
|
function sendToBackchannel(backchannel: string, notificationId: string, data: BackchannelArg): void {
|
||||||
notificationsStore.remove(notificationId);
|
notificationsStore.remove(notificationId);
|
||||||
@ -58,4 +59,5 @@ export function registerIpcHandlers() {
|
|||||||
listener: UpdateAvailableHandler,
|
listener: UpdateAvailableHandler,
|
||||||
verifier: areArgsUpdateAvailableFromMain,
|
verifier: areArgsUpdateAvailableFromMain,
|
||||||
});
|
});
|
||||||
|
onCorrect(invalidKubeconfigHandler);
|
||||||
}
|
}
|
||||||
|
|||||||
44
src/renderer/ipc/invalid-kubeconfig-handler.tsx
Normal file
44
src/renderer/ipc/invalid-kubeconfig-handler.tsx
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { ipcRenderer, IpcRendererEvent, shell } from "electron";
|
||||||
|
import { clusterStore } from "../../common/cluster-store";
|
||||||
|
import { InvalidKubeConfigArgs, InvalidKubeconfigChannel } from "../../common/ipc/invalid-kubeconfig";
|
||||||
|
import { Notifications, notificationsStore } from "../components/notifications";
|
||||||
|
import { Button } from "../components/button";
|
||||||
|
|
||||||
|
export const invalidKubeconfigHandler = {
|
||||||
|
source: ipcRenderer,
|
||||||
|
channel: InvalidKubeconfigChannel,
|
||||||
|
listener: InvalidKubeconfigListener,
|
||||||
|
verifier: (args: [unknown]): args is InvalidKubeConfigArgs => {
|
||||||
|
return args.length === 1;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
function InvalidKubeconfigListener(event: IpcRendererEvent, ...[clusterId]: InvalidKubeConfigArgs): void {
|
||||||
|
const notificationId = `invalid-kubeconfig:${clusterId}`;
|
||||||
|
const cluster = clusterStore.getById(clusterId);
|
||||||
|
|
||||||
|
Notifications.error(
|
||||||
|
(
|
||||||
|
<div className="flex column gaps">
|
||||||
|
<b>Cluster with invalid Kubeconfig Detected!</b>
|
||||||
|
<p>Cluster <b>{cluster.name}</b> has invalid <a href="#" onClick={(e) => { e.preventDefault(); shell.showItemInFolder(cluster.kubeConfigPath); }}>Kubeconfig</a> and cannot be displayed.
|
||||||
|
Please fix the Kubeconfig or remove the cluster. </p>
|
||||||
|
<p>Do you want to remove the cluster now?</p>
|
||||||
|
<div className="flex gaps row align-left box grow">
|
||||||
|
<Button active outlined label="Remove" onClick={()=> {
|
||||||
|
clusterStore.removeById(clusterId);
|
||||||
|
notificationsStore.remove(notificationId);
|
||||||
|
}} />
|
||||||
|
<Button active outlined label="Cancel" onClick={() => notificationsStore.remove(notificationId)} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
{
|
||||||
|
id: notificationId,
|
||||||
|
timeout: 0
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user