mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Display warning notification if invalid kubeconfig detected (#2233)
* Display warning notification if invalid kubeconfig detected Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
parent
ed6e00798d
commit
20c1b061de
@ -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];
|
||||||
@ -4,7 +4,7 @@ import type { IMetricsReqParams } from "../renderer/api/endpoints/metrics.api";
|
|||||||
import type { WorkspaceId } from "../common/workspace-store";
|
import type { WorkspaceId } from "../common/workspace-store";
|
||||||
import { action, comparer, computed, observable, reaction, toJS, when } from "mobx";
|
import { action, comparer, computed, observable, reaction, toJS, when } from "mobx";
|
||||||
import { apiKubePrefix } from "../common/vars";
|
import { apiKubePrefix } from "../common/vars";
|
||||||
import { broadcastMessage } from "../common/ipc";
|
import { broadcastMessage, InvalidKubeconfigChannel } from "../common/ipc";
|
||||||
import { ContextHandler } from "./context-handler";
|
import { ContextHandler } from "./context-handler";
|
||||||
import { AuthorizationV1Api, CoreV1Api, KubeConfig, V1ResourceAttributes } from "@kubernetes/client-node";
|
import { AuthorizationV1Api, CoreV1Api, KubeConfig, V1ResourceAttributes } from "@kubernetes/client-node";
|
||||||
import { Kubectl } from "./kubectl";
|
import { Kubectl } from "./kubectl";
|
||||||
@ -266,6 +266,7 @@ export class Cluster implements ClusterModel, ClusterState {
|
|||||||
} catch(err) {
|
} catch(err) {
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
logger.error(`[CLUSTER] Failed to load kubeconfig for the cluster '${this.name || this.contextName}' (context: ${this.contextName}, kubeconfig: ${this.kubeConfigPath}).`);
|
logger.error(`[CLUSTER] Failed to load kubeconfig for the cluster '${this.name || this.contextName}' (context: ${this.contextName}, kubeconfig: ${this.kubeConfigPath}).`);
|
||||||
|
broadcastMessage(InvalidKubeconfigChannel, model.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
46
src/renderer/ipc/invalid-kubeconfig-handler.tsx
Normal file
46
src/renderer/ipc/invalid-kubeconfig-handler.tsx
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
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 && typeof args[0] === "string" && !!clusterStore.getById(args[0]);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
function InvalidKubeconfigListener(event: IpcRendererEvent, ...[clusterId]: InvalidKubeConfigArgs): void {
|
||||||
|
const notificationId = `invalid-kubeconfig:${clusterId}`;
|
||||||
|
const cluster = clusterStore.getById(clusterId);
|
||||||
|
const contextName = cluster.name !== cluster.contextName ? `(context: ${cluster.contextName})` : "";
|
||||||
|
|
||||||
|
Notifications.error(
|
||||||
|
(
|
||||||
|
<div className="flex column gaps">
|
||||||
|
<b>Cluster with Invalid Kubeconfig Detected!</b>
|
||||||
|
<p>Cluster <b>{cluster.name}</b> has invalid kubeconfig {contextName} and cannot be displayed.
|
||||||
|
Please fix the <a href="#" onClick={(e) => { e.preventDefault(); shell.showItemInFolder(cluster.kubeConfigPath); }}>kubeconfig</a> manually and restart Lens
|
||||||
|
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