mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Merge branch 'master' into general-catalog-category
This commit is contained in:
commit
f0ff4110d8
@ -83,7 +83,7 @@ extra:
|
|||||||
link: https://k8slens.dev/
|
link: https://k8slens.dev/
|
||||||
name: Lens Website
|
name: Lens Website
|
||||||
version:
|
version:
|
||||||
method: mike
|
provider: mike
|
||||||
analytics:
|
analytics:
|
||||||
provider: google
|
provider: google
|
||||||
property: UA-159377374-2
|
property: UA-159377374-2
|
||||||
|
|||||||
@ -125,33 +125,28 @@ describe("empty config", () => {
|
|||||||
expect(storedCluster.preferences.terminalCWD).toBe("/tmp");
|
expect(storedCluster.preferences.terminalCWD).toBe("/tmp");
|
||||||
expect(storedCluster.preferences.icon).toBe("data:image/jpeg;base64, iVBORw0KGgoAAAANSUhEUgAAA1wAAAKoCAYAAABjkf5");
|
expect(storedCluster.preferences.icon).toBe("data:image/jpeg;base64, iVBORw0KGgoAAAANSUhEUgAAA1wAAAKoCAYAAABjkf5");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("removes cluster from store", async () => {
|
|
||||||
await ClusterStore.getInstance().removeById("foo");
|
|
||||||
expect(ClusterStore.getInstance().getById("foo")).toBeNull();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("with prod and dev clusters added", () => {
|
describe("with prod and dev clusters added", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
ClusterStore.getInstance().addClusters(
|
const store = ClusterStore.getInstance();
|
||||||
new Cluster({
|
|
||||||
id: "prod",
|
store.addCluster({
|
||||||
contextName: "foo",
|
id: "prod",
|
||||||
preferences: {
|
contextName: "foo",
|
||||||
clusterName: "prod"
|
preferences: {
|
||||||
},
|
clusterName: "prod"
|
||||||
kubeConfigPath: embed("prod", kubeconfig)
|
},
|
||||||
}),
|
kubeConfigPath: embed("prod", kubeconfig)
|
||||||
new Cluster({
|
});
|
||||||
id: "dev",
|
store.addCluster({
|
||||||
contextName: "foo2",
|
id: "dev",
|
||||||
preferences: {
|
contextName: "foo2",
|
||||||
clusterName: "dev"
|
preferences: {
|
||||||
},
|
clusterName: "dev"
|
||||||
kubeConfigPath: embed("dev", kubeconfig)
|
},
|
||||||
})
|
kubeConfigPath: embed("dev", kubeconfig)
|
||||||
);
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("check if store can contain multiple clusters", () => {
|
it("check if store can contain multiple clusters", () => {
|
||||||
@ -222,16 +217,6 @@ describe("config with existing clusters", () => {
|
|||||||
expect(storedCluster.preferences.terminalCWD).toBe("/foo");
|
expect(storedCluster.preferences.terminalCWD).toBe("/foo");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("allows to delete a cluster", () => {
|
|
||||||
ClusterStore.getInstance().removeById("cluster2");
|
|
||||||
const storedCluster = ClusterStore.getInstance().getById("cluster1");
|
|
||||||
|
|
||||||
expect(storedCluster).toBeTruthy();
|
|
||||||
const storedCluster2 = ClusterStore.getInstance().getById("cluster2");
|
|
||||||
|
|
||||||
expect(storedCluster2).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("allows getting all of the clusters", async () => {
|
it("allows getting all of the clusters", async () => {
|
||||||
const storedClusters = ClusterStore.getInstance().clustersList;
|
const storedClusters = ClusterStore.getInstance().clustersList;
|
||||||
|
|
||||||
|
|||||||
@ -21,14 +21,14 @@
|
|||||||
|
|
||||||
import { catalogCategoryRegistry } from "../catalog/catalog-category-registry";
|
import { catalogCategoryRegistry } from "../catalog/catalog-category-registry";
|
||||||
import { CatalogEntity, CatalogEntityActionContext, CatalogEntityAddMenuContext, CatalogEntityContextMenuContext, CatalogEntityMetadata, CatalogEntityStatus } from "../catalog";
|
import { CatalogEntity, CatalogEntityActionContext, CatalogEntityAddMenuContext, CatalogEntityContextMenuContext, CatalogEntityMetadata, CatalogEntityStatus } from "../catalog";
|
||||||
import { clusterActivateHandler, clusterDisconnectHandler } from "../cluster-ipc";
|
import { clusterActivateHandler, clusterDeleteHandler, clusterDisconnectHandler } from "../cluster-ipc";
|
||||||
import { ClusterStore } from "../cluster-store";
|
import { ClusterStore } from "../cluster-store";
|
||||||
import { requestMain } from "../ipc";
|
import { requestMain } from "../ipc";
|
||||||
import { productName } from "../vars";
|
|
||||||
import { CatalogCategory, CatalogCategorySpec } from "../catalog";
|
import { CatalogCategory, CatalogCategorySpec } from "../catalog";
|
||||||
import { addClusterURL } from "../routes";
|
import { addClusterURL } from "../routes";
|
||||||
import { app } from "electron";
|
import { app } from "electron";
|
||||||
import type { CatalogEntitySpec } from "../catalog/catalog-entity";
|
import type { CatalogEntitySpec } from "../catalog/catalog-entity";
|
||||||
|
import { HotbarStore } from "../hotbar-store";
|
||||||
|
|
||||||
export type KubernetesClusterPrometheusMetrics = {
|
export type KubernetesClusterPrometheusMetrics = {
|
||||||
address?: {
|
address?: {
|
||||||
@ -50,7 +50,7 @@ export type KubernetesClusterSpec = {
|
|||||||
} & CatalogEntitySpec;
|
} & CatalogEntitySpec;
|
||||||
|
|
||||||
export interface KubernetesClusterStatus extends CatalogEntityStatus {
|
export interface KubernetesClusterStatus extends CatalogEntityStatus {
|
||||||
phase: "connected" | "disconnected";
|
phase: "connected" | "disconnected" | "deleting";
|
||||||
}
|
}
|
||||||
|
|
||||||
export class KubernetesCluster extends CatalogEntity<CatalogEntityMetadata, KubernetesClusterStatus, KubernetesClusterSpec> {
|
export class KubernetesCluster extends CatalogEntity<CatalogEntityMetadata, KubernetesClusterStatus, KubernetesClusterSpec> {
|
||||||
@ -103,39 +103,38 @@ export class KubernetesCluster extends CatalogEntity<CatalogEntityMetadata, Kube
|
|||||||
|
|
||||||
async onContextMenuOpen(context: CatalogEntityContextMenuContext) {
|
async onContextMenuOpen(context: CatalogEntityContextMenuContext) {
|
||||||
if (!this.metadata.source || this.metadata.source === "local") {
|
if (!this.metadata.source || this.metadata.source === "local") {
|
||||||
context.menuItems.push({
|
context.menuItems.push(
|
||||||
title: "Settings",
|
{
|
||||||
icon: "edit",
|
title: "Settings",
|
||||||
onClick: async () => context.navigate(`/entity/${this.metadata.uid}/settings`)
|
icon: "edit",
|
||||||
});
|
onClick: () => context.navigate(`/entity/${this.metadata.uid}/settings`)
|
||||||
}
|
},
|
||||||
|
{
|
||||||
if (this.metadata.labels["file"]?.startsWith(ClusterStore.storedKubeConfigFolder)) {
|
title: "Delete",
|
||||||
context.menuItems.push({
|
icon: "delete",
|
||||||
title: "Delete",
|
onClick: () => {
|
||||||
icon: "delete",
|
HotbarStore.getInstance().removeAllHotbarItems(this.getId());
|
||||||
onClick: async () => ClusterStore.getInstance().removeById(this.metadata.uid),
|
requestMain(clusterDeleteHandler, this.metadata.uid);
|
||||||
confirm: {
|
},
|
||||||
message: `Remove Kubernetes Cluster "${this.metadata.name} from ${productName}?`
|
confirm: {
|
||||||
}
|
// TODO: change this to be a <p> tag with better formatting once this code can accept it.
|
||||||
});
|
message: `Delete the "${this.metadata.name}" context from "${this.metadata.labels.file}"?`
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.status.phase == "connected") {
|
if (this.status.phase == "connected") {
|
||||||
context.menuItems.push({
|
context.menuItems.push({
|
||||||
title: "Disconnect",
|
title: "Disconnect",
|
||||||
icon: "link_off",
|
icon: "link_off",
|
||||||
onClick: async () => {
|
onClick: () => requestMain(clusterDisconnectHandler, this.metadata.uid)
|
||||||
requestMain(clusterDisconnectHandler, this.metadata.uid);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
context.menuItems.push({
|
context.menuItems.push({
|
||||||
title: "Connect",
|
title: "Connect",
|
||||||
icon: "link",
|
icon: "link",
|
||||||
onClick: async () => {
|
onClick: () => context.navigate(`/cluster/${this.metadata.uid}`)
|
||||||
context.navigate(`/cluster/${this.metadata.uid}`);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -19,11 +19,13 @@
|
|||||||
* 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 { CatalogCategory, CatalogEntity, CatalogEntityMetadata, CatalogEntityStatus } from "../catalog";
|
import { CatalogCategory, CatalogEntity, CatalogEntityAddMenuContext, CatalogEntityContextMenuContext, CatalogEntityMetadata, CatalogEntityStatus } from "../catalog";
|
||||||
import { catalogCategoryRegistry } from "../catalog/catalog-category-registry";
|
import { catalogCategoryRegistry } from "../catalog/catalog-category-registry";
|
||||||
|
import { productName } from "../vars";
|
||||||
|
import { WeblinkStore } from "../weblink-store";
|
||||||
|
|
||||||
export interface WebLinkStatus extends CatalogEntityStatus {
|
export interface WebLinkStatus extends CatalogEntityStatus {
|
||||||
phase: "valid" | "invalid";
|
phase: "available" | "unavailable";
|
||||||
}
|
}
|
||||||
|
|
||||||
export type WebLinkSpec = {
|
export type WebLinkSpec = {
|
||||||
@ -42,12 +44,17 @@ export class WebLink extends CatalogEntity<CatalogEntityMetadata, WebLinkStatus,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public onDetailsOpen(): void {
|
async onContextMenuOpen(context: CatalogEntityContextMenuContext) {
|
||||||
return;
|
if (this.metadata.source === "local") {
|
||||||
}
|
context.menuItems.push({
|
||||||
|
title: "Delete",
|
||||||
public onContextMenuOpen(): void {
|
icon: "delete",
|
||||||
return;
|
onClick: async () => WeblinkStore.getInstance().removeById(this.metadata.uid),
|
||||||
|
confirm: {
|
||||||
|
message: `Remove Web Link "${this.metadata.name}" from ${productName}?`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +63,7 @@ export class WebLinkCategory extends CatalogCategory {
|
|||||||
public readonly kind = "CatalogCategory";
|
public readonly kind = "CatalogCategory";
|
||||||
public metadata = {
|
public metadata = {
|
||||||
name: "Web Links",
|
name: "Web Links",
|
||||||
icon: "link"
|
icon: "public"
|
||||||
};
|
};
|
||||||
public spec = {
|
public spec = {
|
||||||
group: "entity.k8slens.dev",
|
group: "entity.k8slens.dev",
|
||||||
@ -70,6 +77,21 @@ export class WebLinkCategory extends CatalogCategory {
|
|||||||
kind: "WebLink"
|
kind: "WebLink"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
public static onAdd?: () => void;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.on("catalogAddMenu", (ctx: CatalogEntityAddMenuContext) => {
|
||||||
|
ctx.menuItems.push({
|
||||||
|
icon: "public",
|
||||||
|
title: "Add web link",
|
||||||
|
onClick: () => {
|
||||||
|
WebLinkCategory.onAdd();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
catalogCategoryRegistry.add(new WebLinkCategory());
|
catalogCategoryRegistry.add(new WebLinkCategory());
|
||||||
|
|||||||
@ -86,6 +86,11 @@ export interface CatalogEntityMetadata {
|
|||||||
export interface CatalogEntityStatus {
|
export interface CatalogEntityStatus {
|
||||||
phase: string;
|
phase: string;
|
||||||
reason?: string;
|
reason?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @default true
|
||||||
|
*/
|
||||||
|
enabled?: boolean;
|
||||||
message?: string;
|
message?: string;
|
||||||
active?: boolean;
|
active?: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,5 +24,6 @@ export const clusterSetFrameIdHandler = "cluster:set-frame-id";
|
|||||||
export const clusterVisibilityHandler = "cluster:visibility";
|
export const clusterVisibilityHandler = "cluster:visibility";
|
||||||
export const clusterRefreshHandler = "cluster:refresh";
|
export const clusterRefreshHandler = "cluster:refresh";
|
||||||
export const clusterDisconnectHandler = "cluster:disconnect";
|
export const clusterDisconnectHandler = "cluster:disconnect";
|
||||||
|
export const clusterDeleteHandler = "cluster:delete";
|
||||||
export const clusterKubectlApplyAllHandler = "cluster:kubectl-apply-all";
|
export const clusterKubectlApplyAllHandler = "cluster:kubectl-apply-all";
|
||||||
export const clusterKubectlDeleteAllHandler = "cluster:kubectl-delete-all";
|
export const clusterKubectlDeleteAllHandler = "cluster:kubectl-delete-all";
|
||||||
|
|||||||
@ -20,8 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { app, ipcMain, ipcRenderer, remote, webFrame } from "electron";
|
import { app, ipcMain, ipcRenderer, webFrame } from "electron";
|
||||||
import { unlink } from "fs-extra";
|
|
||||||
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, ClusterState } from "../main/cluster";
|
import { Cluster, ClusterState } from "../main/cluster";
|
||||||
@ -30,7 +29,7 @@ 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";
|
||||||
import { disposer, noop, toJS } from "./utils";
|
import { disposer, toJS } from "./utils";
|
||||||
|
|
||||||
export interface ClusterIconUpload {
|
export interface ClusterIconUpload {
|
||||||
clusterId: string;
|
clusterId: string;
|
||||||
@ -83,9 +82,6 @@ export interface ClusterModel {
|
|||||||
|
|
||||||
/** List of accessible namespaces */
|
/** List of accessible namespaces */
|
||||||
accessibleNamespaces?: string[];
|
accessibleNamespaces?: string[];
|
||||||
|
|
||||||
/** @deprecated */
|
|
||||||
kubeConfig?: string; // yaml
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ClusterPreferences extends ClusterPrometheusPreferences {
|
export interface ClusterPreferences extends ClusterPrometheusPreferences {
|
||||||
@ -113,7 +109,7 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
|||||||
private static StateChannel = "cluster:state";
|
private static StateChannel = "cluster:state";
|
||||||
|
|
||||||
static get storedKubeConfigFolder(): string {
|
static get storedKubeConfigFolder(): string {
|
||||||
return path.resolve((app || remote.app).getPath("userData"), "kubeconfigs");
|
return path.resolve(app.getPath("userData"), "kubeconfigs");
|
||||||
}
|
}
|
||||||
|
|
||||||
static getCustomKubeConfigPath(clusterId: ClusterId = uuid.v4()): string {
|
static getCustomKubeConfigPath(clusterId: ClusterId = uuid.v4()): string {
|
||||||
@ -123,7 +119,6 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
|||||||
@observable clusters = observable.map<ClusterId, Cluster>();
|
@observable clusters = observable.map<ClusterId, Cluster>();
|
||||||
@observable removedClusters = observable.map<ClusterId, Cluster>();
|
@observable removedClusters = observable.map<ClusterId, Cluster>();
|
||||||
|
|
||||||
private static stateRequestChannel = "cluster:states";
|
|
||||||
protected disposer = disposer();
|
protected disposer = disposer();
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -142,35 +137,22 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async load() {
|
async load() {
|
||||||
|
const initialStates = "cluster:states";
|
||||||
|
|
||||||
await super.load();
|
await super.load();
|
||||||
type clusterStateSync = {
|
|
||||||
id: string;
|
|
||||||
state: ClusterState;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (ipcRenderer) {
|
if (ipcRenderer) {
|
||||||
logger.info("[CLUSTER-STORE] requesting initial state sync");
|
logger.info("[CLUSTER-STORE] requesting initial state sync");
|
||||||
const clusterStates: clusterStateSync[] = await requestMain(ClusterStore.stateRequestChannel);
|
|
||||||
|
|
||||||
clusterStates.forEach((clusterState) => {
|
for (const { id, state } of await requestMain(initialStates)) {
|
||||||
const cluster = this.getById(clusterState.id);
|
this.getById(id)?.setState(state);
|
||||||
|
}
|
||||||
if (cluster) {
|
|
||||||
cluster.setState(clusterState.state);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if (ipcMain) {
|
} else if (ipcMain) {
|
||||||
ipcMainHandle(ClusterStore.stateRequestChannel, (): clusterStateSync[] => {
|
ipcMainHandle(initialStates, () => {
|
||||||
const clusterStates: clusterStateSync[] = [];
|
return this.clustersList.map(cluster => ({
|
||||||
|
id: cluster.id,
|
||||||
this.clustersList.forEach((cluster) => {
|
state: cluster.getState(),
|
||||||
clusterStates.push({
|
}));
|
||||||
state: cluster.getState(),
|
|
||||||
id: cluster.id
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return clusterStates;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,9 +160,7 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
|||||||
protected pushStateToViewsAutomatically() {
|
protected pushStateToViewsAutomatically() {
|
||||||
if (ipcMain) {
|
if (ipcMain) {
|
||||||
this.disposer.push(
|
this.disposer.push(
|
||||||
reaction(() => this.connectedClustersList, () => {
|
reaction(() => this.connectedClustersList, () => this.pushState()),
|
||||||
this.pushState();
|
|
||||||
}),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -229,18 +209,6 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
|||||||
return this.clusters.get(id) ?? null;
|
return this.clusters.get(id) ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
|
||||||
addClusters(...models: ClusterModel[]): Cluster[] {
|
|
||||||
const clusters: Cluster[] = [];
|
|
||||||
|
|
||||||
models.forEach(model => {
|
|
||||||
clusters.push(this.addCluster(model));
|
|
||||||
});
|
|
||||||
|
|
||||||
return clusters;
|
|
||||||
}
|
|
||||||
|
|
||||||
@action
|
|
||||||
addCluster(clusterOrModel: ClusterModel | Cluster): Cluster {
|
addCluster(clusterOrModel: ClusterModel | Cluster): Cluster {
|
||||||
appEventBus.emit({ name: "cluster", action: "add" });
|
appEventBus.emit({ name: "cluster", action: "add" });
|
||||||
|
|
||||||
@ -253,25 +221,6 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
|||||||
return cluster;
|
return cluster;
|
||||||
}
|
}
|
||||||
|
|
||||||
async removeCluster(model: ClusterModel) {
|
|
||||||
await this.removeById(model.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@action
|
|
||||||
async removeById(clusterId: ClusterId) {
|
|
||||||
appEventBus.emit({ name: "cluster", action: "remove" });
|
|
||||||
const cluster = this.getById(clusterId);
|
|
||||||
|
|
||||||
if (cluster) {
|
|
||||||
this.clusters.delete(clusterId);
|
|
||||||
|
|
||||||
// remove only custom kubeconfigs (pasted as text)
|
|
||||||
if (cluster.kubeConfigPath == ClusterStore.getCustomKubeConfigPath(clusterId)) {
|
|
||||||
await unlink(cluster.kubeConfigPath).catch(noop);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@action
|
@action
|
||||||
protected fromStore({ clusters = [] }: ClusterStoreModel = {}) {
|
protected fromStore({ clusters = [] }: ClusterStoreModel = {}) {
|
||||||
const currentClusters = new Map(this.clusters);
|
const currentClusters = new Map(this.clusters);
|
||||||
|
|||||||
@ -181,7 +181,7 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
removeFromHotbar(uid: string) {
|
removeFromHotbar(uid: string): void {
|
||||||
const hotbar = this.getActive();
|
const hotbar = this.getActive();
|
||||||
const index = hotbar.items.findIndex((i) => i?.entity.uid === uid);
|
const index = hotbar.items.findIndex((i) => i?.entity.uid === uid);
|
||||||
|
|
||||||
@ -192,6 +192,25 @@ export class HotbarStore extends BaseStore<HotbarStoreModel> {
|
|||||||
hotbar.items[index] = null;
|
hotbar.items[index] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remvove all hotbar items that reference the `uid`.
|
||||||
|
* @param uid The `EntityId` that each hotbar item refers to
|
||||||
|
* @returns A function that will (in an action) undo the removing of the hotbar items. This function will not complete if the hotbar has changed.
|
||||||
|
*/
|
||||||
|
@action
|
||||||
|
removeAllHotbarItems(uid: string) {
|
||||||
|
const undoItems: [Hotbar, number, HotbarItem][] = [];
|
||||||
|
|
||||||
|
for (const hotbar of this.hotbars) {
|
||||||
|
const index = hotbar.items.findIndex((i) => i?.entity.uid === uid);
|
||||||
|
|
||||||
|
if (index >= 0) {
|
||||||
|
undoItems.push([hotbar, index, hotbar.items[index]]);
|
||||||
|
hotbar.items[index] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
findClosestEmptyIndex(from: number, direction = 1) {
|
findClosestEmptyIndex(from: number, direction = 1) {
|
||||||
let index = from;
|
let index = from;
|
||||||
|
|
||||||
|
|||||||
@ -19,8 +19,9 @@
|
|||||||
* 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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Common utils (main OR renderer)
|
/**
|
||||||
|
* A function that does nothing
|
||||||
|
*/
|
||||||
export function noop<T extends any[]>(...args: T): void {
|
export function noop<T extends any[]>(...args: T): void {
|
||||||
return void args;
|
return void args;
|
||||||
}
|
}
|
||||||
|
|||||||
90
src/common/weblink-store.ts
Normal file
90
src/common/weblink-store.ts
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 OpenLens Authors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { action, comparer, observable, makeObservable } from "mobx";
|
||||||
|
import { BaseStore } from "./base-store";
|
||||||
|
import migrations from "../migrations/hotbar-store";
|
||||||
|
import * as uuid from "uuid";
|
||||||
|
import { toJS } from "./utils";
|
||||||
|
|
||||||
|
export interface WeblinkData {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
url: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface WeblinkCreateOptions {
|
||||||
|
id?: string;
|
||||||
|
name: string;
|
||||||
|
url: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export interface WeblinkStoreModel {
|
||||||
|
weblinks: WeblinkData[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export class WeblinkStore extends BaseStore<WeblinkStoreModel> {
|
||||||
|
@observable weblinks: WeblinkData[] = [];
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super({
|
||||||
|
configName: "lens-weblink-store",
|
||||||
|
accessPropertiesByDotNotation: false, // To make dots safe in cluster context names
|
||||||
|
syncOptions: {
|
||||||
|
equals: comparer.structural,
|
||||||
|
},
|
||||||
|
migrations,
|
||||||
|
});
|
||||||
|
makeObservable(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@action protected async fromStore(data: Partial<WeblinkStoreModel> = {}) {
|
||||||
|
this.weblinks = data.weblinks || [];
|
||||||
|
}
|
||||||
|
|
||||||
|
add(data: WeblinkCreateOptions) {
|
||||||
|
const {
|
||||||
|
id = uuid.v4(),
|
||||||
|
name,
|
||||||
|
url
|
||||||
|
} = data;
|
||||||
|
|
||||||
|
const weblink = { id, name, url };
|
||||||
|
|
||||||
|
this.weblinks.push(weblink as WeblinkData);
|
||||||
|
|
||||||
|
return weblink as WeblinkData;
|
||||||
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
removeById(id: string) {
|
||||||
|
this.weblinks = this.weblinks.filter((w) => w.id !== id);
|
||||||
|
}
|
||||||
|
|
||||||
|
toJSON(): WeblinkStoreModel {
|
||||||
|
const model: WeblinkStoreModel = {
|
||||||
|
weblinks: this.weblinks
|
||||||
|
};
|
||||||
|
|
||||||
|
return toJS(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -120,8 +120,8 @@ describe("create clusters", () => {
|
|||||||
protected bindEvents() {
|
protected bindEvents() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
protected async ensureKubectl() {
|
async ensureKubectl() {
|
||||||
return Promise.resolve(true);
|
return Promise.resolve(null);
|
||||||
}
|
}
|
||||||
}({
|
}({
|
||||||
id: "foo",
|
id: "foo",
|
||||||
|
|||||||
@ -30,7 +30,7 @@ import type { CatalogEntity } from "../common/catalog";
|
|||||||
|
|
||||||
const broadcaster = debounce((items: CatalogEntity[]) => {
|
const broadcaster = debounce((items: CatalogEntity[]) => {
|
||||||
broadcastMessage("catalog:items", items);
|
broadcastMessage("catalog:items", items);
|
||||||
}, 1_000, { trailing: true });
|
}, 1_000, { leading: true, trailing: true });
|
||||||
|
|
||||||
export function pushCatalogToRenderer(catalog: CatalogEntityRegistry) {
|
export function pushCatalogToRenderer(catalog: CatalogEntityRegistry) {
|
||||||
return reaction(() => toJS(catalog.items), (items) => {
|
return reaction(() => toJS(catalog.items), (items) => {
|
||||||
|
|||||||
@ -27,6 +27,7 @@ import { computeDiff, configToModels } from "../kubeconfig-sync";
|
|||||||
import mockFs from "mock-fs";
|
import mockFs from "mock-fs";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import { ClusterStore } from "../../../common/cluster-store";
|
import { ClusterStore } from "../../../common/cluster-store";
|
||||||
|
import { ClusterManager } from "../../cluster-manager";
|
||||||
|
|
||||||
jest.mock("electron", () => ({
|
jest.mock("electron", () => ({
|
||||||
app: {
|
app: {
|
||||||
@ -38,10 +39,13 @@ describe("kubeconfig-sync.source tests", () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mockFs();
|
mockFs();
|
||||||
ClusterStore.createInstance();
|
ClusterStore.createInstance();
|
||||||
|
ClusterManager.createInstance();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
mockFs.restore();
|
mockFs.restore();
|
||||||
|
ClusterStore.resetInstance();
|
||||||
|
ClusterManager.resetInstance();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("configsToModels", () => {
|
describe("configsToModels", () => {
|
||||||
|
|||||||
@ -19,4 +19,5 @@
|
|||||||
* 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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
export { initializeWeblinks } from "./weblinks";
|
||||||
export { KubeconfigSyncManager } from "./kubeconfig-sync";
|
export { KubeconfigSyncManager } from "./kubeconfig-sync";
|
||||||
|
|||||||
@ -31,7 +31,7 @@ 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";
|
||||||
import { Cluster } from "../cluster";
|
import { Cluster } from "../cluster";
|
||||||
import { catalogEntityFromCluster } from "../cluster-manager";
|
import { catalogEntityFromCluster, ClusterManager } from "../cluster-manager";
|
||||||
import { UserStore } from "../../common/user-store";
|
import { UserStore } from "../../common/user-store";
|
||||||
import { ClusterStore, UpdateClusterModel } from "../../common/cluster-store";
|
import { ClusterStore, UpdateClusterModel } from "../../common/cluster-store";
|
||||||
import { createHash } from "crypto";
|
import { createHash } from "crypto";
|
||||||
@ -170,6 +170,9 @@ export function computeDiff(contents: string, source: RootSource, filePath: stri
|
|||||||
|
|
||||||
// remove and disconnect clusters that were removed from the config
|
// remove and disconnect clusters that were removed from the config
|
||||||
if (!model) {
|
if (!model) {
|
||||||
|
// remove from the deleting set, so that if a new context of the same name is added, it isn't marked as deleting
|
||||||
|
ClusterManager.getInstance().deleting.delete(value[0].id);
|
||||||
|
|
||||||
value[0].disconnect();
|
value[0].disconnect();
|
||||||
source.delete(contextName);
|
source.delete(contextName);
|
||||||
logger.debug(`${logPrefix} Removed old cluster from sync`, { filePath, contextName });
|
logger.debug(`${logPrefix} Removed old cluster from sync`, { filePath, contextName });
|
||||||
|
|||||||
102
src/main/catalog-sources/weblinks.ts
Normal file
102
src/main/catalog-sources/weblinks.ts
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 OpenLens Authors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { observable, reaction } from "mobx";
|
||||||
|
import { WeblinkStore } from "../../common/weblink-store";
|
||||||
|
import { WebLink } from "../../common/catalog-entities";
|
||||||
|
import { catalogEntityRegistry } from "../catalog";
|
||||||
|
import got from "got";
|
||||||
|
import logger from "../logger";
|
||||||
|
import { docsUrl, slackUrl } from "../../common/vars";
|
||||||
|
|
||||||
|
const defaultLinks = [
|
||||||
|
{ title: "Lens Website", url: "https://k8slens.dev" },
|
||||||
|
{ title: "Lens Documentation", url: docsUrl },
|
||||||
|
{ title: "Lens Community Slack", url: slackUrl },
|
||||||
|
{ title: "Kubernetes Documentation", url: "https://kubernetes.io/docs/home/" },
|
||||||
|
{ title: "Lens on Twitter", url: "https://twitter.com/k8slens" },
|
||||||
|
{ title: "Lens Official Blog", url: "https://medium.com/k8slens" }
|
||||||
|
].map((link) => (
|
||||||
|
new WebLink({
|
||||||
|
metadata: {
|
||||||
|
uid: link.url,
|
||||||
|
name: link.title,
|
||||||
|
source: "app",
|
||||||
|
labels: {}
|
||||||
|
},
|
||||||
|
spec: {
|
||||||
|
url: link.url
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
phase: "available",
|
||||||
|
active: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
));
|
||||||
|
|
||||||
|
async function validateLink(link: WebLink) {
|
||||||
|
try {
|
||||||
|
const response = await got.get(link.spec.url, {
|
||||||
|
throwHttpErrors: false
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.statusCode >= 200 && response.statusCode < 500) {
|
||||||
|
link.status.phase = "available";
|
||||||
|
} else {
|
||||||
|
link.status.phase = "unavailable";
|
||||||
|
}
|
||||||
|
} catch(error) {
|
||||||
|
link.status.phase = "unavailable";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function initializeWeblinks() {
|
||||||
|
const weblinkStore = WeblinkStore.getInstance();
|
||||||
|
const weblinks = observable.array(defaultLinks);
|
||||||
|
|
||||||
|
reaction(() => weblinkStore.weblinks, (links) => {
|
||||||
|
weblinks.replace(links.map((data) => new WebLink({
|
||||||
|
metadata: {
|
||||||
|
uid: data.id,
|
||||||
|
name: data.name,
|
||||||
|
source: "local",
|
||||||
|
labels: {}
|
||||||
|
},
|
||||||
|
spec: {
|
||||||
|
url: data.url
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
phase: "available",
|
||||||
|
active: true
|
||||||
|
}
|
||||||
|
})));
|
||||||
|
weblinks.push(...defaultLinks);
|
||||||
|
|
||||||
|
for (const link of weblinks) {
|
||||||
|
validateLink(link).catch((error) => {
|
||||||
|
logger.error(`failed to validate link ${link.spec.url}: %s`, error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, {fireImmediately: true});
|
||||||
|
|
||||||
|
catalogEntityRegistry.addObservableSource("weblinks", weblinks);
|
||||||
|
}
|
||||||
@ -58,7 +58,7 @@ describe("CatalogEntityRegistry", () => {
|
|||||||
url: "https://k8slens.dev"
|
url: "https://k8slens.dev"
|
||||||
},
|
},
|
||||||
status: {
|
status: {
|
||||||
phase: "valid"
|
phase: "available"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const invalidEntity = new InvalidEntity({
|
const invalidEntity = new InvalidEntity({
|
||||||
@ -72,7 +72,7 @@ describe("CatalogEntityRegistry", () => {
|
|||||||
url: "https://k8slens.dev"
|
url: "https://k8slens.dev"
|
||||||
},
|
},
|
||||||
status: {
|
status: {
|
||||||
phase: "valid"
|
phase: "available"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -21,8 +21,8 @@
|
|||||||
|
|
||||||
import "../common/cluster-ipc";
|
import "../common/cluster-ipc";
|
||||||
import type http from "http";
|
import type http from "http";
|
||||||
import { action, autorun, makeObservable, reaction, toJS } from "mobx";
|
import { action, autorun, makeObservable, observable, observe, reaction, toJS } from "mobx";
|
||||||
import { ClusterStore, getClusterIdFromHost } from "../common/cluster-store";
|
import { ClusterId, ClusterStore, getClusterIdFromHost } from "../common/cluster-store";
|
||||||
import type { Cluster } from "./cluster";
|
import type { Cluster } from "./cluster";
|
||||||
import logger from "./logger";
|
import logger from "./logger";
|
||||||
import { apiKubePrefix } from "../common/vars";
|
import { apiKubePrefix } from "../common/vars";
|
||||||
@ -30,17 +30,18 @@ import { Singleton } from "../common/utils";
|
|||||||
import { catalogEntityRegistry } from "./catalog";
|
import { catalogEntityRegistry } from "./catalog";
|
||||||
import { KubernetesCluster, KubernetesClusterPrometheusMetrics } from "../common/catalog-entities/kubernetes-cluster";
|
import { KubernetesCluster, KubernetesClusterPrometheusMetrics } from "../common/catalog-entities/kubernetes-cluster";
|
||||||
import { ipcMainOn } from "../common/ipc";
|
import { ipcMainOn } from "../common/ipc";
|
||||||
|
import { once } from "lodash";
|
||||||
|
|
||||||
export class ClusterManager extends Singleton {
|
export class ClusterManager extends Singleton {
|
||||||
private store = ClusterStore.getInstance();
|
private store = ClusterStore.getInstance();
|
||||||
|
deleting = observable.set<ClusterId>();
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
this.bindEvents();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bindEvents() {
|
init = once(() => {
|
||||||
// reacting to every cluster's state change and total amount of items
|
// reacting to every cluster's state change and total amount of items
|
||||||
reaction(
|
reaction(
|
||||||
() => this.store.clustersList.map(c => c.getState()),
|
() => this.store.clustersList.map(c => c.getState()),
|
||||||
@ -59,6 +60,12 @@ export class ClusterManager extends Singleton {
|
|||||||
this.syncClustersFromCatalog(entities);
|
this.syncClustersFromCatalog(entities);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
observe(this.deleting, change => {
|
||||||
|
if (change.type === "add") {
|
||||||
|
this.updateEntityStatus(catalogEntityRegistry.getById(change.newValue));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// auto-stop removed clusters
|
// auto-stop removed clusters
|
||||||
autorun(() => {
|
autorun(() => {
|
||||||
const removedClusters = Array.from(this.store.removedClusters.values());
|
const removedClusters = Array.from(this.store.removedClusters.values());
|
||||||
@ -76,7 +83,7 @@ export class ClusterManager extends Singleton {
|
|||||||
|
|
||||||
ipcMainOn("network:offline", this.onNetworkOffline);
|
ipcMainOn("network:offline", this.onNetworkOffline);
|
||||||
ipcMainOn("network:online", this.onNetworkOnline);
|
ipcMainOn("network:online", this.onNetworkOnline);
|
||||||
}
|
});
|
||||||
|
|
||||||
@action
|
@action
|
||||||
protected updateCatalog(clusters: Cluster[]) {
|
protected updateCatalog(clusters: Cluster[]) {
|
||||||
@ -115,8 +122,15 @@ export class ClusterManager extends Singleton {
|
|||||||
catalogEntityRegistry.items.splice(index, 1, entity);
|
catalogEntityRegistry.items.splice(index, 1, entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected updateEntityStatus(entity: KubernetesCluster, cluster: Cluster) {
|
@action
|
||||||
entity.status.phase = cluster.accessible ? "connected" : "disconnected";
|
protected updateEntityStatus(entity: KubernetesCluster, cluster?: Cluster) {
|
||||||
|
if (this.deleting.has(entity.getId())) {
|
||||||
|
entity.status.phase = "deleting";
|
||||||
|
entity.status.enabled = false;
|
||||||
|
} else {
|
||||||
|
entity.status.phase = cluster?.accessible ? "connected" : "disconnected";
|
||||||
|
entity.status.enabled = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@action syncClustersFromCatalog(entities: KubernetesCluster[]) {
|
@action syncClustersFromCatalog(entities: KubernetesCluster[]) {
|
||||||
|
|||||||
@ -88,12 +88,7 @@ export interface ClusterState {
|
|||||||
export class Cluster implements ClusterModel, ClusterState {
|
export class Cluster implements ClusterModel, ClusterState {
|
||||||
/** Unique id for a cluster */
|
/** Unique id for a cluster */
|
||||||
public readonly id: ClusterId;
|
public readonly id: ClusterId;
|
||||||
/**
|
private kubeCtl: Kubectl;
|
||||||
* Kubectl
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
public kubeCtl: Kubectl;
|
|
||||||
/**
|
/**
|
||||||
* Context handler
|
* Context handler
|
||||||
*
|
*
|
||||||
@ -363,7 +358,7 @@ export class Cluster implements ClusterModel, ClusterState {
|
|||||||
|
|
||||||
if (this.accessible) {
|
if (this.accessible) {
|
||||||
await this.refreshAccessibility();
|
await this.refreshAccessibility();
|
||||||
this.ensureKubectl();
|
this.ensureKubectl(); // download kubectl in background, so it's not blocking dashboard
|
||||||
}
|
}
|
||||||
this.activated = true;
|
this.activated = true;
|
||||||
|
|
||||||
@ -373,10 +368,12 @@ export class Cluster implements ClusterModel, ClusterState {
|
|||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
protected async ensureKubectl() {
|
async ensureKubectl() {
|
||||||
this.kubeCtl = new Kubectl(this.version);
|
this.kubeCtl ??= new Kubectl(this.version);
|
||||||
|
|
||||||
return this.kubeCtl.ensureKubectl(); // download kubectl in background, so it's not blocking dashboard
|
await this.kubeCtl.ensureKubectl();
|
||||||
|
|
||||||
|
return this.kubeCtl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -650,7 +647,7 @@ export class Cluster implements ClusterModel, ClusterState {
|
|||||||
const api = (await this.getProxyKubeconfig()).makeApiClient(CoreV1Api);
|
const api = (await this.getProxyKubeconfig()).makeApiClient(CoreV1Api);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { body: { items }} = await api.listNamespace();
|
const { body: { items } } = await api.listNamespace();
|
||||||
const namespaces = items.map(ns => ns.metadata.name);
|
const namespaces = items.map(ns => ns.metadata.name);
|
||||||
|
|
||||||
this.getAllowedNamespacesErrorCount = 0; // reset on success
|
this.getAllowedNamespacesErrorCount = 0; // reset on success
|
||||||
|
|||||||
@ -169,9 +169,10 @@ export async function rollback(name: string, namespace: string, revision: number
|
|||||||
async function getResources(name: string, namespace: string, cluster: Cluster) {
|
async function getResources(name: string, namespace: string, cluster: Cluster) {
|
||||||
try {
|
try {
|
||||||
const helm = await helmCli.binaryPath();
|
const helm = await helmCli.binaryPath();
|
||||||
const kubectl = await cluster.kubeCtl.getPath();
|
const kubectl = await cluster.ensureKubectl();
|
||||||
|
const kubectlPath = await kubectl.getPath();
|
||||||
const pathToKubeconfig = await cluster.getProxyKubeconfigPath();
|
const pathToKubeconfig = await cluster.getProxyKubeconfigPath();
|
||||||
const { stdout } = await promiseExec(`"${helm}" get manifest ${name} --namespace ${namespace} --kubeconfig ${pathToKubeconfig} | "${kubectl}" get -n ${namespace} --kubeconfig ${pathToKubeconfig} -f - -o=json`);
|
const { stdout } = await promiseExec(`"${helm}" get manifest ${name} --namespace ${namespace} --kubeconfig ${pathToKubeconfig} | "${kubectlPath}" get -n ${namespace} --kubeconfig ${pathToKubeconfig} -f - -o=json`);
|
||||||
|
|
||||||
return JSON.parse(stdout).items;
|
return JSON.parse(stdout).items;
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@ -35,14 +35,10 @@ import { shellSync } from "./shell-sync";
|
|||||||
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 { UserStore } from "../common/user-store";
|
|
||||||
import { appEventBus } from "../common/event-bus";
|
import { appEventBus } from "../common/event-bus";
|
||||||
import { ExtensionLoader } from "../extensions/extension-loader";
|
import { ExtensionLoader } from "../extensions/extension-loader";
|
||||||
import { ExtensionsStore } from "../extensions/extensions-store";
|
|
||||||
import { InstalledExtension, ExtensionDiscovery } from "../extensions/extension-discovery";
|
import { InstalledExtension, ExtensionDiscovery } from "../extensions/extension-discovery";
|
||||||
import type { LensExtensionId } from "../extensions/lens-extension";
|
import type { LensExtensionId } from "../extensions/lens-extension";
|
||||||
import { FilesystemProvisionerStore } from "./extension-filesystem";
|
|
||||||
import { installDeveloperTools } from "./developer-tools";
|
import { installDeveloperTools } from "./developer-tools";
|
||||||
import { LensProtocolRouterMain } from "./protocol-handler";
|
import { LensProtocolRouterMain } from "./protocol-handler";
|
||||||
import { disposer, getAppVersion, getAppVersionFromProxyServer } from "../common/utils";
|
import { disposer, getAppVersion, getAppVersionFromProxyServer } from "../common/utils";
|
||||||
@ -51,7 +47,6 @@ import { startUpdateChecking } from "./app-updater";
|
|||||||
import { IpcRendererNavigationEvents } from "../renderer/navigation/events";
|
import { IpcRendererNavigationEvents } from "../renderer/navigation/events";
|
||||||
import { pushCatalogToRenderer } from "./catalog-pusher";
|
import { pushCatalogToRenderer } from "./catalog-pusher";
|
||||||
import { catalogEntityRegistry } from "./catalog";
|
import { catalogEntityRegistry } from "./catalog";
|
||||||
import { HotbarStore } from "../common/hotbar-store";
|
|
||||||
import { HelmRepoManager } from "./helm/helm-repo-manager";
|
import { HelmRepoManager } from "./helm/helm-repo-manager";
|
||||||
import { KubeconfigSyncManager } from "./catalog-sources";
|
import { KubeconfigSyncManager } from "./catalog-sources";
|
||||||
import { handleWsUpgrade } from "./proxy/ws-upgrade";
|
import { handleWsUpgrade } from "./proxy/ws-upgrade";
|
||||||
@ -129,27 +124,17 @@ app.on("ready", async () => {
|
|||||||
PrometheusProviderRegistry.createInstance();
|
PrometheusProviderRegistry.createInstance();
|
||||||
initializers.initPrometheusProviderRegistry();
|
initializers.initPrometheusProviderRegistry();
|
||||||
|
|
||||||
const userStore = UserStore.createInstance();
|
await initializers.initializeStores();
|
||||||
const clusterStore = ClusterStore.createInstance();
|
initializers.initializeWeblinks();
|
||||||
const hotbarStore = HotbarStore.createInstance();
|
|
||||||
const extensionsStore = ExtensionsStore.createInstance();
|
|
||||||
const filesystemStore = FilesystemProvisionerStore.createInstance();
|
|
||||||
|
|
||||||
HelmRepoManager.createInstance(); // create the instance
|
HelmRepoManager.createInstance(); // create the instance
|
||||||
|
|
||||||
logger.info("💾 Loading stores");
|
const lensProxy = LensProxy.createInstance(
|
||||||
// preload
|
handleWsUpgrade,
|
||||||
await Promise.all([
|
req => ClusterManager.getInstance().getClusterForRequest(req),
|
||||||
userStore.load(),
|
);
|
||||||
clusterStore.load(),
|
|
||||||
hotbarStore.load(),
|
ClusterManager.createInstance().init();
|
||||||
extensionsStore.load(),
|
|
||||||
filesystemStore.load(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
const lensProxy = LensProxy.createInstance(handleWsUpgrade);
|
|
||||||
|
|
||||||
ClusterManager.createInstance();
|
|
||||||
KubeconfigSyncManager.createInstance();
|
KubeconfigSyncManager.createInstance();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -256,13 +241,13 @@ app.on("will-quit", (event) => {
|
|||||||
// This is called when the close button of the main window is clicked
|
// This is called when the close button of the main window is clicked
|
||||||
|
|
||||||
const lprm = LensProtocolRouterMain.getInstance(false);
|
const lprm = LensProtocolRouterMain.getInstance(false);
|
||||||
|
|
||||||
logger.info("APP:QUIT");
|
logger.info("APP:QUIT");
|
||||||
appEventBus.emit({ name: "app", action: "close" });
|
appEventBus.emit({ name: "app", action: "close" });
|
||||||
ClusterManager.getInstance(false)?.stop(); // close cluster connections
|
ClusterManager.getInstance(false)?.stop(); // close cluster connections
|
||||||
KubeconfigSyncManager.getInstance(false)?.stopSync();
|
KubeconfigSyncManager.getInstance(false)?.stopSync();
|
||||||
cleanup();
|
cleanup();
|
||||||
|
|
||||||
if (lprm) {
|
if (lprm) {
|
||||||
// This is set to false here so that LPRM can wait to send future lens://
|
// This is set to false here so that LPRM can wait to send future lens://
|
||||||
// requests until after it loads again
|
// requests until after it loads again
|
||||||
@ -271,7 +256,7 @@ app.on("will-quit", (event) => {
|
|||||||
|
|
||||||
if (blockQuit) {
|
if (blockQuit) {
|
||||||
// Quit app on Cmd+Q (MacOS)
|
// Quit app on Cmd+Q (MacOS)
|
||||||
|
|
||||||
event.preventDefault(); // prevent app's default shutdown (e.g. required for telemetry, etc.)
|
event.preventDefault(); // prevent app's default shutdown (e.g. required for telemetry, etc.)
|
||||||
|
|
||||||
return; // skip exit to make tray work, to quit go to app's global menu or tray's menu
|
return; // skip exit to make tray work, to quit go to app's global menu or tray's menu
|
||||||
|
|||||||
@ -22,3 +22,5 @@
|
|||||||
export * from "./registries";
|
export * from "./registries";
|
||||||
export * from "./metrics-providers";
|
export * from "./metrics-providers";
|
||||||
export * from "./ipc";
|
export * from "./ipc";
|
||||||
|
export * from "./weblinks";
|
||||||
|
export * from "./stores";
|
||||||
|
|||||||
@ -22,11 +22,15 @@
|
|||||||
import type { IpcMainInvokeEvent } from "electron";
|
import type { IpcMainInvokeEvent } from "electron";
|
||||||
import type { KubernetesCluster } from "../../common/catalog-entities";
|
import type { KubernetesCluster } from "../../common/catalog-entities";
|
||||||
import { clusterFrameMap } from "../../common/cluster-frames";
|
import { clusterFrameMap } from "../../common/cluster-frames";
|
||||||
import { clusterActivateHandler, clusterSetFrameIdHandler, clusterVisibilityHandler, clusterRefreshHandler, clusterDisconnectHandler, clusterKubectlApplyAllHandler, clusterKubectlDeleteAllHandler } from "../../common/cluster-ipc";
|
import { clusterActivateHandler, clusterSetFrameIdHandler, clusterVisibilityHandler, clusterRefreshHandler, clusterDisconnectHandler, clusterKubectlApplyAllHandler, clusterKubectlDeleteAllHandler, clusterDeleteHandler } from "../../common/cluster-ipc";
|
||||||
import { ClusterId, ClusterStore } from "../../common/cluster-store";
|
import { ClusterId, ClusterStore } from "../../common/cluster-store";
|
||||||
import { appEventBus } from "../../common/event-bus";
|
import { appEventBus } from "../../common/event-bus";
|
||||||
import { ipcMainHandle } from "../../common/ipc";
|
import { ipcMainHandle } from "../../common/ipc";
|
||||||
import { catalogEntityRegistry } from "../catalog";
|
import { catalogEntityRegistry } from "../catalog";
|
||||||
|
import { ClusterManager } from "../cluster-manager";
|
||||||
|
import { bundledKubectlPath } from "../kubectl";
|
||||||
|
import logger from "../logger";
|
||||||
|
import { promiseExecFile } from "../promise-exec";
|
||||||
import { ResourceApplier } from "../resource-applier";
|
import { ResourceApplier } from "../resource-applier";
|
||||||
|
|
||||||
export function initIpcMainHandlers() {
|
export function initIpcMainHandlers() {
|
||||||
@ -73,6 +77,29 @@ export function initIpcMainHandlers() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipcMainHandle(clusterDeleteHandler, async (event, clusterId: ClusterId) => {
|
||||||
|
appEventBus.emit({ name: "cluster", action: "remove" });
|
||||||
|
const cluster = ClusterStore.getInstance().getById(clusterId);
|
||||||
|
|
||||||
|
if (!cluster) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClusterManager.getInstance().deleting.add(clusterId);
|
||||||
|
cluster.disconnect();
|
||||||
|
clusterFrameMap.delete(cluster.id);
|
||||||
|
const kubectlPath = bundledKubectlPath();
|
||||||
|
const args = ["config", "delete-context", cluster.contextName, "--kubeconfig", cluster.kubeConfigPath];
|
||||||
|
|
||||||
|
try {
|
||||||
|
await promiseExecFile(kubectlPath, args);
|
||||||
|
} catch ({ stderr }) {
|
||||||
|
logger.error(`[CLUSTER-REMOVE]: failed to remove cluster: ${stderr}`, { clusterId, context: cluster.contextName });
|
||||||
|
|
||||||
|
throw `Failed to remove cluster: ${stderr}`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
ipcMainHandle(clusterKubectlApplyAllHandler, async (event, clusterId: ClusterId, resources: string[], extraArgs: string[]) => {
|
ipcMainHandle(clusterKubectlApplyAllHandler, async (event, clusterId: ClusterId, resources: string[], extraArgs: string[]) => {
|
||||||
appEventBus.emit({ name: "cluster", action: "kubectl-apply-all" });
|
appEventBus.emit({ name: "cluster", action: "kubectl-apply-all" });
|
||||||
const cluster = ClusterStore.getInstance().getById(clusterId);
|
const cluster = ClusterStore.getInstance().getById(clusterId);
|
||||||
|
|||||||
48
src/main/initializers/stores.ts
Normal file
48
src/main/initializers/stores.ts
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 OpenLens Authors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { HotbarStore } from "../../common/hotbar-store";
|
||||||
|
import { ClusterStore } from "../../common/cluster-store";
|
||||||
|
import { UserStore } from "../../common/user-store";
|
||||||
|
import { ExtensionsStore } from "../../extensions/extensions-store";
|
||||||
|
import { FilesystemProvisionerStore } from "../extension-filesystem";
|
||||||
|
import { WeblinkStore } from "../../common/weblink-store";
|
||||||
|
import logger from "../logger";
|
||||||
|
|
||||||
|
export async function initializeStores() {
|
||||||
|
const userStore = UserStore.createInstance();
|
||||||
|
const clusterStore = ClusterStore.createInstance();
|
||||||
|
const hotbarStore = HotbarStore.createInstance();
|
||||||
|
const extensionsStore = ExtensionsStore.createInstance();
|
||||||
|
const filesystemStore = FilesystemProvisionerStore.createInstance();
|
||||||
|
const weblinkStore = WeblinkStore.createInstance();
|
||||||
|
|
||||||
|
logger.info("💾 Loading stores");
|
||||||
|
// preload
|
||||||
|
await Promise.all([
|
||||||
|
userStore.load(),
|
||||||
|
clusterStore.load(),
|
||||||
|
hotbarStore.load(),
|
||||||
|
extensionsStore.load(),
|
||||||
|
filesystemStore.load(),
|
||||||
|
weblinkStore.load()
|
||||||
|
]);
|
||||||
|
}
|
||||||
22
src/main/initializers/weblinks.ts
Normal file
22
src/main/initializers/weblinks.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 OpenLens Authors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export { initializeWeblinks } from "../catalog-sources";
|
||||||
@ -31,6 +31,7 @@ import { UserStore } from "../common/user-store";
|
|||||||
import { customRequest } from "../common/request";
|
import { customRequest } from "../common/request";
|
||||||
import { getBundledKubectlVersion } from "../common/utils/app-version";
|
import { getBundledKubectlVersion } from "../common/utils/app-version";
|
||||||
import { isDevelopment, isWindows, isTestEnv } from "../common/vars";
|
import { isDevelopment, isWindows, isTestEnv } from "../common/vars";
|
||||||
|
import { SemVer } from "semver";
|
||||||
|
|
||||||
const bundledVersion = getBundledKubectlVersion();
|
const bundledVersion = getBundledKubectlVersion();
|
||||||
const kubectlMap: Map<string, string> = new Map([
|
const kubectlMap: Map<string, string> = new Map([
|
||||||
@ -92,14 +93,19 @@ export class Kubectl {
|
|||||||
|
|
||||||
// Returns the single bundled Kubectl instance
|
// Returns the single bundled Kubectl instance
|
||||||
public static bundled() {
|
public static bundled() {
|
||||||
if (!Kubectl.bundledInstance) Kubectl.bundledInstance = new Kubectl(Kubectl.bundledKubectlVersion);
|
return Kubectl.bundledInstance ??= new Kubectl(Kubectl.bundledKubectlVersion);
|
||||||
|
|
||||||
return Kubectl.bundledInstance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(clusterVersion: string) {
|
constructor(clusterVersion: string) {
|
||||||
const versionParts = /^v?(\d+\.\d+)(.*)/.exec(clusterVersion);
|
let version: SemVer;
|
||||||
const minorVersion = versionParts[1];
|
|
||||||
|
try {
|
||||||
|
version = new SemVer(clusterVersion, { includePrerelease: false });
|
||||||
|
} catch {
|
||||||
|
version = new SemVer(Kubectl.bundledKubectlVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
const minorVersion = `${version.major}.${version.minor}`;
|
||||||
|
|
||||||
/* minorVersion is the first two digits of kube server version
|
/* minorVersion is the first two digits of kube server version
|
||||||
if the version map includes that, use that version, if not, fallback to the exact x.y.z of kube version */
|
if the version map includes that, use that version, if not, fallback to the exact x.y.z of kube version */
|
||||||
@ -107,7 +113,7 @@ export class Kubectl {
|
|||||||
this.kubectlVersion = kubectlMap.get(minorVersion);
|
this.kubectlVersion = kubectlMap.get(minorVersion);
|
||||||
logger.debug(`Set kubectl version ${this.kubectlVersion} for cluster version ${clusterVersion} using version map`);
|
logger.debug(`Set kubectl version ${this.kubectlVersion} for cluster version ${clusterVersion} using version map`);
|
||||||
} else {
|
} else {
|
||||||
this.kubectlVersion = versionParts[1] + versionParts[2];
|
this.kubectlVersion = version.format();
|
||||||
logger.debug(`Set kubectl version ${this.kubectlVersion} for cluster version ${clusterVersion} using fallback`);
|
logger.debug(`Set kubectl version ${this.kubectlVersion} for cluster version ${clusterVersion} using fallback`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,6 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import * as util from "util";
|
import * as util from "util";
|
||||||
import { exec } from "child_process";
|
import { exec, execFile } from "child_process";
|
||||||
|
|
||||||
export const promiseExec = util.promisify(exec);
|
export const promiseExec = util.promisify(exec);
|
||||||
|
export const promiseExecFile = util.promisify(execFile);
|
||||||
|
|||||||
@ -29,7 +29,7 @@ import { Router } from "../router";
|
|||||||
import type { ContextHandler } from "../context-handler";
|
import type { ContextHandler } from "../context-handler";
|
||||||
import logger from "../logger";
|
import logger from "../logger";
|
||||||
import { Singleton } from "../../common/utils";
|
import { Singleton } from "../../common/utils";
|
||||||
import { ClusterManager } from "../cluster-manager";
|
import type { Cluster } from "../cluster";
|
||||||
|
|
||||||
type WSUpgradeHandler = (req: http.IncomingMessage, socket: net.Socket, head: Buffer) => void;
|
type WSUpgradeHandler = (req: http.IncomingMessage, socket: net.Socket, head: Buffer) => void;
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ export class LensProxy extends Singleton {
|
|||||||
|
|
||||||
public port: number;
|
public port: number;
|
||||||
|
|
||||||
constructor(handleWsUpgrade: WSUpgradeHandler) {
|
constructor(handleWsUpgrade: WSUpgradeHandler, protected getClusterForRequest: (req: http.IncomingMessage) => Cluster | undefined) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
const proxy = this.createProxy();
|
const proxy = this.createProxy();
|
||||||
@ -104,7 +104,7 @@ export class LensProxy extends Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected async handleProxyUpgrade(proxy: httpProxy, req: http.IncomingMessage, socket: net.Socket, head: Buffer) {
|
protected async handleProxyUpgrade(proxy: httpProxy, req: http.IncomingMessage, socket: net.Socket, head: Buffer) {
|
||||||
const cluster = ClusterManager.getInstance().getClusterForRequest(req);
|
const cluster = this.getClusterForRequest(req);
|
||||||
|
|
||||||
if (cluster) {
|
if (cluster) {
|
||||||
const proxyUrl = await cluster.contextHandler.resolveAuthProxyUrl() + req.url.replace(apiKubePrefix, "");
|
const proxyUrl = await cluster.contextHandler.resolveAuthProxyUrl() + req.url.replace(apiKubePrefix, "");
|
||||||
@ -220,7 +220,7 @@ export class LensProxy extends Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected async handleRequest(proxy: httpProxy, req: http.IncomingMessage, res: http.ServerResponse) {
|
protected async handleRequest(proxy: httpProxy, req: http.IncomingMessage, res: http.ServerResponse) {
|
||||||
const cluster = ClusterManager.getInstance().getClusterForRequest(req);
|
const cluster = this.getClusterForRequest(req);
|
||||||
|
|
||||||
if (cluster) {
|
if (cluster) {
|
||||||
const proxyTarget = await this.getProxyTarget(req, cluster.contextHandler);
|
const proxyTarget = await this.getProxyTarget(req, cluster.contextHandler);
|
||||||
|
|||||||
@ -36,15 +36,15 @@ export class ResourceApplier {
|
|||||||
|
|
||||||
async apply(resource: KubernetesObject | any): Promise<string> {
|
async apply(resource: KubernetesObject | any): Promise<string> {
|
||||||
resource = this.sanitizeObject(resource);
|
resource = this.sanitizeObject(resource);
|
||||||
appEventBus.emit({name: "resource", action: "apply"});
|
appEventBus.emit({ name: "resource", action: "apply" });
|
||||||
|
|
||||||
return await this.kubectlApply(yaml.safeDump(resource));
|
return await this.kubectlApply(yaml.safeDump(resource));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async kubectlApply(content: string): Promise<string> {
|
protected async kubectlApply(content: string): Promise<string> {
|
||||||
const { kubeCtl } = this.cluster;
|
const kubectl = await this.cluster.ensureKubectl();
|
||||||
const kubectlPath = await kubeCtl.getPath();
|
const kubectlPath = await kubectl.getPath();
|
||||||
const proxyKubeconfigPath = await this.cluster.getProxyKubeconfigPath();
|
const proxyKubeconfigPath = await this.cluster.getProxyKubeconfigPath();
|
||||||
|
|
||||||
return new Promise<string>((resolve, reject) => {
|
return new Promise<string>((resolve, reject) => {
|
||||||
const fileName = tempy.file({ name: "resource.yaml" });
|
const fileName = tempy.file({ name: "resource.yaml" });
|
||||||
@ -82,9 +82,9 @@ export class ResourceApplier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected async kubectlCmdAll(subCmd: string, resources: string[], args: string[] = []): Promise<string> {
|
protected async kubectlCmdAll(subCmd: string, resources: string[], args: string[] = []): Promise<string> {
|
||||||
const { kubeCtl } = this.cluster;
|
const kubectl = await this.cluster.ensureKubectl();
|
||||||
const kubectlPath = await kubeCtl.getPath();
|
const kubectlPath = await kubectl.getPath();
|
||||||
const proxyKubeconfigPath = await this.cluster.getProxyKubeconfigPath();
|
const proxyKubeconfigPath = await this.cluster.getProxyKubeconfigPath();
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const tmpDir = tempy.directory();
|
const tmpDir = tempy.directory();
|
||||||
|
|||||||
@ -23,69 +23,68 @@
|
|||||||
// convert file path cluster icons to their base64 encoded versions
|
// convert file path cluster icons to their base64 encoded versions
|
||||||
|
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { app, remote } from "electron";
|
import { app } from "electron";
|
||||||
import { migration } from "../migration-wrapper";
|
import { migration } from "../migration-wrapper";
|
||||||
import fse from "fs-extra";
|
import fse from "fs-extra";
|
||||||
import { ClusterModel, ClusterStore } from "../../common/cluster-store";
|
import { ClusterModel, ClusterStore } from "../../common/cluster-store";
|
||||||
import { loadConfigFromFileSync } from "../../common/kube-helpers";
|
import { loadConfigFromFileSync } from "../../common/kube-helpers";
|
||||||
|
|
||||||
|
interface Pre360ClusterModel extends ClusterModel {
|
||||||
|
kubeConfig: string;
|
||||||
|
}
|
||||||
|
|
||||||
export default migration({
|
export default migration({
|
||||||
version: "3.6.0-beta.1",
|
version: "3.6.0-beta.1",
|
||||||
run(store, printLog) {
|
run(store, printLog) {
|
||||||
const userDataPath = (app || remote.app).getPath("userData");
|
const userDataPath = app.getPath("userData");
|
||||||
const kubeConfigBase = ClusterStore.getCustomKubeConfigPath("");
|
const storedClusters: Pre360ClusterModel[] = store.get("clusters") ?? [];
|
||||||
const storedClusters: ClusterModel[] = store.get("clusters") || [];
|
const migratedClusters: ClusterModel[] = [];
|
||||||
|
|
||||||
if (!storedClusters.length) return;
|
fse.ensureDirSync(ClusterStore.storedKubeConfigFolder);
|
||||||
fse.ensureDirSync(kubeConfigBase);
|
|
||||||
|
|
||||||
printLog("Number of clusters to migrate: ", storedClusters.length);
|
printLog("Number of clusters to migrate: ", storedClusters.length);
|
||||||
const migratedClusters = storedClusters
|
|
||||||
.map(cluster => {
|
|
||||||
/**
|
|
||||||
* migrate kubeconfig
|
|
||||||
*/
|
|
||||||
try {
|
|
||||||
const absPath = ClusterStore.getCustomKubeConfigPath(cluster.id);
|
|
||||||
|
|
||||||
fse.ensureDirSync(path.dirname(absPath));
|
for (const clusterModel of storedClusters) {
|
||||||
fse.writeFileSync(absPath, cluster.kubeConfig, { encoding: "utf-8", mode: 0o600 });
|
/**
|
||||||
// take the embedded kubeconfig and dump it into a file
|
* migrate kubeconfig
|
||||||
cluster.kubeConfigPath = absPath;
|
*/
|
||||||
cluster.contextName = loadConfigFromFileSync(cluster.kubeConfigPath).config.getCurrentContext();
|
try {
|
||||||
delete cluster.kubeConfig;
|
const absPath = ClusterStore.getCustomKubeConfigPath(clusterModel.id);
|
||||||
|
|
||||||
} catch (error) {
|
// take the embedded kubeconfig and dump it into a file
|
||||||
printLog(`Failed to migrate Kubeconfig for cluster "${cluster.id}", removing cluster...`, error);
|
fse.writeFileSync(absPath, clusterModel.kubeConfig, { encoding: "utf-8", mode: 0o600 });
|
||||||
|
|
||||||
return undefined;
|
clusterModel.kubeConfigPath = absPath;
|
||||||
|
clusterModel.contextName = loadConfigFromFileSync(clusterModel.kubeConfigPath).config.getCurrentContext();
|
||||||
|
delete clusterModel.kubeConfig;
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
printLog(`Failed to migrate Kubeconfig for cluster "${clusterModel.id}", removing clusterModel...`, error);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* migrate cluster icon
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
if (clusterModel.preferences?.icon) {
|
||||||
|
printLog(`migrating ${clusterModel.preferences.icon} for ${clusterModel.preferences.clusterName}`);
|
||||||
|
const iconPath = clusterModel.preferences.icon.replace("store://", "");
|
||||||
|
const fileData = fse.readFileSync(path.join(userDataPath, iconPath));
|
||||||
|
|
||||||
|
clusterModel.preferences.icon = `data:;base64,${fileData.toString("base64")}`;
|
||||||
|
} else {
|
||||||
|
delete clusterModel.preferences?.icon;
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
printLog(`Failed to migrate cluster icon for cluster "${clusterModel.id}"`, error);
|
||||||
|
delete clusterModel.preferences.icon;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
migratedClusters.push(clusterModel);
|
||||||
* migrate cluster icon
|
|
||||||
*/
|
|
||||||
try {
|
|
||||||
if (cluster.preferences?.icon) {
|
|
||||||
printLog(`migrating ${cluster.preferences.icon} for ${cluster.preferences.clusterName}`);
|
|
||||||
const iconPath = cluster.preferences.icon.replace("store://", "");
|
|
||||||
const fileData = fse.readFileSync(path.join(userDataPath, iconPath));
|
|
||||||
|
|
||||||
cluster.preferences.icon = `data:;base64,${fileData.toString("base64")}`;
|
|
||||||
} else {
|
|
||||||
delete cluster.preferences?.icon;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
printLog(`Failed to migrate cluster icon for cluster "${cluster.id}"`, error);
|
|
||||||
delete cluster.preferences.icon;
|
|
||||||
}
|
|
||||||
|
|
||||||
return cluster;
|
|
||||||
})
|
|
||||||
.filter(c => c);
|
|
||||||
|
|
||||||
// "overwrite" the cluster configs
|
|
||||||
if (migratedClusters.length > 0) {
|
|
||||||
store.set("clusters", migratedClusters);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
store.set("clusters", migratedClusters);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -31,16 +31,12 @@ import * as LensExtensionsRendererApi from "../extensions/renderer-api";
|
|||||||
import { render, unmountComponentAtNode } from "react-dom";
|
import { render, unmountComponentAtNode } from "react-dom";
|
||||||
import { delay } from "../common/utils";
|
import { delay } from "../common/utils";
|
||||||
import { isMac, isDevelopment } from "../common/vars";
|
import { isMac, isDevelopment } from "../common/vars";
|
||||||
import { HotbarStore } from "../common/hotbar-store";
|
|
||||||
import { ClusterStore } from "../common/cluster-store";
|
import { ClusterStore } from "../common/cluster-store";
|
||||||
import { UserStore } from "../common/user-store";
|
import { UserStore } from "../common/user-store";
|
||||||
import { ExtensionDiscovery } from "../extensions/extension-discovery";
|
import { ExtensionDiscovery } from "../extensions/extension-discovery";
|
||||||
import { ExtensionLoader } from "../extensions/extension-loader";
|
import { ExtensionLoader } from "../extensions/extension-loader";
|
||||||
import { ExtensionsStore } from "../extensions/extensions-store";
|
|
||||||
import { FilesystemProvisionerStore } from "../main/extension-filesystem";
|
|
||||||
import { App } from "./components/app";
|
import { App } from "./components/app";
|
||||||
import { LensApp } from "./lens-app";
|
import { LensApp } from "./lens-app";
|
||||||
import { ThemeStore } from "./theme.store";
|
|
||||||
import { HelmRepoManager } from "../main/helm/helm-repo-manager";
|
import { HelmRepoManager } from "../main/helm/helm-repo-manager";
|
||||||
import { ExtensionInstallationStateStore } from "./components/+extensions/extension-install.store";
|
import { ExtensionInstallationStateStore } from "./components/+extensions/extension-install.store";
|
||||||
import { DefaultProps } from "./mui-base-theme";
|
import { DefaultProps } from "./mui-base-theme";
|
||||||
@ -77,33 +73,19 @@ export async function bootstrap(App: AppComponent) {
|
|||||||
initializers.intiKubeObjectDetailRegistry();
|
initializers.intiKubeObjectDetailRegistry();
|
||||||
initializers.initWelcomeMenuRegistry();
|
initializers.initWelcomeMenuRegistry();
|
||||||
initializers.initWorkloadsOverviewDetailRegistry();
|
initializers.initWorkloadsOverviewDetailRegistry();
|
||||||
|
initializers.initCatalog();
|
||||||
initializers.initIpcRendererListeners();
|
initializers.initIpcRendererListeners();
|
||||||
|
|
||||||
ExtensionLoader.createInstance().init();
|
ExtensionLoader.createInstance().init();
|
||||||
ExtensionDiscovery.createInstance().init();
|
ExtensionDiscovery.createInstance().init();
|
||||||
|
|
||||||
const userStore = UserStore.createInstance();
|
await initializers.initStores();
|
||||||
const clusterStore = ClusterStore.createInstance();
|
|
||||||
const extensionsStore = ExtensionsStore.createInstance();
|
|
||||||
const filesystemStore = FilesystemProvisionerStore.createInstance();
|
|
||||||
const themeStore = ThemeStore.createInstance();
|
|
||||||
const hotbarStore = HotbarStore.createInstance();
|
|
||||||
|
|
||||||
ExtensionInstallationStateStore.bindIpcListeners();
|
ExtensionInstallationStateStore.bindIpcListeners();
|
||||||
HelmRepoManager.createInstance(); // initialize the manager
|
HelmRepoManager.createInstance(); // initialize the manager
|
||||||
|
|
||||||
// preload common stores
|
|
||||||
await Promise.all([
|
|
||||||
userStore.load(),
|
|
||||||
hotbarStore.load(),
|
|
||||||
clusterStore.load(),
|
|
||||||
extensionsStore.load(),
|
|
||||||
filesystemStore.load(),
|
|
||||||
themeStore.init(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Register additional store listeners
|
// Register additional store listeners
|
||||||
clusterStore.registerIpcListener();
|
ClusterStore.getInstance().registerIpcListener();
|
||||||
|
|
||||||
// init app's dependencies if any
|
// init app's dependencies if any
|
||||||
if (App.init) {
|
if (App.init) {
|
||||||
|
|||||||
@ -26,28 +26,18 @@ import { Drawer, DrawerItem, DrawerItemLabels } from "../drawer";
|
|||||||
import { CatalogEntity, catalogEntityRunContext } from "../../api/catalog-entity";
|
import { CatalogEntity, catalogEntityRunContext } from "../../api/catalog-entity";
|
||||||
import type { CatalogCategory } from "../../../common/catalog";
|
import type { CatalogCategory } from "../../../common/catalog";
|
||||||
import { Icon } from "../icon";
|
import { Icon } from "../icon";
|
||||||
import { KubeObject } from "../../api/kube-object";
|
|
||||||
import { CatalogEntityDrawerMenu } from "./catalog-entity-drawer-menu";
|
import { CatalogEntityDrawerMenu } from "./catalog-entity-drawer-menu";
|
||||||
import { CatalogEntityDetailRegistry } from "../../../extensions/registries";
|
import { CatalogEntityDetailRegistry } from "../../../extensions/registries";
|
||||||
import { HotbarIcon } from "../hotbar/hotbar-icon";
|
import { HotbarIcon } from "../hotbar/hotbar-icon";
|
||||||
|
import type { CatalogEntityItem } from "./catalog-entity.store";
|
||||||
|
|
||||||
interface Props {
|
interface Props<T extends CatalogEntity> {
|
||||||
entity: CatalogEntity;
|
item: CatalogEntityItem<T> | null | undefined;
|
||||||
hideDetails(): void;
|
hideDetails(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class CatalogEntityDetails extends Component<Props> {
|
export class CatalogEntityDetails<T extends CatalogEntity> extends Component<Props<T>> {
|
||||||
private abortController?: AbortController;
|
|
||||||
|
|
||||||
constructor(props: Props) {
|
|
||||||
super(props);
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillUnmount() {
|
|
||||||
this.abortController?.abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
categoryIcon(category: CatalogCategory) {
|
categoryIcon(category: CatalogCategory) {
|
||||||
if (category.metadata.icon.includes("<svg")) {
|
if (category.metadata.icon.includes("<svg")) {
|
||||||
return <Icon svg={category.metadata.icon} smallest />;
|
return <Icon svg={category.metadata.icon} smallest />;
|
||||||
@ -56,16 +46,10 @@ export class CatalogEntityDetails extends Component<Props> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
openEntity() {
|
renderContent(item: CatalogEntityItem<T>) {
|
||||||
this.props.entity.onRun(catalogEntityRunContext);
|
const detailItems = CatalogEntityDetailRegistry.getInstance().getItemsForKind(item.kind, item.apiVersion);
|
||||||
}
|
const details = detailItems.map(({ components }, index) => {
|
||||||
|
return <components.Details entity={item.entity} key={index}/>;
|
||||||
renderContent() {
|
|
||||||
const { entity } = this.props;
|
|
||||||
const labels = KubeObject.stringifyLabels(entity.metadata.labels);
|
|
||||||
const detailItems = CatalogEntityDetailRegistry.getInstance().getItemsForKind(entity.kind, entity.apiVersion);
|
|
||||||
const details = detailItems.map((item, index) => {
|
|
||||||
return <item.components.Details entity={entity} key={index}/>;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const showDetails = detailItems.find((item) => item.priority > 999) === undefined;
|
const showDetails = detailItems.find((item) => item.priority > 999) === undefined;
|
||||||
@ -76,31 +60,37 @@ export class CatalogEntityDetails extends Component<Props> {
|
|||||||
<div className="flex CatalogEntityDetails">
|
<div className="flex CatalogEntityDetails">
|
||||||
<div className="EntityIcon box top left">
|
<div className="EntityIcon box top left">
|
||||||
<HotbarIcon
|
<HotbarIcon
|
||||||
uid={entity.metadata.uid}
|
uid={item.id}
|
||||||
title={entity.metadata.name}
|
title={item.name}
|
||||||
source={entity.metadata.source}
|
source={item.source}
|
||||||
src={entity.spec.icon?.src}
|
src={item.entity.spec.icon?.src}
|
||||||
material={entity.spec.icon?.material}
|
material={item.entity.spec.icon?.material}
|
||||||
background={entity.spec.icon?.background}
|
background={item.entity.spec.icon?.background}
|
||||||
onClick={() => this.openEntity()}
|
disabled={!item?.enabled}
|
||||||
|
onClick={() => item.onRun(catalogEntityRunContext)}
|
||||||
size={128} />
|
size={128} />
|
||||||
<div className="IconHint">
|
{item?.enabled && (
|
||||||
Click to open
|
<div className="IconHint">
|
||||||
</div>
|
Click to open
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="box grow EntityMetadata">
|
<div className="box grow EntityMetadata">
|
||||||
<DrawerItem name="Name">
|
<DrawerItem name="Name">
|
||||||
{entity.metadata.name}
|
{item.name}
|
||||||
</DrawerItem>
|
</DrawerItem>
|
||||||
<DrawerItem name="Kind">
|
<DrawerItem name="Kind">
|
||||||
{entity.kind}
|
{item.kind}
|
||||||
</DrawerItem>
|
</DrawerItem>
|
||||||
<DrawerItem name="Source">
|
<DrawerItem name="Source">
|
||||||
{entity.metadata.source}
|
{item.source}
|
||||||
|
</DrawerItem>
|
||||||
|
<DrawerItem name="Status">
|
||||||
|
{item.phase}
|
||||||
</DrawerItem>
|
</DrawerItem>
|
||||||
<DrawerItemLabels
|
<DrawerItemLabels
|
||||||
name="Labels"
|
name="Labels"
|
||||||
labels={labels}
|
labels={item.labels}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -113,8 +103,8 @@ export class CatalogEntityDetails extends Component<Props> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { entity, hideDetails } = this.props;
|
const { item, hideDetails } = this.props;
|
||||||
const title = `${entity.kind}: ${entity.metadata.name}`;
|
const title = `${item.kind}: ${item.name}`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Drawer
|
<Drawer
|
||||||
@ -122,10 +112,10 @@ export class CatalogEntityDetails extends Component<Props> {
|
|||||||
usePortal={true}
|
usePortal={true}
|
||||||
open={true}
|
open={true}
|
||||||
title={title}
|
title={title}
|
||||||
toolbar={<CatalogEntityDrawerMenu entity={entity} key={entity.getId()} />}
|
toolbar={<CatalogEntityDrawerMenu item={item} key={item.getId()} />}
|
||||||
onClose={hideDetails}
|
onClose={hideDetails}
|
||||||
>
|
>
|
||||||
{this.renderContent()}
|
{item && this.renderContent(item)}
|
||||||
</Drawer>
|
</Drawer>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,9 +30,10 @@ import { MenuItem } from "../menu";
|
|||||||
import { ConfirmDialog } from "../confirm-dialog";
|
import { ConfirmDialog } from "../confirm-dialog";
|
||||||
import { HotbarStore } from "../../../common/hotbar-store";
|
import { HotbarStore } from "../../../common/hotbar-store";
|
||||||
import { Icon } from "../icon";
|
import { Icon } from "../icon";
|
||||||
|
import type { CatalogEntityItem } from "./catalog-entity.store";
|
||||||
|
|
||||||
export interface CatalogEntityDrawerMenuProps<T extends CatalogEntity> extends MenuActionsProps {
|
export interface CatalogEntityDrawerMenuProps<T extends CatalogEntity> extends MenuActionsProps {
|
||||||
entity: T | null | undefined;
|
item: CatalogEntityItem<T> | null | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
@ -47,9 +48,9 @@ export class CatalogEntityDrawerMenu<T extends CatalogEntity> extends React.Comp
|
|||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.contextMenu = {
|
this.contextMenu = {
|
||||||
menuItems: [],
|
menuItems: [],
|
||||||
navigate: (url: string) => navigate(url)
|
navigate: (url: string) => navigate(url),
|
||||||
};
|
};
|
||||||
this.props.entity?.onContextMenuOpen(this.contextMenu);
|
this.props.item?.onContextMenuOpen(this.contextMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
onMenuItemClick(menuItem: CatalogEntityContextMenu) {
|
onMenuItemClick(menuItem: CatalogEntityContextMenu) {
|
||||||
@ -107,19 +108,19 @@ export class CatalogEntityDrawerMenu<T extends CatalogEntity> extends React.Comp
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (!this.contextMenu) {
|
const { className, item: entity, ...menuProps } = this.props;
|
||||||
|
|
||||||
|
if (!this.contextMenu || !entity.enabled) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { className, entity, ...menuProps } = this.props;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MenuActions
|
<MenuActions
|
||||||
className={cssNames("CatalogEntityDrawerMenu", className)}
|
className={cssNames("CatalogEntityDrawerMenu", className)}
|
||||||
toolbar
|
toolbar
|
||||||
{...menuProps}
|
{...menuProps}
|
||||||
>
|
>
|
||||||
{this.getMenuItems(entity)}
|
{this.getMenuItems(entity.entity)}
|
||||||
</MenuActions>
|
</MenuActions>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,13 +25,17 @@ import type { CatalogEntity, CatalogEntityActionContext } from "../../api/catalo
|
|||||||
import { ItemObject, ItemStore } from "../../item.store";
|
import { ItemObject, ItemStore } from "../../item.store";
|
||||||
import { CatalogCategory, catalogCategoryRegistry } from "../../../common/catalog";
|
import { CatalogCategory, catalogCategoryRegistry } from "../../../common/catalog";
|
||||||
import { autoBind } from "../../../common/utils";
|
import { autoBind } from "../../../common/utils";
|
||||||
export class CatalogEntityItem implements ItemObject {
|
export class CatalogEntityItem<T extends CatalogEntity> implements ItemObject {
|
||||||
constructor(public entity: CatalogEntity) {}
|
constructor(public entity: T) {}
|
||||||
|
|
||||||
get kind() {
|
get kind() {
|
||||||
return this.entity.kind;
|
return this.entity.kind;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get apiVersion() {
|
||||||
|
return this.entity.apiVersion;
|
||||||
|
}
|
||||||
|
|
||||||
get name() {
|
get name() {
|
||||||
return this.entity.metadata.name;
|
return this.entity.metadata.name;
|
||||||
}
|
}
|
||||||
@ -52,6 +56,10 @@ export class CatalogEntityItem implements ItemObject {
|
|||||||
return this.entity.status.phase;
|
return this.entity.status.phase;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get enabled() {
|
||||||
|
return this.entity.status.enabled ?? true;
|
||||||
|
}
|
||||||
|
|
||||||
get labels() {
|
get labels() {
|
||||||
const labels: string[] = [];
|
const labels: string[] = [];
|
||||||
|
|
||||||
@ -73,6 +81,7 @@ export class CatalogEntityItem implements ItemObject {
|
|||||||
this.name,
|
this.name,
|
||||||
this.id,
|
this.id,
|
||||||
this.phase,
|
this.phase,
|
||||||
|
`source=${this.source}`,
|
||||||
...this.labels.map((value, key) => `${key}=${value}`)
|
...this.labels.map((value, key) => `${key}=${value}`)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -87,7 +96,7 @@ export class CatalogEntityItem implements ItemObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CatalogEntityStore extends ItemStore<CatalogEntityItem> {
|
export class CatalogEntityStore extends ItemStore<CatalogEntityItem<CatalogEntity>> {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
@ -95,6 +104,7 @@ export class CatalogEntityStore extends ItemStore<CatalogEntityItem> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@observable activeCategory?: CatalogCategory;
|
@observable activeCategory?: CatalogCategory;
|
||||||
|
@observable selectedItemId?: string;
|
||||||
|
|
||||||
@computed get entities() {
|
@computed get entities() {
|
||||||
if (!this.activeCategory) {
|
if (!this.activeCategory) {
|
||||||
@ -104,6 +114,10 @@ export class CatalogEntityStore extends ItemStore<CatalogEntityItem> {
|
|||||||
return catalogEntityRegistry.getItemsForCategory(this.activeCategory).map(entity => new CatalogEntityItem(entity));
|
return catalogEntityRegistry.getItemsForCategory(this.activeCategory).map(entity => new CatalogEntityItem(entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@computed get selectedItem() {
|
||||||
|
return this.entities.find(e => e.getId() === this.selectedItemId);
|
||||||
|
}
|
||||||
|
|
||||||
watch() {
|
watch() {
|
||||||
const disposers: IReactionDisposer[] = [
|
const disposers: IReactionDisposer[] = [
|
||||||
reaction(() => this.entities, () => this.loadAll()),
|
reaction(() => this.entities, () => this.loadAll()),
|
||||||
|
|||||||
@ -23,10 +23,10 @@
|
|||||||
max-width: 40px;
|
max-width: 40px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
.MuiAvatar-root {
|
.iconCell > div * {
|
||||||
font-size: var(--unit);
|
font-size: var(--unit);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.nameCell {
|
.nameCell {
|
||||||
@ -40,11 +40,11 @@
|
|||||||
max-width: 100px;
|
max-width: 100px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.connected {
|
.connected, .available {
|
||||||
color: var(--colorSuccess);
|
color: var(--colorSuccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
.disconnected {
|
.disconnected, .deleting, .unavailable {
|
||||||
color: var(--halfGray);
|
color: var(--halfGray);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -32,7 +32,7 @@ import type { CatalogEntityContextMenu, CatalogEntityContextMenuContext } from "
|
|||||||
import { Badge } from "../badge";
|
import { Badge } from "../badge";
|
||||||
import { HotbarStore } from "../../../common/hotbar-store";
|
import { HotbarStore } from "../../../common/hotbar-store";
|
||||||
import { ConfirmDialog } from "../confirm-dialog";
|
import { ConfirmDialog } from "../confirm-dialog";
|
||||||
import { catalogCategoryRegistry } from "../../../common/catalog";
|
import { catalogCategoryRegistry, CatalogEntity } from "../../../common/catalog";
|
||||||
import { CatalogAddButton } from "./catalog-add-button";
|
import { CatalogAddButton } from "./catalog-add-button";
|
||||||
import type { RouteComponentProps } from "react-router";
|
import type { RouteComponentProps } from "react-router";
|
||||||
import { Notifications } from "../notifications";
|
import { Notifications } from "../notifications";
|
||||||
@ -59,7 +59,6 @@ export class Catalog extends React.Component<Props> {
|
|||||||
@observable private catalogEntityStore?: CatalogEntityStore;
|
@observable private catalogEntityStore?: CatalogEntityStore;
|
||||||
@observable private contextMenu: CatalogEntityContextMenuContext;
|
@observable private contextMenu: CatalogEntityContextMenuContext;
|
||||||
@observable activeTab?: string;
|
@observable activeTab?: string;
|
||||||
@observable selectedItem?: CatalogEntityItem;
|
|
||||||
|
|
||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
super(props);
|
super(props);
|
||||||
@ -79,7 +78,7 @@ export class Catalog extends React.Component<Props> {
|
|||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
this.contextMenu = {
|
this.contextMenu = {
|
||||||
menuItems: observable.array([]),
|
menuItems: observable.array([]),
|
||||||
navigate: (url: string) => navigate(url)
|
navigate: (url: string) => navigate(url),
|
||||||
};
|
};
|
||||||
this.catalogEntityStore = new CatalogEntityStore();
|
this.catalogEntityStore = new CatalogEntityStore();
|
||||||
disposeOnUnmount(this, [
|
disposeOnUnmount(this, [
|
||||||
@ -103,13 +102,13 @@ export class Catalog extends React.Component<Props> {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
addToHotbar(item: CatalogEntityItem): void {
|
addToHotbar(item: CatalogEntityItem<CatalogEntity>): void {
|
||||||
HotbarStore.getInstance().addToHotbar(item.entity);
|
HotbarStore.getInstance().addToHotbar(item.entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
onDetails(item: CatalogEntityItem) {
|
onDetails = (item: CatalogEntityItem<CatalogEntity>) => {
|
||||||
this.selectedItem = item;
|
this.catalogEntityStore.selectedItemId = item.getId();
|
||||||
}
|
};
|
||||||
|
|
||||||
onMenuItemClick(menuItem: CatalogEntityContextMenu) {
|
onMenuItemClick(menuItem: CatalogEntityContextMenu) {
|
||||||
if (menuItem.confirm) {
|
if (menuItem.confirm) {
|
||||||
@ -144,7 +143,7 @@ export class Catalog extends React.Component<Props> {
|
|||||||
return <CatalogMenu activeItem={this.activeTab} onItemClick={this.onTabChange}/>;
|
return <CatalogMenu activeItem={this.activeTab} onItemClick={this.onTabChange}/>;
|
||||||
}
|
}
|
||||||
|
|
||||||
renderItemMenu = (item: CatalogEntityItem) => {
|
renderItemMenu = (item: CatalogEntityItem<CatalogEntity>) => {
|
||||||
const onOpen = () => {
|
const onOpen = () => {
|
||||||
this.contextMenu.menuItems = [];
|
this.contextMenu.menuItems = [];
|
||||||
|
|
||||||
@ -167,7 +166,7 @@ export class Catalog extends React.Component<Props> {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
renderIcon(item: CatalogEntityItem) {
|
renderIcon(item: CatalogEntityItem<CatalogEntity>) {
|
||||||
return (
|
return (
|
||||||
<HotbarIcon
|
<HotbarIcon
|
||||||
uid={item.getId()}
|
uid={item.getId()}
|
||||||
@ -191,12 +190,12 @@ export class Catalog extends React.Component<Props> {
|
|||||||
store={this.catalogEntityStore}
|
store={this.catalogEntityStore}
|
||||||
tableId="catalog-items"
|
tableId="catalog-items"
|
||||||
sortingCallbacks={{
|
sortingCallbacks={{
|
||||||
[sortBy.name]: (item: CatalogEntityItem) => item.name,
|
[sortBy.name]: (item: CatalogEntityItem<CatalogEntity>) => item.name,
|
||||||
[sortBy.source]: (item: CatalogEntityItem) => item.source,
|
[sortBy.source]: (item: CatalogEntityItem<CatalogEntity>) => item.source,
|
||||||
[sortBy.status]: (item: CatalogEntityItem) => item.phase,
|
[sortBy.status]: (item: CatalogEntityItem<CatalogEntity>) => item.phase,
|
||||||
}}
|
}}
|
||||||
searchFilters={[
|
searchFilters={[
|
||||||
(entity: CatalogEntityItem) => entity.searchFields,
|
(entity: CatalogEntityItem<CatalogEntity>) => entity.searchFields,
|
||||||
]}
|
]}
|
||||||
renderTableHeader={[
|
renderTableHeader={[
|
||||||
{ title: "", className: css.iconCell },
|
{ title: "", className: css.iconCell },
|
||||||
@ -205,14 +204,17 @@ export class Catalog extends React.Component<Props> {
|
|||||||
{ title: "Labels", className: css.labelsCell },
|
{ title: "Labels", className: css.labelsCell },
|
||||||
{ title: "Status", className: css.statusCell, sortBy: sortBy.status },
|
{ title: "Status", className: css.statusCell, sortBy: sortBy.status },
|
||||||
]}
|
]}
|
||||||
renderTableContents={(item: CatalogEntityItem) => [
|
customizeTableRowProps={(item: CatalogEntityItem<CatalogEntity>) => ({
|
||||||
|
disabled: !item.enabled,
|
||||||
|
})}
|
||||||
|
renderTableContents={(item: CatalogEntityItem<CatalogEntity>) => [
|
||||||
this.renderIcon(item),
|
this.renderIcon(item),
|
||||||
item.name,
|
item.name,
|
||||||
item.source,
|
item.source,
|
||||||
item.labels.map((label) => <Badge className={css.badge} key={label} label={label} title={label} />),
|
item.labels.map((label) => <Badge className={css.badge} key={label} label={label} title={label} />),
|
||||||
{ title: item.phase, className: cssNames(css[item.phase]) }
|
{ title: item.phase, className: cssNames(css[item.phase]) }
|
||||||
]}
|
]}
|
||||||
onDetails={(item: CatalogEntityItem) => this.onDetails(item) }
|
onDetails={this.onDetails}
|
||||||
renderItemMenu={this.renderItemMenu}
|
renderItemMenu={this.renderItemMenu}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@ -227,13 +229,13 @@ export class Catalog extends React.Component<Props> {
|
|||||||
store={this.catalogEntityStore}
|
store={this.catalogEntityStore}
|
||||||
tableId="catalog-items"
|
tableId="catalog-items"
|
||||||
sortingCallbacks={{
|
sortingCallbacks={{
|
||||||
[sortBy.name]: (item: CatalogEntityItem) => item.name,
|
[sortBy.name]: (item: CatalogEntityItem<CatalogEntity>) => item.name,
|
||||||
[sortBy.kind]: (item: CatalogEntityItem) => item.kind,
|
[sortBy.kind]: (item: CatalogEntityItem<CatalogEntity>) => item.kind,
|
||||||
[sortBy.source]: (item: CatalogEntityItem) => item.source,
|
[sortBy.source]: (item: CatalogEntityItem<CatalogEntity>) => item.source,
|
||||||
[sortBy.status]: (item: CatalogEntityItem) => item.phase,
|
[sortBy.status]: (item: CatalogEntityItem<CatalogEntity>) => item.phase,
|
||||||
}}
|
}}
|
||||||
searchFilters={[
|
searchFilters={[
|
||||||
(entity: CatalogEntityItem) => entity.searchFields,
|
(entity: CatalogEntityItem<CatalogEntity>) => entity.searchFields,
|
||||||
]}
|
]}
|
||||||
renderTableHeader={[
|
renderTableHeader={[
|
||||||
{ title: "", className: css.iconCell },
|
{ title: "", className: css.iconCell },
|
||||||
@ -243,7 +245,10 @@ export class Catalog extends React.Component<Props> {
|
|||||||
{ title: "Labels", className: css.labelsCell },
|
{ title: "Labels", className: css.labelsCell },
|
||||||
{ title: "Status", className: css.statusCell, sortBy: sortBy.status },
|
{ title: "Status", className: css.statusCell, sortBy: sortBy.status },
|
||||||
]}
|
]}
|
||||||
renderTableContents={(item: CatalogEntityItem) => [
|
customizeTableRowProps={(item: CatalogEntityItem<CatalogEntity>) => ({
|
||||||
|
disabled: !item.enabled,
|
||||||
|
})}
|
||||||
|
renderTableContents={(item: CatalogEntityItem<CatalogEntity>) => [
|
||||||
this.renderIcon(item),
|
this.renderIcon(item),
|
||||||
item.name,
|
item.name,
|
||||||
item.kind,
|
item.kind,
|
||||||
@ -251,8 +256,8 @@ export class Catalog extends React.Component<Props> {
|
|||||||
item.labels.map((label) => <Badge className={css.badge} key={label} label={label} title={label} />),
|
item.labels.map((label) => <Badge className={css.badge} key={label} label={label} title={label} />),
|
||||||
{ title: item.phase, className: cssNames(css[item.phase]) }
|
{ title: item.phase, className: cssNames(css[item.phase]) }
|
||||||
]}
|
]}
|
||||||
detailsItem={this.selectedItem}
|
detailsItem={this.catalogEntityStore.selectedItem}
|
||||||
onDetails={(item: CatalogEntityItem) => this.onDetails(item) }
|
onDetails={this.onDetails}
|
||||||
renderItemMenu={this.renderItemMenu}
|
renderItemMenu={this.renderItemMenu}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@ -268,15 +273,18 @@ export class Catalog extends React.Component<Props> {
|
|||||||
<div className="p-6 h-full">
|
<div className="p-6 h-full">
|
||||||
{ this.catalogEntityStore.activeCategory ? this.renderSingleCategoryList() : this.renderAllCategoriesList() }
|
{ this.catalogEntityStore.activeCategory ? this.renderSingleCategoryList() : this.renderAllCategoriesList() }
|
||||||
</div>
|
</div>
|
||||||
{ !this.selectedItem && (
|
{
|
||||||
<CatalogAddButton category={this.catalogEntityStore.activeCategory} />
|
this.catalogEntityStore.selectedItem
|
||||||
)}
|
? (
|
||||||
{ this.selectedItem && (
|
<CatalogEntityDetails
|
||||||
<CatalogEntityDetails
|
item={this.catalogEntityStore.selectedItem}
|
||||||
entity={this.selectedItem.entity}
|
hideDetails={() => this.catalogEntityStore.selectedItemId = null}
|
||||||
hideDetails={() => this.selectedItem = null}
|
/>
|
||||||
/>
|
)
|
||||||
)}
|
: (
|
||||||
|
<CatalogAddButton category = {this.catalogEntityStore.activeCategory} />
|
||||||
|
)
|
||||||
|
}
|
||||||
</MainLayout>
|
</MainLayout>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -112,7 +112,7 @@ export class NamespaceStore extends KubeObjectStore<Namespace> {
|
|||||||
protected async loadItems(params: KubeObjectStoreLoadingParams) {
|
protected async loadItems(params: KubeObjectStoreLoadingParams) {
|
||||||
const { allowedNamespaces } = this;
|
const { allowedNamespaces } = this;
|
||||||
|
|
||||||
let namespaces = (await super.loadItems(params)) || [];
|
let namespaces = await super.loadItems(params).catch(() => []);
|
||||||
|
|
||||||
namespaces = namespaces.filter(namespace => allowedNamespaces.includes(namespace.getName()));
|
namespaces = namespaces.filter(namespace => allowedNamespaces.includes(namespace.getName()));
|
||||||
|
|
||||||
|
|||||||
@ -91,17 +91,15 @@ export class RoleBindingDialog extends React.Component<Props> {
|
|||||||
const serviceAccounts = Array.from(this.selectedAccounts, sa => ({
|
const serviceAccounts = Array.from(this.selectedAccounts, sa => ({
|
||||||
name: sa.getName(),
|
name: sa.getName(),
|
||||||
kind: "ServiceAccount" as const,
|
kind: "ServiceAccount" as const,
|
||||||
namespace: this.bindingNamespace,
|
namespace: sa.getNs(),
|
||||||
}));
|
}));
|
||||||
const users = Array.from(this.selectedUsers, user => ({
|
const users = Array.from(this.selectedUsers, user => ({
|
||||||
name: user,
|
name: user,
|
||||||
kind: "User" as const,
|
kind: "User" as const
|
||||||
namespace: this.bindingNamespace,
|
|
||||||
}));
|
}));
|
||||||
const groups = Array.from(this.selectedGroups, group => ({
|
const groups = Array.from(this.selectedGroups, group => ({
|
||||||
name: group,
|
name: group,
|
||||||
kind: "Group" as const,
|
kind: "Group" as const
|
||||||
namespace: this.bindingNamespace,
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|||||||
102
src/renderer/components/catalog-entities/weblink-add-command.tsx
Normal file
102
src/renderer/components/catalog-entities/weblink-add-command.tsx
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 OpenLens Authors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React from "react";
|
||||||
|
import { observer } from "mobx-react";
|
||||||
|
import { CommandOverlay } from "../command-palette";
|
||||||
|
import { Input } from "../input";
|
||||||
|
import { isUrl } from "../input/input_validators";
|
||||||
|
import { WeblinkStore } from "../../../common/weblink-store";
|
||||||
|
import { computed, makeObservable, observable } from "mobx";
|
||||||
|
|
||||||
|
@observer
|
||||||
|
export class WeblinkAddCommand extends React.Component {
|
||||||
|
@observable url = "";
|
||||||
|
@observable nameHidden = true;
|
||||||
|
@observable dirty = false;
|
||||||
|
|
||||||
|
constructor(props: {}) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
makeObservable(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
onChangeUrl(url: string) {
|
||||||
|
this.dirty = true;
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
onSubmitUrl(url: string) {
|
||||||
|
this.dirty = true;
|
||||||
|
this.url = url;
|
||||||
|
this.nameHidden = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
onSubmit(name: string) {
|
||||||
|
WeblinkStore.getInstance().add({
|
||||||
|
name: name || this.url,
|
||||||
|
url: this.url
|
||||||
|
});
|
||||||
|
|
||||||
|
CommandOverlay.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@computed get showValidation() {
|
||||||
|
return this.url?.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Input
|
||||||
|
placeholder="Link URL"
|
||||||
|
autoFocus={this.nameHidden}
|
||||||
|
theme="round-black"
|
||||||
|
data-test-id="command-palette-weblink-add-url"
|
||||||
|
validators={[isUrl]}
|
||||||
|
dirty={this.dirty}
|
||||||
|
value={this.url}
|
||||||
|
onChange={(v) => this.onChangeUrl(v)}
|
||||||
|
onSubmit={(v) => this.onSubmitUrl(v)}
|
||||||
|
showValidationLine={true} />
|
||||||
|
{ this.nameHidden && (
|
||||||
|
<small className="hint">
|
||||||
|
Please provide a web link URL (Press "Enter" to continue or "Escape" to cancel)
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
{ !this.nameHidden && (
|
||||||
|
<>
|
||||||
|
<Input
|
||||||
|
placeholder="Name (optional)"
|
||||||
|
autoFocus={true}
|
||||||
|
theme="round-black"
|
||||||
|
data-test-id="command-palette-weblink-add-name"
|
||||||
|
onSubmit={(v) => this.onSubmit(v)}
|
||||||
|
dirty={true}/>
|
||||||
|
<small className="hint">
|
||||||
|
Please provide a name for the web link (Press "Enter" to confirm or "Escape" to cancel)
|
||||||
|
</small>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -35,6 +35,10 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|
||||||
|
> * {
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.HotbarMenu {
|
.HotbarMenu {
|
||||||
|
|||||||
@ -54,7 +54,7 @@ export class HotbarEntityIcon extends React.Component<Props> {
|
|||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.contextMenu = {
|
this.contextMenu = {
|
||||||
menuItems: [],
|
menuItems: [],
|
||||||
navigate: (url: string) => navigate(url)
|
navigate: (url: string) => navigate(url),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -65,7 +65,7 @@ function onMenuItemClick(menuItem: CatalogEntityContextMenu) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const HotbarIcon = observer(({menuItems = [], size = 40, ...props}: HotbarIconProps) => {
|
export const HotbarIcon = observer(({menuItems = [], size = 40, ...props}: HotbarIconProps) => {
|
||||||
const { uid, title, src, material, active, className, source, disabled, onMenuOpen, children, ...rest } = props;
|
const { uid, title, src, material, active, className, source, disabled, onMenuOpen, onClick, children, ...rest } = props;
|
||||||
const id = `hotbarIcon-${uid}`;
|
const id = `hotbarIcon-${uid}`;
|
||||||
const [menuOpen, setMenuOpen] = useState(false);
|
const [menuOpen, setMenuOpen] = useState(false);
|
||||||
|
|
||||||
@ -83,6 +83,11 @@ export const HotbarIcon = observer(({menuItems = [], size = 40, ...props}: Hotba
|
|||||||
width={size}
|
width={size}
|
||||||
height={size}
|
height={size}
|
||||||
src={src}
|
src={src}
|
||||||
|
onClick={(event) => {
|
||||||
|
if (!disabled) {
|
||||||
|
onClick?.(event);
|
||||||
|
}
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{material && <Icon className="materialIcon" material={material}/>}
|
{material && <Icon className="materialIcon" material={material}/>}
|
||||||
</Avatar>
|
</Avatar>
|
||||||
@ -105,8 +110,10 @@ export const HotbarIcon = observer(({menuItems = [], size = 40, ...props}: Hotba
|
|||||||
toggleEvent="contextmenu"
|
toggleEvent="contextmenu"
|
||||||
position={{right: true, bottom: true }} // FIXME: position does not work
|
position={{right: true, bottom: true }} // FIXME: position does not work
|
||||||
open={() => {
|
open={() => {
|
||||||
onMenuOpen?.();
|
if (!disabled) {
|
||||||
toggleMenu();
|
onMenuOpen?.();
|
||||||
|
toggleMenu();
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
close={() => toggleMenu()}>
|
close={() => toggleMenu()}>
|
||||||
{ menuItems.map((menuItem) => {
|
{ menuItems.map((menuItem) => {
|
||||||
|
|||||||
@ -261,7 +261,7 @@ export class Input extends React.Component<InputProps, State> {
|
|||||||
|
|
||||||
switch (evt.key) {
|
switch (evt.key) {
|
||||||
case "Enter":
|
case "Enter":
|
||||||
if (this.props.onSubmit && !modified && !evt.repeat && this.isValid) {
|
if (this.props.onSubmit && !modified && !evt.repeat && this.isValid()) {
|
||||||
this.props.onSubmit(this.getValue(), evt);
|
this.props.onSubmit(this.getValue(), evt);
|
||||||
|
|
||||||
if (this.isUncontrolled) {
|
if (this.isUncontrolled) {
|
||||||
|
|||||||
33
src/renderer/initializers/catalog.tsx
Normal file
33
src/renderer/initializers/catalog.tsx
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 OpenLens Authors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React from "react";
|
||||||
|
import { WebLinkCategory } from "../../common/catalog-entities";
|
||||||
|
import { WeblinkAddCommand } from "../components/catalog-entities/weblink-add-command";
|
||||||
|
import { CommandOverlay } from "../components/command-palette";
|
||||||
|
|
||||||
|
function initWebLinks() {
|
||||||
|
WebLinkCategory.onAdd = () => CommandOverlay.open(<WeblinkAddCommand />);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function initCatalog() {
|
||||||
|
initWebLinks();
|
||||||
|
}
|
||||||
@ -26,4 +26,6 @@ export * from "./kube-object-menu-registry";
|
|||||||
export * from "./registries";
|
export * from "./registries";
|
||||||
export * from "./welcome-menu-registry";
|
export * from "./welcome-menu-registry";
|
||||||
export * from "./workloads-overview-detail-registry";
|
export * from "./workloads-overview-detail-registry";
|
||||||
|
export * from "./catalog";
|
||||||
|
export * from "./stores";
|
||||||
export * from "./ipc";
|
export * from "./ipc";
|
||||||
|
|||||||
50
src/renderer/initializers/stores.ts
Normal file
50
src/renderer/initializers/stores.ts
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 OpenLens Authors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { HotbarStore } from "../../common/hotbar-store";
|
||||||
|
import { ClusterStore } from "../../common/cluster-store";
|
||||||
|
import { UserStore } from "../../common/user-store";
|
||||||
|
import { ExtensionsStore } from "../../extensions/extensions-store";
|
||||||
|
import { FilesystemProvisionerStore } from "../../main/extension-filesystem";
|
||||||
|
|
||||||
|
import { ThemeStore } from "../theme.store";
|
||||||
|
import { WeblinkStore } from "../../common/weblink-store";
|
||||||
|
|
||||||
|
export async function initStores() {
|
||||||
|
const userStore = UserStore.createInstance();
|
||||||
|
const clusterStore = ClusterStore.createInstance();
|
||||||
|
const extensionsStore = ExtensionsStore.createInstance();
|
||||||
|
const filesystemStore = FilesystemProvisionerStore.createInstance();
|
||||||
|
const themeStore = ThemeStore.createInstance();
|
||||||
|
const hotbarStore = HotbarStore.createInstance();
|
||||||
|
const weblinkStore = WeblinkStore.createInstance();
|
||||||
|
|
||||||
|
// preload common stores
|
||||||
|
await Promise.all([
|
||||||
|
userStore.load(),
|
||||||
|
hotbarStore.load(),
|
||||||
|
clusterStore.load(),
|
||||||
|
extensionsStore.load(),
|
||||||
|
filesystemStore.load(),
|
||||||
|
themeStore.init(),
|
||||||
|
weblinkStore.load()
|
||||||
|
]);
|
||||||
|
}
|
||||||
@ -25,7 +25,6 @@ import { areArgsUpdateAvailableFromMain, UpdateAvailableChannel, onCorrect, Upda
|
|||||||
import { Notifications, notificationsStore } from "../components/notifications";
|
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 { invalidKubeconfigHandler } from "./invalid-kubeconfig-handler";
|
|
||||||
import { ClusterStore } from "../../common/cluster-store";
|
import { ClusterStore } from "../../common/cluster-store";
|
||||||
import { navigate } from "../navigation";
|
import { navigate } from "../navigation";
|
||||||
import { entitySettingsURL } from "../../common/routes";
|
import { entitySettingsURL } from "../../common/routes";
|
||||||
@ -87,7 +86,7 @@ function ListNamespacesForbiddenHandler(event: IpcRendererEvent, ...[clusterId]:
|
|||||||
|
|
||||||
if (!wasDisplayed || (now - lastDisplayedAt) > intervalBetweenNotifications) {
|
if (!wasDisplayed || (now - lastDisplayedAt) > intervalBetweenNotifications) {
|
||||||
listNamespacesForbiddenHandlerDisplayedAt.set(clusterId, now);
|
listNamespacesForbiddenHandlerDisplayedAt.set(clusterId, now);
|
||||||
} else {
|
} else {
|
||||||
// don't bother the user too often
|
// don't bother the user too often
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -100,7 +99,7 @@ function ListNamespacesForbiddenHandler(event: IpcRendererEvent, ...[clusterId]:
|
|||||||
<b>Add Accessible Namespaces</b>
|
<b>Add Accessible Namespaces</b>
|
||||||
<p>Cluster <b>{ClusterStore.getInstance().getById(clusterId).name}</b> does not have permissions to list namespaces. Please add the namespaces you have access to.</p>
|
<p>Cluster <b>{ClusterStore.getInstance().getById(clusterId).name}</b> does not have permissions to list namespaces. Please add the namespaces you have access to.</p>
|
||||||
<div className="flex gaps row align-left box grow">
|
<div className="flex gaps row align-left box grow">
|
||||||
<Button active outlined label="Go to Accessible Namespaces Settings" onClick={()=> {
|
<Button active outlined label="Go to Accessible Namespaces Settings" onClick={() => {
|
||||||
navigate(entitySettingsURL({ params: { entityId: clusterId }, fragment: "accessible-namespaces" }));
|
navigate(entitySettingsURL({ params: { entityId: clusterId }, fragment: "accessible-namespaces" }));
|
||||||
notificationsStore.remove(notificationId);
|
notificationsStore.remove(notificationId);
|
||||||
}} />
|
}} />
|
||||||
@ -120,7 +119,6 @@ export function registerIpcHandlers() {
|
|||||||
listener: UpdateAvailableHandler,
|
listener: UpdateAvailableHandler,
|
||||||
verifier: areArgsUpdateAvailableFromMain,
|
verifier: areArgsUpdateAvailableFromMain,
|
||||||
});
|
});
|
||||||
onCorrect(invalidKubeconfigHandler);
|
|
||||||
onCorrect({
|
onCorrect({
|
||||||
source: ipcRenderer,
|
source: ipcRenderer,
|
||||||
channel: ClusterListNamespaceForbiddenChannel,
|
channel: ClusterListNamespaceForbiddenChannel,
|
||||||
|
|||||||
@ -1,66 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2021 OpenLens Authors
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
|
||||||
* the Software without restriction, including without limitation the rights to
|
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
||||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
||||||
* subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
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";
|
|
||||||
import { productName } from "../../common/vars";
|
|
||||||
|
|
||||||
export const invalidKubeconfigHandler = {
|
|
||||||
source: ipcRenderer,
|
|
||||||
channel: InvalidKubeconfigChannel,
|
|
||||||
listener: InvalidKubeconfigListener,
|
|
||||||
verifier: (args: [unknown]): args is InvalidKubeConfigArgs => {
|
|
||||||
return args.length === 1 && typeof args[0] === "string" && !!ClusterStore.getInstance().getById(args[0]);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
function InvalidKubeconfigListener(event: IpcRendererEvent, ...[clusterId]: InvalidKubeConfigArgs): void {
|
|
||||||
const notificationId = `invalid-kubeconfig:${clusterId}`;
|
|
||||||
const cluster = ClusterStore.getInstance().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 {productName}
|
|
||||||
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.getInstance().removeById(clusterId);
|
|
||||||
notificationsStore.remove(notificationId);
|
|
||||||
}} />
|
|
||||||
<Button active outlined label="Cancel" onClick={() => notificationsStore.remove(notificationId)} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
{
|
|
||||||
id: notificationId,
|
|
||||||
timeout: 0
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@ -280,7 +280,7 @@ export abstract class KubeObjectStore<T extends KubeObject = any> extends ItemSt
|
|||||||
|
|
||||||
async update(item: T, data: Partial<T>): Promise<T> {
|
async update(item: T, data: Partial<T>): Promise<T> {
|
||||||
const newItem = await item.update<T>(data);
|
const newItem = await item.update<T>(data);
|
||||||
|
|
||||||
ensureObjectSelfLink(this.api, newItem);
|
ensureObjectSelfLink(this.api, newItem);
|
||||||
|
|
||||||
const index = this.items.findIndex(item => item.getId() === newItem.getId());
|
const index = this.items.findIndex(item => item.getId() === newItem.getId());
|
||||||
@ -332,6 +332,10 @@ export abstract class KubeObjectStore<T extends KubeObject = any> extends ItemSt
|
|||||||
}
|
}
|
||||||
|
|
||||||
private watchNamespace(namespace: string, abortController: AbortController) {
|
private watchNamespace(namespace: string, abortController: AbortController) {
|
||||||
|
if (!this.api.getResourceVersion(namespace)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let timedRetry: NodeJS.Timeout;
|
let timedRetry: NodeJS.Timeout;
|
||||||
const watch = () => this.api.watch({
|
const watch = () => this.api.watch({
|
||||||
namespace,
|
namespace,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user