mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Merge branch 'master' into preferences-redesign
This commit is contained in:
commit
987be6c52e
19
Makefile
19
Makefile
@ -1,3 +1,8 @@
|
|||||||
|
CMD_ARGS = $(filter-out $@,$(MAKECMDGOALS))
|
||||||
|
|
||||||
|
%:
|
||||||
|
@:
|
||||||
|
|
||||||
EXTENSIONS_DIR = ./extensions
|
EXTENSIONS_DIR = ./extensions
|
||||||
extensions = $(foreach dir, $(wildcard $(EXTENSIONS_DIR)/*), ${dir})
|
extensions = $(foreach dir, $(wildcard $(EXTENSIONS_DIR)/*), ${dir})
|
||||||
extension_node_modules = $(foreach dir, $(wildcard $(EXTENSIONS_DIR)/*), ${dir}/node_modules)
|
extension_node_modules = $(foreach dir, $(wildcard $(EXTENSIONS_DIR)/*), ${dir}/node_modules)
|
||||||
@ -16,16 +21,16 @@ node_modules: yarn.lock
|
|||||||
yarn install --frozen-lockfile
|
yarn install --frozen-lockfile
|
||||||
yarn check --verify-tree --integrity
|
yarn check --verify-tree --integrity
|
||||||
|
|
||||||
static/build/LensDev.html:
|
static/build/LensDev.html: node_modules
|
||||||
yarn compile:renderer
|
yarn compile:renderer
|
||||||
|
|
||||||
.PHONY: compile-dev
|
.PHONY: compile-dev
|
||||||
compile-dev:
|
compile-dev: node_modules
|
||||||
yarn compile:main --cache
|
yarn compile:main --cache
|
||||||
yarn compile:renderer --cache
|
yarn compile:renderer --cache
|
||||||
|
|
||||||
.PHONY: dev
|
.PHONY: dev
|
||||||
dev: node_modules binaries/client build-extensions static/build/LensDev.html
|
dev: binaries/client build-extensions static/build/LensDev.html
|
||||||
yarn dev
|
yarn dev
|
||||||
|
|
||||||
.PHONY: lint
|
.PHONY: lint
|
||||||
@ -34,7 +39,7 @@ lint:
|
|||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: binaries/client
|
test: binaries/client
|
||||||
yarn test
|
yarn run jest $(or $(CMD_ARGS), "src")
|
||||||
|
|
||||||
.PHONY: integration-linux
|
.PHONY: integration-linux
|
||||||
integration-linux: binaries/client build-extension-types build-extensions
|
integration-linux: binaries/client build-extension-types build-extensions
|
||||||
@ -58,10 +63,6 @@ integration-win: binaries/client build-extension-types build-extensions
|
|||||||
yarn build:win
|
yarn build:win
|
||||||
yarn integration
|
yarn integration
|
||||||
|
|
||||||
.PHONY: test-app
|
|
||||||
test-app:
|
|
||||||
yarn test
|
|
||||||
|
|
||||||
.PHONY: build
|
.PHONY: build
|
||||||
build: node_modules binaries/client build-extensions
|
build: node_modules binaries/client build-extensions
|
||||||
ifeq "$(DETECTED_OS)" "Windows"
|
ifeq "$(DETECTED_OS)" "Windows"
|
||||||
@ -77,7 +78,7 @@ $(extension_dists): src/extensions/npm/extensions/dist
|
|||||||
cd $(@:/dist=) && npm run build
|
cd $(@:/dist=) && npm run build
|
||||||
|
|
||||||
.PHONY: build-extensions
|
.PHONY: build-extensions
|
||||||
build-extensions: $(extension_node_modules) $(extension_dists)
|
build-extensions: node_modules $(extension_node_modules) $(extension_dists)
|
||||||
|
|
||||||
.PHONY: test-extensions
|
.PHONY: test-extensions
|
||||||
test-extensions: $(extension_node_modules)
|
test-extensions: $(extension_node_modules)
|
||||||
|
|||||||
9
SECURITY.md
Normal file
9
SECURITY.md
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# Security Policy
|
||||||
|
|
||||||
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
|
Team Lens encourages users who become aware of a security vulnerability in Lens to contact Team Lens with details of the vulnerability. Team Lens has established an email address that should be used for reporting a vulnerability. Please send descriptions of any vulnerabilities found to security@k8slens.dev. Please include details on the software and hardware configuration of your system so that we can duplicate the issue being reported.
|
||||||
|
|
||||||
|
Team Lens hopes that users encountering a new vulnerability will contact us privately as it is in the best interests of our users that Team Lens has an opportunity to investigate and confirm a suspected vulnerability before it becomes public knowledge.
|
||||||
|
|
||||||
|
In the case of vulnerabilities found in third-party software components used in Lens, please also notify Team Lens as described above.
|
||||||
@ -1,9 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* @jest-environment node
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Cluster tests are run if there is a pre-existing minikube cluster. Before running cluster tests the TEST_NAMESPACE
|
||||||
|
namespace is removed, if it exists, from the minikube cluster. Resources are created as part of the cluster tests in the
|
||||||
|
TEST_NAMESPACE namespace. This is done to minimize destructive impact of the cluster tests on an existing minikube
|
||||||
|
cluster and vice versa.
|
||||||
|
*/
|
||||||
import { Application } from "spectron";
|
import { Application } from "spectron";
|
||||||
import * as utils from "../helpers/utils";
|
import * as utils from "../helpers/utils";
|
||||||
import { listHelmRepositories } from "../helpers/utils";
|
import { listHelmRepositories } from "../helpers/utils";
|
||||||
import { fail } from "assert";
|
import { fail } from "assert";
|
||||||
|
|
||||||
|
|
||||||
jest.setTimeout(60000);
|
jest.setTimeout(60000);
|
||||||
|
|
||||||
// FIXME (!): improve / simplify all css-selectors + use [data-test-id="some-id"] (already used in some tests below)
|
// FIXME (!): improve / simplify all css-selectors + use [data-test-id="some-id"] (already used in some tests below)
|
||||||
@ -11,9 +20,11 @@ describe("Lens integration tests", () => {
|
|||||||
let app: Application;
|
let app: Application;
|
||||||
|
|
||||||
describe("app start", () => {
|
describe("app start", () => {
|
||||||
beforeAll(async () => app = await utils.appStart(), 20000);
|
utils.beforeAllWrapped(async () => {
|
||||||
|
app = await utils.appStart();
|
||||||
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
utils.afterAllWrapped(async () => {
|
||||||
if (app?.isRunning()) {
|
if (app?.isRunning()) {
|
||||||
await utils.tearDown(app);
|
await utils.tearDown(app);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,10 +33,12 @@ describe("Lens cluster pages", () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
describe("cluster add", () => {
|
describe("cluster add", () => {
|
||||||
beforeAll(async () => app = await utils.appStart(), 20000);
|
utils.beforeAllWrapped(async () => {
|
||||||
|
app = await utils.appStart();
|
||||||
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
utils.afterAllWrapped(async () => {
|
||||||
if (app && app.isRunning()) {
|
if (app?.isRunning()) {
|
||||||
return utils.tearDown(app);
|
return utils.tearDown(app);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -64,11 +66,10 @@ describe("Lens cluster pages", () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe("cluster pages", () => {
|
describe("cluster pages", () => {
|
||||||
|
utils.beforeAllWrapped(appStartAddCluster);
|
||||||
|
|
||||||
beforeAll(appStartAddCluster, 40000);
|
utils.afterAllWrapped(async () => {
|
||||||
|
if (app?.isRunning()) {
|
||||||
afterAll(async () => {
|
|
||||||
if (app && app.isRunning()) {
|
|
||||||
return utils.tearDown(app);
|
return utils.tearDown(app);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -355,10 +356,10 @@ describe("Lens cluster pages", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("viewing pod logs", () => {
|
describe("viewing pod logs", () => {
|
||||||
beforeEach(appStartAddCluster, 40000);
|
utils.beforeEachWrapped(appStartAddCluster);
|
||||||
|
|
||||||
afterEach(async () => {
|
utils.afterEachWrapped(async () => {
|
||||||
if (app && app.isRunning()) {
|
if (app?.isRunning()) {
|
||||||
return utils.tearDown(app);
|
return utils.tearDown(app);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -405,10 +406,10 @@ describe("Lens cluster pages", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("cluster operations", () => {
|
describe("cluster operations", () => {
|
||||||
beforeEach(appStartAddCluster, 40000);
|
utils.beforeEachWrapped(appStartAddCluster);
|
||||||
|
|
||||||
afterEach(async () => {
|
utils.afterEachWrapped(async () => {
|
||||||
if (app && app.isRunning()) {
|
if (app?.isRunning()) {
|
||||||
return utils.tearDown(app);
|
return utils.tearDown(app);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -7,9 +7,11 @@ describe("Lens command palette", () => {
|
|||||||
let app: Application;
|
let app: Application;
|
||||||
|
|
||||||
describe("menu", () => {
|
describe("menu", () => {
|
||||||
beforeAll(async () => app = await utils.appStart(), 20000);
|
utils.beforeAllWrapped(async () => {
|
||||||
|
app = await utils.appStart();
|
||||||
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
utils.afterAllWrapped(async () => {
|
||||||
if (app?.isRunning()) {
|
if (app?.isRunning()) {
|
||||||
await utils.tearDown(app);
|
await utils.tearDown(app);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,13 +13,13 @@ describe("Lens integration tests", () => {
|
|||||||
const ready = minikubeReady("workspace-int-tests");
|
const ready = minikubeReady("workspace-int-tests");
|
||||||
|
|
||||||
utils.describeIf(ready)("workspaces", () => {
|
utils.describeIf(ready)("workspaces", () => {
|
||||||
beforeAll(async () => {
|
utils.beforeAllWrapped(async () => {
|
||||||
app = await utils.appStart();
|
app = await utils.appStart();
|
||||||
await utils.clickWhatsNew(app);
|
await utils.clickWhatsNew(app);
|
||||||
}, 20000);
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
utils.afterAllWrapped(async () => {
|
||||||
if (app && app.isRunning()) {
|
if (app?.isRunning()) {
|
||||||
return utils.tearDown(app);
|
return utils.tearDown(app);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -8,6 +8,39 @@ const AppPaths: Partial<Record<NodeJS.Platform, string>> = {
|
|||||||
"darwin": "./dist/mac/Lens.app/Contents/MacOS/Lens",
|
"darwin": "./dist/mac/Lens.app/Contents/MacOS/Lens",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface DoneCallback {
|
||||||
|
(...args: any[]): any;
|
||||||
|
fail(error?: string | { message: string }): any;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is necessary because Jest doesn't do this correctly.
|
||||||
|
* @param fn The function to call
|
||||||
|
*/
|
||||||
|
export function wrapJestLifecycle(fn: () => Promise<void>): (done: DoneCallback) => void {
|
||||||
|
return function (done: DoneCallback) {
|
||||||
|
fn()
|
||||||
|
.then(() => done())
|
||||||
|
.catch(error => done.fail(error));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function beforeAllWrapped(fn: () => Promise<void>): void {
|
||||||
|
beforeAll(wrapJestLifecycle(fn));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function beforeEachWrapped(fn: () => Promise<void>): void {
|
||||||
|
beforeEach(wrapJestLifecycle(fn));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function afterAllWrapped(fn: () => Promise<void>): void {
|
||||||
|
afterAll(wrapJestLifecycle(fn));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function afterEachWrapped(fn: () => Promise<void>): void {
|
||||||
|
afterEach(wrapJestLifecycle(fn));
|
||||||
|
}
|
||||||
|
|
||||||
export function itIf(condition: boolean) {
|
export function itIf(condition: boolean) {
|
||||||
return condition ? it : it.skip;
|
return condition ? it : it.skip;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"name": "kontena-lens",
|
"name": "kontena-lens",
|
||||||
"productName": "Lens",
|
"productName": "Lens",
|
||||||
"description": "Lens - The Kubernetes IDE",
|
"description": "Lens - The Kubernetes IDE",
|
||||||
"version": "4.2.0-rc.2",
|
"version": "4.2.0-rc.3",
|
||||||
"main": "static/build/main.js",
|
"main": "static/build/main.js",
|
||||||
"copyright": "© 2021, Mirantis, Inc.",
|
"copyright": "© 2021, Mirantis, Inc.",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@ -26,7 +26,6 @@
|
|||||||
"build:linux": "yarn run compile && electron-builder --linux --dir -c.productName=Lens",
|
"build:linux": "yarn run compile && electron-builder --linux --dir -c.productName=Lens",
|
||||||
"build:mac": "yarn run compile && electron-builder --mac --dir -c.productName=Lens",
|
"build:mac": "yarn run compile && electron-builder --mac --dir -c.productName=Lens",
|
||||||
"build:win": "yarn run compile && electron-builder --win --dir -c.productName=Lens",
|
"build:win": "yarn run compile && electron-builder --win --dir -c.productName=Lens",
|
||||||
"test": "scripts/test.sh",
|
|
||||||
"integration": "jest --runInBand integration",
|
"integration": "jest --runInBand integration",
|
||||||
"dist": "yarn run compile && electron-builder --publish onTag",
|
"dist": "yarn run compile && electron-builder --publish onTag",
|
||||||
"dist:win": "yarn run compile && electron-builder --publish onTag --x64 --ia32",
|
"dist:win": "yarn run compile && electron-builder --publish onTag --x64 --ia32",
|
||||||
@ -36,7 +35,7 @@
|
|||||||
"download:kubectl": "yarn run ts-node build/download_kubectl.ts",
|
"download:kubectl": "yarn run ts-node build/download_kubectl.ts",
|
||||||
"download:helm": "yarn run ts-node build/download_helm.ts",
|
"download:helm": "yarn run ts-node build/download_helm.ts",
|
||||||
"build:tray-icons": "yarn run ts-node build/build_tray_icon.ts",
|
"build:tray-icons": "yarn run ts-node build/build_tray_icon.ts",
|
||||||
"lint": "yarn run eslint $@ --ext js,ts,tsx --max-warnings=0 .",
|
"lint": "yarn run eslint --ext js,ts,tsx --max-warnings=0 .",
|
||||||
"lint:fix": "yarn run lint --fix",
|
"lint:fix": "yarn run lint --fix",
|
||||||
"mkdocs-serve-local": "docker build -t mkdocs-serve-local:latest mkdocs/ && docker run --rm -it -p 8000:8000 -v ${PWD}:/docs mkdocs-serve-local:latest",
|
"mkdocs-serve-local": "docker build -t mkdocs-serve-local:latest mkdocs/ && docker run --rm -it -p 8000:8000 -v ${PWD}:/docs mkdocs-serve-local:latest",
|
||||||
"verify-docs": "docker build -t mkdocs-serve-local:latest mkdocs/ && docker run --rm -v ${PWD}:/docs mkdocs-serve-local:latest build --strict",
|
"verify-docs": "docker build -t mkdocs-serve-local:latest mkdocs/ && docker run --rm -v ${PWD}:/docs mkdocs-serve-local:latest build --strict",
|
||||||
@ -52,7 +51,6 @@
|
|||||||
"jest": {
|
"jest": {
|
||||||
"collectCoverage": false,
|
"collectCoverage": false,
|
||||||
"verbose": true,
|
"verbose": true,
|
||||||
"testEnvironment": "node",
|
|
||||||
"transform": {
|
"transform": {
|
||||||
"^.+\\.tsx?$": "ts-jest"
|
"^.+\\.tsx?$": "ts-jest"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
jest --env=jsdom ${1:-src}
|
|
||||||
@ -35,7 +35,8 @@ jest.mock("electron", () => {
|
|||||||
app: {
|
app: {
|
||||||
getVersion: () => "99.99.99",
|
getVersion: () => "99.99.99",
|
||||||
getPath: () => "tmp",
|
getPath: () => "tmp",
|
||||||
getLocale: () => "en"
|
getLocale: () => "en",
|
||||||
|
setLoginItemSettings: jest.fn(),
|
||||||
},
|
},
|
||||||
ipcMain: {
|
ipcMain: {
|
||||||
handle: jest.fn(),
|
handle: jest.fn(),
|
||||||
@ -99,7 +100,7 @@ describe("empty config", () => {
|
|||||||
|
|
||||||
it("removes cluster from store", async () => {
|
it("removes cluster from store", async () => {
|
||||||
await clusterStore.removeById("foo");
|
await clusterStore.removeById("foo");
|
||||||
expect(clusterStore.getById("foo")).toBeUndefined();
|
expect(clusterStore.getById("foo")).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("sets active cluster", () => {
|
it("sets active cluster", () => {
|
||||||
@ -248,7 +249,7 @@ describe("config with existing clusters", () => {
|
|||||||
expect(storedCluster).toBeTruthy();
|
expect(storedCluster).toBeTruthy();
|
||||||
const storedCluster2 = clusterStore.getById("cluster2");
|
const storedCluster2 = clusterStore.getById("cluster2");
|
||||||
|
|
||||||
expect(storedCluster2).toBeUndefined();
|
expect(storedCluster2).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("allows getting all of the clusters", async () => {
|
it("allows getting all of the clusters", async () => {
|
||||||
|
|||||||
@ -1,7 +1,3 @@
|
|||||||
/**
|
|
||||||
* @jest-environment jsdom
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { SearchStore } from "../search-store";
|
import { SearchStore } from "../search-store";
|
||||||
|
|
||||||
let searchStore: SearchStore = null;
|
let searchStore: SearchStore = null;
|
||||||
|
|||||||
@ -1,3 +1,7 @@
|
|||||||
|
import { Console } from "console";
|
||||||
|
|
||||||
|
console = new Console(process.stdout, process.stderr);
|
||||||
|
|
||||||
import mockFs from "mock-fs";
|
import mockFs from "mock-fs";
|
||||||
|
|
||||||
jest.mock("electron", () => {
|
jest.mock("electron", () => {
|
||||||
@ -5,7 +9,8 @@ jest.mock("electron", () => {
|
|||||||
app: {
|
app: {
|
||||||
getVersion: () => "99.99.99",
|
getVersion: () => "99.99.99",
|
||||||
getPath: () => "tmp",
|
getPath: () => "tmp",
|
||||||
getLocale: () => "en"
|
getLocale: () => "en",
|
||||||
|
setLoginItemSettings: jest.fn(),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@ -5,7 +5,8 @@ jest.mock("electron", () => {
|
|||||||
app: {
|
app: {
|
||||||
getVersion: () => "99.99.99",
|
getVersion: () => "99.99.99",
|
||||||
getPath: () => "tmp",
|
getPath: () => "tmp",
|
||||||
getLocale: () => "en"
|
getLocale: () => "en",
|
||||||
|
setLoginItemSettings: jest.fn(),
|
||||||
},
|
},
|
||||||
ipcMain: {
|
ipcMain: {
|
||||||
handle: jest.fn(),
|
handle: jest.fn(),
|
||||||
|
|||||||
@ -19,7 +19,7 @@ export interface BaseStoreParams<T = any> extends ConfOptions<T> {
|
|||||||
* Note: T should only contain base JSON serializable types.
|
* Note: T should only contain base JSON serializable types.
|
||||||
*/
|
*/
|
||||||
export abstract class BaseStore<T = any> extends Singleton {
|
export abstract class BaseStore<T = any> extends Singleton {
|
||||||
protected storeConfig: Config<T>;
|
protected storeConfig?: Config<T>;
|
||||||
protected syncDisposers: Function[] = [];
|
protected syncDisposers: Function[] = [];
|
||||||
|
|
||||||
whenLoaded = when(() => this.isLoaded);
|
whenLoaded = when(() => this.isLoaded);
|
||||||
@ -36,7 +36,7 @@ export abstract class BaseStore<T = any> extends Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get name() {
|
get name() {
|
||||||
return path.basename(this.storeConfig.path);
|
return path.basename(this.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected get syncRendererChannel() {
|
protected get syncRendererChannel() {
|
||||||
@ -48,7 +48,7 @@ export abstract class BaseStore<T = any> extends Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get path() {
|
get path() {
|
||||||
return this.storeConfig.path;
|
return this.storeConfig?.path || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async init() {
|
protected async init() {
|
||||||
@ -82,10 +82,13 @@ export abstract class BaseStore<T = any> extends Singleton {
|
|||||||
|
|
||||||
protected async saveToFile(model: T) {
|
protected async saveToFile(model: T) {
|
||||||
logger.info(`[STORE]: SAVING ${this.path}`);
|
logger.info(`[STORE]: SAVING ${this.path}`);
|
||||||
|
|
||||||
// todo: update when fixed https://github.com/sindresorhus/conf/issues/114
|
// todo: update when fixed https://github.com/sindresorhus/conf/issues/114
|
||||||
Object.entries(model).forEach(([key, value]) => {
|
if (this.storeConfig) {
|
||||||
this.storeConfig.set(key, value);
|
for (const [key, value] of Object.entries(model)) {
|
||||||
});
|
this.storeConfig.set(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enableSync() {
|
enableSync() {
|
||||||
|
|||||||
@ -218,8 +218,12 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
setActive(id: ClusterId) {
|
setActive(clusterId: ClusterId) {
|
||||||
const clusterId = this.clusters.has(id) ? id : null;
|
const cluster = this.clusters.get(clusterId);
|
||||||
|
|
||||||
|
if (!cluster?.enabled) {
|
||||||
|
clusterId = null;
|
||||||
|
}
|
||||||
|
|
||||||
this.activeCluster = clusterId;
|
this.activeCluster = clusterId;
|
||||||
workspaceStore.setLastActiveClusterId(clusterId);
|
workspaceStore.setLastActiveClusterId(clusterId);
|
||||||
@ -251,8 +255,8 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
|||||||
return this.clusters.size > 0;
|
return this.clusters.size > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
getById(id: ClusterId): Cluster {
|
getById(id: ClusterId): Cluster | null {
|
||||||
return this.clusters.get(id);
|
return this.clusters.get(id) ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
getByWorkspaceId(workspaceId: string): Cluster[] {
|
getByWorkspaceId(workspaceId: string): Cluster[] {
|
||||||
|
|||||||
@ -25,7 +25,7 @@ export class ClusterStore extends Singleton {
|
|||||||
* Set active cluster id
|
* Set active cluster id
|
||||||
*/
|
*/
|
||||||
set activeClusterId(id : ClusterId) {
|
set activeClusterId(id : ClusterId) {
|
||||||
internalClusterStore.activeCluster = id;
|
internalClusterStore.setActive(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,12 +38,8 @@ export class ClusterStore extends Singleton {
|
|||||||
/**
|
/**
|
||||||
* Get active cluster (a cluster which is currently visible)
|
* Get active cluster (a cluster which is currently visible)
|
||||||
*/
|
*/
|
||||||
get activeCluster(): Cluster {
|
get activeCluster(): Cluster | null {
|
||||||
if (!this.activeClusterId) {
|
return internalClusterStore.active;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.getById(this.activeClusterId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -104,7 +100,7 @@ export class ClusterStore extends Singleton {
|
|||||||
* @param model cluster
|
* @param model cluster
|
||||||
*/
|
*/
|
||||||
async removeCluster(model: ClusterModel) {
|
async removeCluster(model: ClusterModel) {
|
||||||
return this.removeById(model.id);
|
return internalClusterStore.removeById(model.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -4,3 +4,7 @@ fetchMock.enableMocks();
|
|||||||
|
|
||||||
// Mock __non_webpack_require__ for tests
|
// Mock __non_webpack_require__ for tests
|
||||||
globalThis.__non_webpack_require__ = jest.fn();
|
globalThis.__non_webpack_require__ = jest.fn();
|
||||||
|
|
||||||
|
process.on("unhandledRejection", (err) => {
|
||||||
|
fail(err);
|
||||||
|
});
|
||||||
|
|||||||
40
src/main/__test__/router.test.ts
Normal file
40
src/main/__test__/router.test.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import { Router } from "../router";
|
||||||
|
|
||||||
|
const staticRoot = __dirname;
|
||||||
|
|
||||||
|
class TestRouter extends Router {
|
||||||
|
protected resolveStaticRootPath() {
|
||||||
|
return staticRoot;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("Router", () => {
|
||||||
|
it("blocks path traversal attacks", async () => {
|
||||||
|
const router = new TestRouter();
|
||||||
|
const res = {
|
||||||
|
statusCode: 200,
|
||||||
|
end: jest.fn()
|
||||||
|
};
|
||||||
|
|
||||||
|
await router.handleStaticFile("../index.ts", res as any, {} as any, 0);
|
||||||
|
|
||||||
|
expect(res.statusCode).toEqual(404);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("serves files under static root", async () => {
|
||||||
|
const router = new TestRouter();
|
||||||
|
const res = {
|
||||||
|
statusCode: 200,
|
||||||
|
write: jest.fn(),
|
||||||
|
setHeader: jest.fn(),
|
||||||
|
end: jest.fn()
|
||||||
|
};
|
||||||
|
const req = {
|
||||||
|
url: ""
|
||||||
|
};
|
||||||
|
|
||||||
|
await router.handleStaticFile("router.test.ts", res as any, req as any, 0);
|
||||||
|
|
||||||
|
expect(res.statusCode).toEqual(200);
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -28,7 +28,7 @@ export class LensProxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
listen(port = this.port): this {
|
listen(port = this.port): this {
|
||||||
this.proxyServer = this.buildCustomProxy().listen(port);
|
this.proxyServer = this.buildCustomProxy().listen(port, "127.0.0.1");
|
||||||
logger.info(`[LENS-PROXY]: Proxy server has started at ${this.origin}`);
|
logger.info(`[LENS-PROXY]: Proxy server has started at ${this.origin}`);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@ -40,10 +40,16 @@ export interface LensApiRequest<P = any> {
|
|||||||
|
|
||||||
export class Router {
|
export class Router {
|
||||||
protected router: any;
|
protected router: any;
|
||||||
|
protected staticRootPath: string;
|
||||||
|
|
||||||
public constructor() {
|
public constructor() {
|
||||||
this.router = new Call.Router();
|
this.router = new Call.Router();
|
||||||
this.addRoutes();
|
this.addRoutes();
|
||||||
|
this.staticRootPath = this.resolveStaticRootPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected resolveStaticRootPath() {
|
||||||
|
return path.resolve(__static);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async route(cluster: Cluster, req: http.IncomingMessage, res: http.ServerResponse): Promise<boolean> {
|
public async route(cluster: Cluster, req: http.IncomingMessage, res: http.ServerResponse): Promise<boolean> {
|
||||||
@ -102,7 +108,15 @@ export class Router {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async handleStaticFile(filePath: string, res: http.ServerResponse, req: http.IncomingMessage, retryCount = 0) {
|
async handleStaticFile(filePath: string, res: http.ServerResponse, req: http.IncomingMessage, retryCount = 0) {
|
||||||
const asset = path.join(__static, filePath);
|
const asset = path.join(this.staticRootPath, filePath);
|
||||||
|
const normalizedFilePath = path.resolve(asset);
|
||||||
|
|
||||||
|
if (!normalizedFilePath.startsWith(this.staticRootPath)) {
|
||||||
|
res.statusCode = 404;
|
||||||
|
res.end();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const filename = path.basename(req.url);
|
const filename = path.basename(req.url);
|
||||||
|
|||||||
@ -70,7 +70,7 @@ class HelmApiRoute extends LensApi {
|
|||||||
this.respondJson(response, result);
|
this.respondJson(response, result);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.debug(error);
|
logger.debug(error);
|
||||||
this.respondText(response, error);
|
this.respondText(response, error, 422);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ class HelmApiRoute extends LensApi {
|
|||||||
this.respondJson(response, result);
|
this.respondJson(response, result);
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
logger.debug(error);
|
logger.debug(error);
|
||||||
this.respondText(response, error);
|
this.respondText(response, error, 422);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
120
src/main/tray.ts
120
src/main/tray.ts
@ -1,6 +1,6 @@
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import packageInfo from "../../package.json";
|
import packageInfo from "../../package.json";
|
||||||
import { Menu, NativeImage, Tray } from "electron";
|
import { Menu, Tray } from "electron";
|
||||||
import { autorun } from "mobx";
|
import { autorun } from "mobx";
|
||||||
import { showAbout } from "./menu";
|
import { showAbout } from "./menu";
|
||||||
import { checkForUpdates } from "./app-updater";
|
import { checkForUpdates } from "./app-updater";
|
||||||
@ -13,6 +13,8 @@ import logger from "./logger";
|
|||||||
import { isDevelopment, isWindows } from "../common/vars";
|
import { isDevelopment, isWindows } from "../common/vars";
|
||||||
import { exitApp } from "./exit-app";
|
import { exitApp } from "./exit-app";
|
||||||
|
|
||||||
|
const TRAY_LOG_PREFIX = "[TRAY]";
|
||||||
|
|
||||||
// note: instance of Tray should be saved somewhere, otherwise it disappears
|
// note: instance of Tray should be saved somewhere, otherwise it disappears
|
||||||
export let tray: Tray;
|
export let tray: Tray;
|
||||||
|
|
||||||
@ -25,94 +27,92 @@ export function getTrayIcon(): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function initTray(windowManager: WindowManager) {
|
export function initTray(windowManager: WindowManager) {
|
||||||
const dispose = autorun(() => {
|
const icon = getTrayIcon();
|
||||||
try {
|
|
||||||
const menu = createTrayMenu(windowManager);
|
|
||||||
|
|
||||||
buildTray(getTrayIcon(), menu, windowManager);
|
tray = new Tray(icon);
|
||||||
} catch (err) {
|
tray.setToolTip(packageInfo.description);
|
||||||
logger.error(`[TRAY]: building failed: ${err}`);
|
tray.setIgnoreDoubleClickEvents(true);
|
||||||
}
|
|
||||||
});
|
if (isWindows) {
|
||||||
|
tray.on("click", () => {
|
||||||
|
windowManager
|
||||||
|
.ensureMainWindow()
|
||||||
|
.catch(error => logger.error(`${TRAY_LOG_PREFIX}: Failed to open lens`, { error }));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const disposers = [
|
||||||
|
autorun(() => {
|
||||||
|
try {
|
||||||
|
const menu = createTrayMenu(windowManager);
|
||||||
|
|
||||||
|
tray.setContextMenu(menu);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(`${TRAY_LOG_PREFIX}: building failed`, { error });
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
dispose();
|
disposers.forEach(disposer => disposer());
|
||||||
tray?.destroy();
|
tray?.destroy();
|
||||||
tray = null;
|
tray = null;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildTray(icon: string | NativeImage, menu: Menu, windowManager: WindowManager) {
|
|
||||||
if (!tray) {
|
|
||||||
tray = new Tray(icon);
|
|
||||||
tray.setToolTip(packageInfo.description);
|
|
||||||
tray.setIgnoreDoubleClickEvents(true);
|
|
||||||
tray.setImage(icon);
|
|
||||||
tray.setContextMenu(menu);
|
|
||||||
|
|
||||||
if (isWindows) {
|
|
||||||
tray.on("click", () => {
|
|
||||||
windowManager.ensureMainWindow();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return tray;
|
|
||||||
}
|
|
||||||
|
|
||||||
function createTrayMenu(windowManager: WindowManager): Menu {
|
function createTrayMenu(windowManager: WindowManager): Menu {
|
||||||
return Menu.buildFromTemplate([
|
return Menu.buildFromTemplate([
|
||||||
{
|
{
|
||||||
label: "Open Lens",
|
label: "Open Lens",
|
||||||
async click() {
|
click() {
|
||||||
await windowManager.ensureMainWindow();
|
windowManager
|
||||||
|
.ensureMainWindow()
|
||||||
|
.catch(error => logger.error(`${TRAY_LOG_PREFIX}: Failed to open lens`, { error }));
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Preferences",
|
label: "Preferences",
|
||||||
click() {
|
click() {
|
||||||
windowManager.navigate(preferencesURL());
|
windowManager
|
||||||
|
.navigate(preferencesURL())
|
||||||
|
.catch(error => logger.error(`${TRAY_LOG_PREFIX}: Failed to nativate to Preferences`, { error }));
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Clusters",
|
label: "Clusters",
|
||||||
submenu: workspaceStore.enabledWorkspacesList
|
submenu: workspaceStore.enabledWorkspacesList
|
||||||
.filter(workspace => clusterStore.getByWorkspaceId(workspace.id).length > 0) // hide empty workspaces
|
.map(workspace => [workspace, clusterStore.getByWorkspaceId(workspace.id)] as const)
|
||||||
.map(workspace => {
|
.map(([workspace, clusters]) => ({
|
||||||
const clusters = clusterStore.getByWorkspaceId(workspace.id);
|
label: workspace.name,
|
||||||
|
toolTip: workspace.description,
|
||||||
return {
|
enabled: clusters.length > 0,
|
||||||
label: workspace.name,
|
submenu: clusters.map(({ id: clusterId, name: label, online, workspace }) => ({
|
||||||
toolTip: workspace.description,
|
checked: online,
|
||||||
submenu: clusters.map(cluster => {
|
type: "checkbox",
|
||||||
const { id: clusterId, name: label, online, workspace } = cluster;
|
label,
|
||||||
|
toolTip: clusterId,
|
||||||
return {
|
click() {
|
||||||
label: `${online ? "✓" : "\x20".repeat(3)/*offset*/}${label}`,
|
workspaceStore.setActive(workspace);
|
||||||
toolTip: clusterId,
|
windowManager
|
||||||
async click() {
|
.navigate(clusterViewURL({ params: { clusterId } }))
|
||||||
workspaceStore.setActive(workspace);
|
.catch(error => logger.error(`${TRAY_LOG_PREFIX}: Failed to nativate to cluster`, { clusterId, error }));
|
||||||
windowManager.navigate(clusterViewURL({ params: { clusterId } }));
|
}
|
||||||
}
|
}))
|
||||||
};
|
})),
|
||||||
})
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Check for updates",
|
label: "Check for updates",
|
||||||
async click() {
|
click() {
|
||||||
await checkForUpdates();
|
checkForUpdates()
|
||||||
await windowManager.ensureMainWindow();
|
.then(() => windowManager.ensureMainWindow());
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "About Lens",
|
label: "About Lens",
|
||||||
async click() {
|
click() {
|
||||||
// note: argument[1] (browserWindow) not available when app is not focused / hidden
|
windowManager.ensureMainWindow()
|
||||||
const browserWindow = await windowManager.ensureMainWindow();
|
.then(showAbout)
|
||||||
|
.catch(error => logger.error(`${TRAY_LOG_PREFIX}: Failed to show Lens About view`, { error }));
|
||||||
showAbout(browserWindow);
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ type: "separator" },
|
{ type: "separator" },
|
||||||
|
|||||||
@ -1,134 +1,115 @@
|
|||||||
|
jest.mock("../kube-object");
|
||||||
|
jest.mock("../kube-api");
|
||||||
|
jest.mock("../api-manager", () => ({
|
||||||
|
apiManager() {
|
||||||
|
return {
|
||||||
|
registerStore: jest.fn(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
import { IKubeApiParsed, parseKubeApi } from "../kube-api-parse";
|
import { IKubeApiParsed, parseKubeApi } from "../kube-api-parse";
|
||||||
|
|
||||||
interface KubeApiParseTestData {
|
/**
|
||||||
url: string;
|
* [<input-url>, <expected-result>]
|
||||||
expected: Required<IKubeApiParsed>;
|
*/
|
||||||
}
|
type KubeApiParseTestData = [string, Required<IKubeApiParsed>];
|
||||||
|
|
||||||
const tests: KubeApiParseTestData[] = [
|
const tests: KubeApiParseTestData[] = [
|
||||||
{
|
["/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/prometheuses.monitoring.coreos.com", {
|
||||||
url: "/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/prometheuses.monitoring.coreos.com",
|
apiBase: "/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions",
|
||||||
expected: {
|
apiPrefix: "/apis",
|
||||||
apiBase: "/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions",
|
apiGroup: "apiextensions.k8s.io",
|
||||||
apiPrefix: "/apis",
|
apiVersion: "v1beta1",
|
||||||
apiGroup: "apiextensions.k8s.io",
|
apiVersionWithGroup: "apiextensions.k8s.io/v1beta1",
|
||||||
apiVersion: "v1beta1",
|
namespace: undefined,
|
||||||
apiVersionWithGroup: "apiextensions.k8s.io/v1beta1",
|
resource: "customresourcedefinitions",
|
||||||
namespace: undefined,
|
name: "prometheuses.monitoring.coreos.com"
|
||||||
resource: "customresourcedefinitions",
|
}],
|
||||||
name: "prometheuses.monitoring.coreos.com"
|
["/api/v1/namespaces/kube-system/pods/coredns-6955765f44-v8p27", {
|
||||||
},
|
apiBase: "/api/v1/pods",
|
||||||
},
|
apiPrefix: "/api",
|
||||||
{
|
apiGroup: "",
|
||||||
url: "/api/v1/namespaces/kube-system/pods/coredns-6955765f44-v8p27",
|
apiVersion: "v1",
|
||||||
expected: {
|
apiVersionWithGroup: "v1",
|
||||||
apiBase: "/api/v1/pods",
|
namespace: "kube-system",
|
||||||
apiPrefix: "/api",
|
resource: "pods",
|
||||||
apiGroup: "",
|
name: "coredns-6955765f44-v8p27"
|
||||||
apiVersion: "v1",
|
}],
|
||||||
apiVersionWithGroup: "v1",
|
["/apis/stable.example.com/foo1/crontabs", {
|
||||||
namespace: "kube-system",
|
apiBase: "/apis/stable.example.com/foo1/crontabs",
|
||||||
resource: "pods",
|
apiPrefix: "/apis",
|
||||||
name: "coredns-6955765f44-v8p27"
|
apiGroup: "stable.example.com",
|
||||||
},
|
apiVersion: "foo1",
|
||||||
},
|
apiVersionWithGroup: "stable.example.com/foo1",
|
||||||
{
|
resource: "crontabs",
|
||||||
url: "/apis/stable.example.com/foo1/crontabs",
|
name: undefined,
|
||||||
expected: {
|
namespace: undefined,
|
||||||
apiBase: "/apis/stable.example.com/foo1/crontabs",
|
}],
|
||||||
apiPrefix: "/apis",
|
["/apis/cluster.k8s.io/v1alpha1/clusters", {
|
||||||
apiGroup: "stable.example.com",
|
apiBase: "/apis/cluster.k8s.io/v1alpha1/clusters",
|
||||||
apiVersion: "foo1",
|
apiPrefix: "/apis",
|
||||||
apiVersionWithGroup: "stable.example.com/foo1",
|
apiGroup: "cluster.k8s.io",
|
||||||
resource: "crontabs",
|
apiVersion: "v1alpha1",
|
||||||
name: undefined,
|
apiVersionWithGroup: "cluster.k8s.io/v1alpha1",
|
||||||
namespace: undefined,
|
resource: "clusters",
|
||||||
},
|
name: undefined,
|
||||||
},
|
namespace: undefined,
|
||||||
{
|
}],
|
||||||
url: "/apis/cluster.k8s.io/v1alpha1/clusters",
|
["/api/v1/namespaces", {
|
||||||
expected: {
|
apiBase: "/api/v1/namespaces",
|
||||||
apiBase: "/apis/cluster.k8s.io/v1alpha1/clusters",
|
apiPrefix: "/api",
|
||||||
apiPrefix: "/apis",
|
apiGroup: "",
|
||||||
apiGroup: "cluster.k8s.io",
|
apiVersion: "v1",
|
||||||
apiVersion: "v1alpha1",
|
apiVersionWithGroup: "v1",
|
||||||
apiVersionWithGroup: "cluster.k8s.io/v1alpha1",
|
resource: "namespaces",
|
||||||
resource: "clusters",
|
name: undefined,
|
||||||
name: undefined,
|
namespace: undefined,
|
||||||
namespace: undefined,
|
}],
|
||||||
},
|
["/api/v1/secrets", {
|
||||||
},
|
apiBase: "/api/v1/secrets",
|
||||||
{
|
apiPrefix: "/api",
|
||||||
url: "/api/v1/namespaces",
|
apiGroup: "",
|
||||||
expected: {
|
apiVersion: "v1",
|
||||||
apiBase: "/api/v1/namespaces",
|
apiVersionWithGroup: "v1",
|
||||||
apiPrefix: "/api",
|
resource: "secrets",
|
||||||
apiGroup: "",
|
name: undefined,
|
||||||
apiVersion: "v1",
|
namespace: undefined,
|
||||||
apiVersionWithGroup: "v1",
|
}],
|
||||||
resource: "namespaces",
|
["/api/v1/nodes/minikube", {
|
||||||
name: undefined,
|
apiBase: "/api/v1/nodes",
|
||||||
namespace: undefined,
|
apiPrefix: "/api",
|
||||||
},
|
apiGroup: "",
|
||||||
},
|
apiVersion: "v1",
|
||||||
{
|
apiVersionWithGroup: "v1",
|
||||||
url: "/api/v1/secrets",
|
resource: "nodes",
|
||||||
expected: {
|
name: "minikube",
|
||||||
apiBase: "/api/v1/secrets",
|
namespace: undefined,
|
||||||
apiPrefix: "/api",
|
}],
|
||||||
apiGroup: "",
|
["/api/foo-bar/nodes/minikube", {
|
||||||
apiVersion: "v1",
|
apiBase: "/api/foo-bar/nodes",
|
||||||
apiVersionWithGroup: "v1",
|
apiPrefix: "/api",
|
||||||
resource: "secrets",
|
apiGroup: "",
|
||||||
name: undefined,
|
apiVersion: "foo-bar",
|
||||||
namespace: undefined,
|
apiVersionWithGroup: "foo-bar",
|
||||||
},
|
resource: "nodes",
|
||||||
},
|
name: "minikube",
|
||||||
{
|
namespace: undefined,
|
||||||
url: "/api/v1/nodes/minikube",
|
}],
|
||||||
expected: {
|
["/api/v1/namespaces/kube-public", {
|
||||||
apiBase: "/api/v1/nodes",
|
apiBase: "/api/v1/namespaces",
|
||||||
apiPrefix: "/api",
|
apiPrefix: "/api",
|
||||||
apiGroup: "",
|
apiGroup: "",
|
||||||
apiVersion: "v1",
|
apiVersion: "v1",
|
||||||
apiVersionWithGroup: "v1",
|
apiVersionWithGroup: "v1",
|
||||||
resource: "nodes",
|
resource: "namespaces",
|
||||||
name: "minikube",
|
name: "kube-public",
|
||||||
namespace: undefined,
|
namespace: undefined,
|
||||||
},
|
}],
|
||||||
},
|
|
||||||
{
|
|
||||||
url: "/api/foo-bar/nodes/minikube",
|
|
||||||
expected: {
|
|
||||||
apiBase: "/api/foo-bar/nodes",
|
|
||||||
apiPrefix: "/api",
|
|
||||||
apiGroup: "",
|
|
||||||
apiVersion: "foo-bar",
|
|
||||||
apiVersionWithGroup: "foo-bar",
|
|
||||||
resource: "nodes",
|
|
||||||
name: "minikube",
|
|
||||||
namespace: undefined,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
url: "/api/v1/namespaces/kube-public",
|
|
||||||
expected: {
|
|
||||||
apiBase: "/api/v1/namespaces",
|
|
||||||
apiPrefix: "/api",
|
|
||||||
apiGroup: "",
|
|
||||||
apiVersion: "v1",
|
|
||||||
apiVersionWithGroup: "v1",
|
|
||||||
resource: "namespaces",
|
|
||||||
name: "kube-public",
|
|
||||||
namespace: undefined,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
|
|
||||||
describe("parseApi unit tests", () => {
|
describe("parseApi unit tests", () => {
|
||||||
for (const { url, expected } of tests) {
|
it.each(tests)("testing %s", (url, expected) => {
|
||||||
test(`testing "${url}"`, () => {
|
expect(parseKubeApi(url)).toStrictEqual(expected);
|
||||||
expect(parseKubeApi(url)).toStrictEqual(expected);
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|||||||
303
src/renderer/api/__tests__/pods.test.ts
Normal file
303
src/renderer/api/__tests__/pods.test.ts
Normal file
@ -0,0 +1,303 @@
|
|||||||
|
import { Pod } from "../endpoints";
|
||||||
|
|
||||||
|
interface GetDummyPodOptions {
|
||||||
|
running?: number;
|
||||||
|
dead?: number;
|
||||||
|
initRunning?: number;
|
||||||
|
initDead?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDummyPodDefaultOptions(): Required<GetDummyPodOptions> {
|
||||||
|
return {
|
||||||
|
running: 0,
|
||||||
|
dead: 0,
|
||||||
|
initDead: 0,
|
||||||
|
initRunning: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDummyPod(opts: GetDummyPodOptions = getDummyPodDefaultOptions()): Pod {
|
||||||
|
const pod = new Pod({
|
||||||
|
apiVersion: "v1",
|
||||||
|
kind: "Pod",
|
||||||
|
metadata: {
|
||||||
|
uid: "1",
|
||||||
|
name: "test",
|
||||||
|
resourceVersion: "v1",
|
||||||
|
selfLink: "http"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
pod.spec = {
|
||||||
|
containers: [],
|
||||||
|
initContainers: [],
|
||||||
|
serviceAccount: "dummy",
|
||||||
|
serviceAccountName: "dummy",
|
||||||
|
};
|
||||||
|
|
||||||
|
pod.status = {
|
||||||
|
phase: "Running",
|
||||||
|
conditions: [],
|
||||||
|
hostIP: "10.0.0.1",
|
||||||
|
podIP: "10.0.0.1",
|
||||||
|
startTime: "now",
|
||||||
|
containerStatuses: [],
|
||||||
|
initContainerStatuses: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
for (let i = 0; i < opts.running; i += 1) {
|
||||||
|
const name = `container_r_${i}`;
|
||||||
|
|
||||||
|
pod.spec.containers.push({
|
||||||
|
image: "dummy",
|
||||||
|
imagePullPolicy: "dummy",
|
||||||
|
name,
|
||||||
|
});
|
||||||
|
pod.status.containerStatuses.push({
|
||||||
|
image: "dummy",
|
||||||
|
imageID: "dummy",
|
||||||
|
name,
|
||||||
|
ready: true,
|
||||||
|
restartCount: i,
|
||||||
|
state: {
|
||||||
|
running: {
|
||||||
|
startedAt: "before"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < opts.dead; i += 1) {
|
||||||
|
const name = `container_d_${i}`;
|
||||||
|
|
||||||
|
pod.spec.containers.push({
|
||||||
|
image: "dummy",
|
||||||
|
imagePullPolicy: "dummy",
|
||||||
|
name,
|
||||||
|
});
|
||||||
|
pod.status.containerStatuses.push({
|
||||||
|
image: "dummy",
|
||||||
|
imageID: "dummy",
|
||||||
|
name,
|
||||||
|
ready: false,
|
||||||
|
restartCount: i,
|
||||||
|
state: {
|
||||||
|
terminated: {
|
||||||
|
startedAt: "before",
|
||||||
|
exitCode: i+1,
|
||||||
|
finishedAt: "later",
|
||||||
|
reason: `reason_${i}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < opts.initRunning; i += 1) {
|
||||||
|
const name = `container_ir_${i}`;
|
||||||
|
|
||||||
|
pod.spec.initContainers.push({
|
||||||
|
image: "dummy",
|
||||||
|
imagePullPolicy: "dummy",
|
||||||
|
name,
|
||||||
|
});
|
||||||
|
pod.status.initContainerStatuses.push({
|
||||||
|
image: "dummy",
|
||||||
|
imageID: "dummy",
|
||||||
|
name,
|
||||||
|
ready: true,
|
||||||
|
restartCount: i,
|
||||||
|
state: {
|
||||||
|
running: {
|
||||||
|
startedAt: "before"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < opts.initDead; i += 1) {
|
||||||
|
const name = `container_id_${i}`;
|
||||||
|
|
||||||
|
pod.spec.initContainers.push({
|
||||||
|
image: "dummy",
|
||||||
|
imagePullPolicy: "dummy",
|
||||||
|
name,
|
||||||
|
});
|
||||||
|
pod.status.initContainerStatuses.push({
|
||||||
|
image: "dummy",
|
||||||
|
imageID: "dummy",
|
||||||
|
name,
|
||||||
|
ready: false,
|
||||||
|
restartCount: i,
|
||||||
|
state: {
|
||||||
|
terminated: {
|
||||||
|
startedAt: "before",
|
||||||
|
exitCode: i+1,
|
||||||
|
finishedAt: "later",
|
||||||
|
reason: `reason_${i}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return pod;
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("Pods", () => {
|
||||||
|
const podTests = [];
|
||||||
|
|
||||||
|
for (let r = 0; r < 10; r += 1) {
|
||||||
|
for (let d = 0; d < 10; d += 1) {
|
||||||
|
for (let ir = 0; ir < 10; ir += 1) {
|
||||||
|
for (let id = 0; id < 10; id += 1) {
|
||||||
|
podTests.push([r, d, ir, id]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe.each(podTests)("for [%d running, %d dead] & initial [%d running, %d dead]", (running, dead, initRunning, initDead) => {
|
||||||
|
const pod = getDummyPod({ running, dead, initRunning, initDead });
|
||||||
|
|
||||||
|
function getNamedContainer(name: string) {
|
||||||
|
return {
|
||||||
|
image: "dummy",
|
||||||
|
imagePullPolicy: "dummy",
|
||||||
|
name
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
it("getRunningContainers should return only running and init running", () => {
|
||||||
|
const res = [
|
||||||
|
...Array.from(new Array(running), (val, index) => getNamedContainer(`container_r_${index}`)),
|
||||||
|
...Array.from(new Array(initRunning), (val, index) => getNamedContainer(`container_ir_${index}`)),
|
||||||
|
];
|
||||||
|
|
||||||
|
expect(pod.getRunningContainers()).toStrictEqual(res);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("getAllContainers should return all containers", () => {
|
||||||
|
const res = [
|
||||||
|
...Array.from(new Array(running), (val, index) => getNamedContainer(`container_r_${index}`)),
|
||||||
|
...Array.from(new Array(dead), (val, index) => getNamedContainer(`container_d_${index}`)),
|
||||||
|
...Array.from(new Array(initRunning), (val, index) => getNamedContainer(`container_ir_${index}`)),
|
||||||
|
...Array.from(new Array(initDead), (val, index) => getNamedContainer(`container_id_${index}`)),
|
||||||
|
];
|
||||||
|
|
||||||
|
expect(pod.getAllContainers()).toStrictEqual(res);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("getRestartsCount should return total restart counts", () => {
|
||||||
|
function sum(len: number): number {
|
||||||
|
let res = 0;
|
||||||
|
|
||||||
|
for (let i = 0; i < len; i += 1) {
|
||||||
|
res += i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(pod.getRestartsCount()).toStrictEqual(sum(running) + sum(dead));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("hasIssues should return false", () => {
|
||||||
|
expect(pod.hasIssues()).toStrictEqual(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("getSelectedNodeOs", () => {
|
||||||
|
it("should return stable", () => {
|
||||||
|
const pod = getDummyPod();
|
||||||
|
|
||||||
|
pod.spec.nodeSelector = {
|
||||||
|
"kubernetes.io/os": "foobar"
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(pod.getSelectedNodeOs()).toStrictEqual("foobar");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return beta", () => {
|
||||||
|
const pod = getDummyPod();
|
||||||
|
|
||||||
|
pod.spec.nodeSelector = {
|
||||||
|
"beta.kubernetes.io/os": "foobar1"
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(pod.getSelectedNodeOs()).toStrictEqual("foobar1");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return stable over beta", () => {
|
||||||
|
const pod = getDummyPod();
|
||||||
|
|
||||||
|
pod.spec.nodeSelector = {
|
||||||
|
"kubernetes.io/os": "foobar2",
|
||||||
|
"beta.kubernetes.io/os": "foobar3"
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(pod.getSelectedNodeOs()).toStrictEqual("foobar2");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return undefined if none set", () => {
|
||||||
|
const pod = getDummyPod();
|
||||||
|
|
||||||
|
expect(pod.getSelectedNodeOs()).toStrictEqual(undefined);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("hasIssues", () => {
|
||||||
|
it("should return true if a condition isn't ready", () => {
|
||||||
|
const pod = getDummyPod({ running: 1 });
|
||||||
|
|
||||||
|
pod.status.conditions.push({
|
||||||
|
type: "Ready",
|
||||||
|
status: "foobar",
|
||||||
|
lastProbeTime: 1,
|
||||||
|
lastTransitionTime: "longer ago"
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(pod.hasIssues()).toStrictEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return false if a condition is non-ready", () => {
|
||||||
|
const pod = getDummyPod({ running: 1 });
|
||||||
|
|
||||||
|
pod.status.conditions.push({
|
||||||
|
type: "dummy",
|
||||||
|
status: "foobar",
|
||||||
|
lastProbeTime: 1,
|
||||||
|
lastTransitionTime: "longer ago"
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(pod.hasIssues()).toStrictEqual(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return true if a current container is in a crash loop back off", () => {
|
||||||
|
const pod = getDummyPod({ running: 1 });
|
||||||
|
|
||||||
|
pod.status.containerStatuses[0].state = {
|
||||||
|
waiting: {
|
||||||
|
reason: "CrashLookBackOff",
|
||||||
|
message: "too much foobar"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(pod.hasIssues()).toStrictEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return true if a current phase isn't running", () => {
|
||||||
|
const pod = getDummyPod({ running: 1 });
|
||||||
|
|
||||||
|
pod.status.phase = "not running";
|
||||||
|
|
||||||
|
expect(pod.hasIssues()).toStrictEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return false if a current phase is running", () => {
|
||||||
|
const pod = getDummyPod({ running: 1 });
|
||||||
|
|
||||||
|
pod.status.phase = "Running";
|
||||||
|
|
||||||
|
expect(pod.hasIssues()).toStrictEqual(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -270,60 +270,55 @@ export class Pod extends WorkloadKubeObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getAllContainers() {
|
getAllContainers() {
|
||||||
return this.getContainers().concat(this.getInitContainers());
|
return [...this.getContainers(), ...this.getInitContainers()];
|
||||||
}
|
}
|
||||||
|
|
||||||
getRunningContainers() {
|
getRunningContainers() {
|
||||||
const statuses = this.getContainerStatuses();
|
const runningContainerNames = new Set(
|
||||||
|
this.getContainerStatuses()
|
||||||
return this.getAllContainers().filter(container => {
|
.filter(({ state }) => state.running)
|
||||||
return statuses.find(status => status.name === container.name && !!status.state["running"]);
|
.map(({ name }) => name)
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return this.getAllContainers()
|
||||||
|
.filter(({ name }) => runningContainerNames.has(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
getContainerStatuses(includeInitContainers = true) {
|
getContainerStatuses(includeInitContainers = true) {
|
||||||
const statuses: IPodContainerStatus[] = [];
|
const { containerStatuses = [], initContainerStatuses = [] } = this.status ?? {};
|
||||||
const { containerStatuses, initContainerStatuses } = this.status;
|
|
||||||
|
|
||||||
if (containerStatuses) {
|
if (includeInitContainers) {
|
||||||
statuses.push(...containerStatuses);
|
return [...containerStatuses, ...initContainerStatuses];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (includeInitContainers && initContainerStatuses) {
|
return [...containerStatuses];
|
||||||
statuses.push(...initContainerStatuses);
|
|
||||||
}
|
|
||||||
|
|
||||||
return statuses;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getRestartsCount(): number {
|
getRestartsCount(): number {
|
||||||
const { containerStatuses } = this.status;
|
const { containerStatuses = [] } = this.status ?? {};
|
||||||
|
|
||||||
if (!containerStatuses) return 0;
|
return containerStatuses.reduce((totalCount, { restartCount }) => totalCount + restartCount, 0);
|
||||||
|
|
||||||
return containerStatuses.reduce((count, item) => count + item.restartCount, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getQosClass() {
|
getQosClass() {
|
||||||
return this.status.qosClass || "";
|
return this.status?.qosClass || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
getReason() {
|
getReason() {
|
||||||
return this.status.reason || "";
|
return this.status?.reason || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
getPriorityClassName() {
|
getPriorityClassName() {
|
||||||
return this.spec.priorityClassName || "";
|
return this.spec.priorityClassName || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns one of 5 statuses: Running, Succeeded, Pending, Failed, Evicted
|
getStatus(): PodStatus {
|
||||||
getStatus() {
|
|
||||||
const phase = this.getStatusPhase();
|
const phase = this.getStatusPhase();
|
||||||
const reason = this.getReason();
|
const reason = this.getReason();
|
||||||
const goodConditions = ["Initialized", "Ready"].every(condition =>
|
const trueConditionTypes = new Set(this.getConditions()
|
||||||
!!this.getConditions().find(item => item.type === condition && item.status === "True")
|
.filter(({ status }) => status === "True")
|
||||||
);
|
.map(({ type }) => type));
|
||||||
|
const isInGoodCondition = ["Initialized", "Ready"].every(condition => trueConditionTypes.has(condition));
|
||||||
|
|
||||||
if (reason === PodStatus.EVICTED) {
|
if (reason === PodStatus.EVICTED) {
|
||||||
return PodStatus.EVICTED;
|
return PodStatus.EVICTED;
|
||||||
@ -337,7 +332,7 @@ export class Pod extends WorkloadKubeObject {
|
|||||||
return PodStatus.SUCCEEDED;
|
return PodStatus.SUCCEEDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (phase === PodStatus.RUNNING && goodConditions) {
|
if (phase === PodStatus.RUNNING && isInGoodCondition) {
|
||||||
return PodStatus.RUNNING;
|
return PodStatus.RUNNING;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,37 +344,27 @@ export class Pod extends WorkloadKubeObject {
|
|||||||
if (this.getReason() === PodStatus.EVICTED) return "Evicted";
|
if (this.getReason() === PodStatus.EVICTED) return "Evicted";
|
||||||
if (this.getStatus() === PodStatus.RUNNING && this.metadata.deletionTimestamp) return "Terminating";
|
if (this.getStatus() === PodStatus.RUNNING && this.metadata.deletionTimestamp) return "Terminating";
|
||||||
|
|
||||||
let message = "";
|
|
||||||
const statuses = this.getContainerStatuses(false); // not including initContainers
|
const statuses = this.getContainerStatuses(false); // not including initContainers
|
||||||
|
|
||||||
if (statuses.length) {
|
for (const { state } of statuses.reverse()) {
|
||||||
statuses.forEach(status => {
|
if (state.waiting) {
|
||||||
const { state } = status;
|
return state.waiting.reason || "Waiting";
|
||||||
|
}
|
||||||
|
|
||||||
if (state.waiting) {
|
if (state.terminated) {
|
||||||
const { reason } = state.waiting;
|
return state.terminated.reason || "Terminated";
|
||||||
|
}
|
||||||
message = reason ? reason : "Waiting";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state.terminated) {
|
|
||||||
const { reason } = state.terminated;
|
|
||||||
|
|
||||||
message = reason ? reason : "Terminated";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
if (message) return message;
|
|
||||||
|
|
||||||
return this.getStatusPhase();
|
return this.getStatusPhase();
|
||||||
}
|
}
|
||||||
|
|
||||||
getStatusPhase() {
|
getStatusPhase() {
|
||||||
return this.status.phase;
|
return this.status?.phase;
|
||||||
}
|
}
|
||||||
|
|
||||||
getConditions() {
|
getConditions() {
|
||||||
return this.status.conditions || [];
|
return this.status?.conditions || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
getVolumes() {
|
getVolumes() {
|
||||||
@ -393,9 +378,7 @@ export class Pod extends WorkloadKubeObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getNodeSelectors(): string[] {
|
getNodeSelectors(): string[] {
|
||||||
const { nodeSelector } = this.spec;
|
const { nodeSelector = {} } = this.spec;
|
||||||
|
|
||||||
if (!nodeSelector) return [];
|
|
||||||
|
|
||||||
return Object.entries(nodeSelector).map(values => values.join(": "));
|
return Object.entries(nodeSelector).map(values => values.join(": "));
|
||||||
}
|
}
|
||||||
@ -409,20 +392,19 @@ export class Pod extends WorkloadKubeObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hasIssues() {
|
hasIssues() {
|
||||||
const notReady = !!this.getConditions().find(condition => {
|
for (const { type, status } of this.getConditions()) {
|
||||||
return condition.type == "Ready" && condition.status !== "True";
|
if (type === "Ready" && status !== "True") {
|
||||||
});
|
return true;
|
||||||
const crashLoop = !!this.getContainerStatuses().find(condition => {
|
}
|
||||||
const waiting = condition.state.waiting;
|
}
|
||||||
|
|
||||||
return (waiting && waiting.reason == "CrashLoopBackOff");
|
for (const { state } of this.getContainerStatuses()) {
|
||||||
});
|
if (state?.waiting?.reason === "CrashLookBackOff") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return this.getStatusPhase() !== "Running";
|
||||||
notReady ||
|
|
||||||
crashLoop ||
|
|
||||||
this.getStatusPhase() !== "Running"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getLivenessProbe(container: IPodContainer) {
|
getLivenessProbe(container: IPodContainer) {
|
||||||
@ -476,14 +458,11 @@ export class Pod extends WorkloadKubeObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getNodeName() {
|
getNodeName() {
|
||||||
return this.spec?.nodeName;
|
return this.spec.nodeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
getSelectedNodeOs() {
|
getSelectedNodeOs(): string | undefined {
|
||||||
if (!this.spec.nodeSelector) return;
|
return this.spec.nodeSelector?.["kubernetes.io/os"] || this.spec.nodeSelector?.["beta.kubernetes.io/os"];
|
||||||
if (!this.spec.nodeSelector["kubernetes.io/os"] && !this.spec.nodeSelector["beta.kubernetes.io/os"]) return;
|
|
||||||
|
|
||||||
return this.spec.nodeSelector["kubernetes.io/os"] || this.spec.nodeSelector["beta.kubernetes.io/os"];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import { ItemStore } from "../../item.store";
|
|||||||
import { Secret } from "../../api/endpoints";
|
import { Secret } from "../../api/endpoints";
|
||||||
import { secretsStore } from "../+config-secrets/secrets.store";
|
import { secretsStore } from "../+config-secrets/secrets.store";
|
||||||
import { namespaceStore } from "../+namespaces/namespace.store";
|
import { namespaceStore } from "../+namespaces/namespace.store";
|
||||||
|
import { Notifications } from "../notifications";
|
||||||
|
|
||||||
@autobind()
|
@autobind()
|
||||||
export class ReleaseStore extends ItemStore<HelmRelease> {
|
export class ReleaseStore extends ItemStore<HelmRelease> {
|
||||||
@ -67,7 +68,11 @@ export class ReleaseStore extends ItemStore<HelmRelease> {
|
|||||||
this.items.replace(this.sortItems(items));
|
this.items.replace(this.sortItems(items));
|
||||||
this.isLoaded = true;
|
this.isLoaded = true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Loading Helm Chart releases has failed: ${error}`);
|
console.error("Loading Helm Chart releases has failed", error);
|
||||||
|
|
||||||
|
if (error.error) {
|
||||||
|
Notifications.error(error.error);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import { Cluster } from "../../../main/cluster";
|
|||||||
import { clusterStore } from "../../../common/cluster-store";
|
import { clusterStore } from "../../../common/cluster-store";
|
||||||
import { ItemObject, ItemStore } from "../../item.store";
|
import { ItemObject, ItemStore } from "../../item.store";
|
||||||
import { autobind } from "../../utils";
|
import { autobind } from "../../utils";
|
||||||
|
import { computed, reaction } from "mobx";
|
||||||
|
|
||||||
export class ClusterItem implements ItemObject {
|
export class ClusterItem implements ItemObject {
|
||||||
constructor(public cluster: Cluster) {}
|
constructor(public cluster: Cluster) {}
|
||||||
@ -51,15 +52,21 @@ export class WorkspaceClusterStore extends ItemStore<ClusterItem> {
|
|||||||
this.workspaceId = workspaceId;
|
this.workspaceId = workspaceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@computed get clusters(): ClusterItem[] {
|
||||||
|
return clusterStore
|
||||||
|
.getByWorkspaceId(this.workspaceId)
|
||||||
|
.filter(cluster => cluster.enabled)
|
||||||
|
.map(cluster => new ClusterItem(cluster));
|
||||||
|
}
|
||||||
|
|
||||||
|
watch() {
|
||||||
|
return reaction(() => this.clusters, () => this.loadAll(), {
|
||||||
|
fireImmediately: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
loadAll() {
|
loadAll() {
|
||||||
return this.loadItems(
|
return this.loadItems(() => this.clusters);
|
||||||
() => (
|
|
||||||
clusterStore
|
|
||||||
.getByWorkspaceId(this.workspaceId)
|
|
||||||
.filter(cluster => cluster.enabled)
|
|
||||||
.map(cluster => new ClusterItem(cluster))
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async remove(clusterItem: ClusterItem) {
|
async remove(clusterItem: ClusterItem) {
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import "./workspace-overview.scss";
|
import "./workspace-overview.scss";
|
||||||
|
|
||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import { disposeOnUnmount, observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import { ItemListLayout } from "../item-object-list/item-list-layout";
|
import { ItemListLayout } from "../item-object-list/item-list-layout";
|
||||||
import { ClusterItem, WorkspaceClusterStore } from "./workspace-cluster.store";
|
import { ClusterItem, WorkspaceClusterStore } from "./workspace-cluster.store";
|
||||||
import { navigate } from "../../navigation";
|
import { navigate } from "../../navigation";
|
||||||
@ -9,7 +9,7 @@ import { clusterViewURL } from "../cluster-manager/cluster-view.route";
|
|||||||
import { WorkspaceClusterMenu } from "./workspace-cluster-menu";
|
import { WorkspaceClusterMenu } from "./workspace-cluster-menu";
|
||||||
import { kebabCase } from "lodash";
|
import { kebabCase } from "lodash";
|
||||||
import { addClusterURL } from "../+add-cluster";
|
import { addClusterURL } from "../+add-cluster";
|
||||||
import { observable, reaction } from "mobx";
|
import { IReactionDisposer, observable, reaction } from "mobx";
|
||||||
import { workspaceStore } from "../../../common/workspace-store";
|
import { workspaceStore } from "../../../common/workspace-store";
|
||||||
|
|
||||||
enum sortBy {
|
enum sortBy {
|
||||||
@ -23,15 +23,22 @@ enum sortBy {
|
|||||||
export class WorkspaceOverview extends Component {
|
export class WorkspaceOverview extends Component {
|
||||||
@observable private workspaceClusterStore?: WorkspaceClusterStore;
|
@observable private workspaceClusterStore?: WorkspaceClusterStore;
|
||||||
|
|
||||||
|
disposeWorkspaceWatch: IReactionDisposer;
|
||||||
|
disposeClustersWatch: IReactionDisposer;
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
disposeOnUnmount(this, [
|
this.disposeWorkspaceWatch = reaction(() => workspaceStore.currentWorkspaceId, workspaceId => {
|
||||||
reaction(() => workspaceStore.currentWorkspaceId, workspaceId => {
|
this.workspaceClusterStore = new WorkspaceClusterStore(workspaceId);
|
||||||
this.workspaceClusterStore = new WorkspaceClusterStore(workspaceId);
|
this.disposeClustersWatch?.();
|
||||||
this.workspaceClusterStore.loadAll().catch(error => console.log("workspaceClusterStore.loadAll", error));
|
this.disposeClustersWatch = this.workspaceClusterStore.watch();
|
||||||
}, {
|
}, {
|
||||||
fireImmediately: true,
|
fireImmediately: true,
|
||||||
})
|
});
|
||||||
]);
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
this.disposeWorkspaceWatch?.();
|
||||||
|
this.disposeClustersWatch?.();
|
||||||
}
|
}
|
||||||
|
|
||||||
showCluster = ({ clusterId }: ClusterItem) => {
|
showCluster = ({ clusterId }: ClusterItem) => {
|
||||||
|
|||||||
@ -1,7 +1,3 @@
|
|||||||
/**
|
|
||||||
* @jest-environment jsdom
|
|
||||||
*/
|
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import "@testing-library/jest-dom/extend-expect";
|
import "@testing-library/jest-dom/extend-expect";
|
||||||
import { fireEvent, render } from "@testing-library/react";
|
import { fireEvent, render } from "@testing-library/react";
|
||||||
|
|||||||
@ -1,7 +1,3 @@
|
|||||||
/**
|
|
||||||
* @jest-environment jsdom
|
|
||||||
*/
|
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import "@testing-library/jest-dom/extend-expect";
|
import "@testing-library/jest-dom/extend-expect";
|
||||||
import { render } from "@testing-library/react";
|
import { render } from "@testing-library/react";
|
||||||
|
|||||||
@ -1,7 +1,3 @@
|
|||||||
/**
|
|
||||||
* @jest-environment jsdom
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { podsStore } from "../../+workloads-pods/pods.store";
|
import { podsStore } from "../../+workloads-pods/pods.store";
|
||||||
import { Pod } from "../../../api/endpoints";
|
import { Pod } from "../../../api/endpoints";
|
||||||
import { dockStore } from "../dock.store";
|
import { dockStore } from "../dock.store";
|
||||||
|
|||||||
@ -26,7 +26,6 @@ interface SidebarItemProps {
|
|||||||
* this item should be shown as active
|
* this item should be shown as active
|
||||||
*/
|
*/
|
||||||
isActive?: boolean;
|
isActive?: boolean;
|
||||||
subMenus?: React.ReactNode | React.ComponentType<SidebarItemProps>[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
@ -53,11 +52,9 @@ export class SidebarItem extends React.Component<SidebarItemProps> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@computed get isExpandable(): boolean {
|
@computed get isExpandable(): boolean {
|
||||||
if (this.compact) {
|
if (this.compact) return false; // not available in compact-mode currently
|
||||||
return false; // not available currently
|
|
||||||
}
|
|
||||||
|
|
||||||
return Boolean(this.props.subMenus || this.props.children);
|
return Boolean(this.props.children);
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleExpand = () => {
|
toggleExpand = () => {
|
||||||
@ -66,8 +63,22 @@ export class SidebarItem extends React.Component<SidebarItemProps> {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
renderSubMenu() {
|
||||||
|
const { isExpandable, expanded, isActive } = this;
|
||||||
|
|
||||||
|
if (!isExpandable || !expanded) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ul className={cssNames("sub-menu", { active: isActive })}>
|
||||||
|
{this.props.children}
|
||||||
|
</ul>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { isHidden, icon, text, children, url, className, subMenus } = this.props;
|
const { isHidden, icon, text, url, className } = this.props;
|
||||||
|
|
||||||
if (isHidden) return null;
|
if (isHidden) return null;
|
||||||
|
|
||||||
@ -90,12 +101,7 @@ export class SidebarItem extends React.Component<SidebarItemProps> {
|
|||||||
material={expanded ? "keyboard_arrow_up" : "keyboard_arrow_down"}
|
material={expanded ? "keyboard_arrow_up" : "keyboard_arrow_down"}
|
||||||
/>}
|
/>}
|
||||||
</NavLink>
|
</NavLink>
|
||||||
{isExpandable && expanded && (
|
{this.renderSubMenu()}
|
||||||
<ul className={cssNames("sub-menu", { active: isActive })}>
|
|
||||||
{subMenus}
|
|
||||||
{children}
|
|
||||||
</ul>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,25 +51,20 @@ export class Sidebar extends React.Component<Props> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return Object.entries(crdStore.groups).map(([group, crds]) => {
|
return Object.entries(crdStore.groups).map(([group, crds]) => {
|
||||||
const crdGroupSubMenu: React.ReactNode = crds.map((crd) => {
|
const id = `crd-group:${group}`;
|
||||||
return (
|
const crdGroupsPageUrl = crdURL({ query: { groups: group } });
|
||||||
<SidebarItem
|
|
||||||
key={crd.getResourceApiBase()}
|
|
||||||
id={`crd-resource:${crd.getResourceApiBase()}`}
|
|
||||||
url={crd.getResourceUrl()}
|
|
||||||
text={crd.getResourceTitle()}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SidebarItem
|
<SidebarItem key={id} id={id} text={group} url={crdGroupsPageUrl}>
|
||||||
key={group}
|
{crds.map((crd) => (
|
||||||
text={group}
|
<SidebarItem
|
||||||
id={`crd-group:${group}`}
|
key={crd.getResourceApiBase()}
|
||||||
url={crdURL({ query: { groups: group } })}
|
id={`crd-resource:${crd.getResourceApiBase()}`}
|
||||||
subMenus={crdGroupSubMenu}
|
url={crd.getResourceUrl()}
|
||||||
/>
|
text={crd.getResourceTitle()}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</SidebarItem>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -147,8 +142,9 @@ export class Sidebar extends React.Component<Props> {
|
|||||||
isActive={isActive}
|
isActive={isActive}
|
||||||
text={menuItem.title}
|
text={menuItem.title}
|
||||||
icon={<menuItem.components.Icon/>}
|
icon={<menuItem.components.Icon/>}
|
||||||
subMenus={this.renderTreeFromTabRoutes(tabRoutes)}
|
>
|
||||||
/>
|
{this.renderTreeFromTabRoutes(tabRoutes)}
|
||||||
|
</SidebarItem>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -175,88 +171,94 @@ export class Sidebar extends React.Component<Props> {
|
|||||||
<div className={cssNames("sidebar-nav flex column box grow-fixed", { compact })}>
|
<div className={cssNames("sidebar-nav flex column box grow-fixed", { compact })}>
|
||||||
<SidebarItem
|
<SidebarItem
|
||||||
id="cluster"
|
id="cluster"
|
||||||
|
text="Cluster"
|
||||||
isActive={isActiveRoute(clusterRoute)}
|
isActive={isActiveRoute(clusterRoute)}
|
||||||
isHidden={!isAllowedResource("nodes")}
|
isHidden={!isAllowedResource("nodes")}
|
||||||
url={clusterURL()}
|
url={clusterURL()}
|
||||||
text="Cluster"
|
|
||||||
icon={<Icon svg="kube"/>}
|
icon={<Icon svg="kube"/>}
|
||||||
/>
|
/>
|
||||||
<SidebarItem
|
<SidebarItem
|
||||||
id="nodes"
|
id="nodes"
|
||||||
|
text="Nodes"
|
||||||
isActive={isActiveRoute(nodesRoute)}
|
isActive={isActiveRoute(nodesRoute)}
|
||||||
isHidden={!isAllowedResource("nodes")}
|
isHidden={!isAllowedResource("nodes")}
|
||||||
url={nodesURL()}
|
url={nodesURL()}
|
||||||
text="Nodes"
|
|
||||||
icon={<Icon svg="nodes"/>}
|
icon={<Icon svg="nodes"/>}
|
||||||
/>
|
/>
|
||||||
<SidebarItem
|
<SidebarItem
|
||||||
id="workloads"
|
id="workloads"
|
||||||
|
text="Workloads"
|
||||||
isActive={isActiveRoute(workloadsRoute)}
|
isActive={isActiveRoute(workloadsRoute)}
|
||||||
isHidden={Workloads.tabRoutes.length == 0}
|
isHidden={Workloads.tabRoutes.length == 0}
|
||||||
url={workloadsURL({ query })}
|
url={workloadsURL({ query })}
|
||||||
subMenus={this.renderTreeFromTabRoutes(Workloads.tabRoutes)}
|
|
||||||
text="Workloads"
|
|
||||||
icon={<Icon svg="workloads"/>}
|
icon={<Icon svg="workloads"/>}
|
||||||
/>
|
>
|
||||||
|
{this.renderTreeFromTabRoutes(Workloads.tabRoutes)}
|
||||||
|
</SidebarItem>
|
||||||
<SidebarItem
|
<SidebarItem
|
||||||
id="config"
|
id="config"
|
||||||
|
text="Configuration"
|
||||||
isActive={isActiveRoute(configRoute)}
|
isActive={isActiveRoute(configRoute)}
|
||||||
isHidden={Config.tabRoutes.length == 0}
|
isHidden={Config.tabRoutes.length == 0}
|
||||||
url={configURL({ query })}
|
url={configURL({ query })}
|
||||||
subMenus={this.renderTreeFromTabRoutes(Config.tabRoutes)}
|
|
||||||
text="Configuration"
|
|
||||||
icon={<Icon material="list"/>}
|
icon={<Icon material="list"/>}
|
||||||
/>
|
>
|
||||||
|
{this.renderTreeFromTabRoutes(Config.tabRoutes)}
|
||||||
|
</SidebarItem>
|
||||||
<SidebarItem
|
<SidebarItem
|
||||||
id="networks"
|
id="networks"
|
||||||
|
text="Network"
|
||||||
isActive={isActiveRoute(networkRoute)}
|
isActive={isActiveRoute(networkRoute)}
|
||||||
isHidden={Network.tabRoutes.length == 0}
|
isHidden={Network.tabRoutes.length == 0}
|
||||||
url={networkURL({ query })}
|
url={networkURL({ query })}
|
||||||
subMenus={this.renderTreeFromTabRoutes(Network.tabRoutes)}
|
|
||||||
text="Network"
|
|
||||||
icon={<Icon material="device_hub"/>}
|
icon={<Icon material="device_hub"/>}
|
||||||
/>
|
>
|
||||||
|
{this.renderTreeFromTabRoutes(Network.tabRoutes)}
|
||||||
|
</SidebarItem>
|
||||||
<SidebarItem
|
<SidebarItem
|
||||||
id="storage"
|
id="storage"
|
||||||
|
text="Storage"
|
||||||
isActive={isActiveRoute(storageRoute)}
|
isActive={isActiveRoute(storageRoute)}
|
||||||
isHidden={Storage.tabRoutes.length == 0}
|
isHidden={Storage.tabRoutes.length == 0}
|
||||||
url={storageURL({ query })}
|
url={storageURL({ query })}
|
||||||
subMenus={this.renderTreeFromTabRoutes(Storage.tabRoutes)}
|
|
||||||
icon={<Icon svg="storage"/>}
|
icon={<Icon svg="storage"/>}
|
||||||
text="Storage"
|
>
|
||||||
/>
|
{this.renderTreeFromTabRoutes(Storage.tabRoutes)}
|
||||||
|
</SidebarItem>
|
||||||
<SidebarItem
|
<SidebarItem
|
||||||
id="namespaces"
|
id="namespaces"
|
||||||
|
text="Namespaces"
|
||||||
isActive={isActiveRoute(namespacesRoute)}
|
isActive={isActiveRoute(namespacesRoute)}
|
||||||
isHidden={!isAllowedResource("namespaces")}
|
isHidden={!isAllowedResource("namespaces")}
|
||||||
url={namespacesURL()}
|
url={namespacesURL()}
|
||||||
icon={<Icon material="layers"/>}
|
icon={<Icon material="layers"/>}
|
||||||
text="Namespaces"
|
|
||||||
/>
|
/>
|
||||||
<SidebarItem
|
<SidebarItem
|
||||||
id="events"
|
id="events"
|
||||||
|
text="Events"
|
||||||
isActive={isActiveRoute(eventRoute)}
|
isActive={isActiveRoute(eventRoute)}
|
||||||
isHidden={!isAllowedResource("events")}
|
isHidden={!isAllowedResource("events")}
|
||||||
url={eventsURL({ query })}
|
url={eventsURL({ query })}
|
||||||
icon={<Icon material="access_time"/>}
|
icon={<Icon material="access_time"/>}
|
||||||
text="Events"
|
|
||||||
/>
|
/>
|
||||||
<SidebarItem
|
<SidebarItem
|
||||||
id="apps"
|
id="apps"
|
||||||
|
text="Apps" // helm charts
|
||||||
isActive={isActiveRoute(appsRoute)}
|
isActive={isActiveRoute(appsRoute)}
|
||||||
url={appsURL({ query })}
|
url={appsURL({ query })}
|
||||||
subMenus={this.renderTreeFromTabRoutes(Apps.tabRoutes)}
|
|
||||||
icon={<Icon material="apps"/>}
|
icon={<Icon material="apps"/>}
|
||||||
text="Apps"
|
>
|
||||||
/>
|
{this.renderTreeFromTabRoutes(Apps.tabRoutes)}
|
||||||
|
</SidebarItem>
|
||||||
<SidebarItem
|
<SidebarItem
|
||||||
id="users"
|
id="users"
|
||||||
|
text="Access Control"
|
||||||
isActive={isActiveRoute(usersManagementRoute)}
|
isActive={isActiveRoute(usersManagementRoute)}
|
||||||
url={usersManagementURL({ query })}
|
url={usersManagementURL({ query })}
|
||||||
subMenus={this.renderTreeFromTabRoutes(UserManagement.tabRoutes)}
|
|
||||||
icon={<Icon material="security"/>}
|
icon={<Icon material="security"/>}
|
||||||
text="Access Control"
|
>
|
||||||
/>
|
{this.renderTreeFromTabRoutes(UserManagement.tabRoutes)}
|
||||||
|
</SidebarItem>
|
||||||
<SidebarItem
|
<SidebarItem
|
||||||
id="custom-resources"
|
id="custom-resources"
|
||||||
text="Custom Resources"
|
text="Custom Resources"
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Here you can find description of changes we've built into each release. While we try our best to make each upgrade automatic and as smooth as possible, there may be some cases where you might need to do something to ensure the application works smoothly. So please read through the release highlights!
|
Here you can find description of changes we've built into each release. While we try our best to make each upgrade automatic and as smooth as possible, there may be some cases where you might need to do something to ensure the application works smoothly. So please read through the release highlights!
|
||||||
|
|
||||||
## 4.2.0-rc.2 (current version)
|
## 4.2.0-rc.3 (current version)
|
||||||
|
|
||||||
- Add lens:// protocol handling with a routing mechanism
|
- Add lens:// protocol handling with a routing mechanism
|
||||||
- Add common app routes to the protocol renderer router from the documentation
|
- Add common app routes to the protocol renderer router from the documentation
|
||||||
@ -33,6 +33,10 @@ Here you can find description of changes we've built into each release. While we
|
|||||||
- Fix: Closing workspace menu after clicking on iframe
|
- Fix: Closing workspace menu after clicking on iframe
|
||||||
- Fix: extension global pages are never able to be visible
|
- Fix: extension global pages are never able to be visible
|
||||||
- Fix: recreate proxy kubeconfig if it is deleted
|
- Fix: recreate proxy kubeconfig if it is deleted
|
||||||
|
- Fix: Proxy should listen only on loopback device
|
||||||
|
- Fix: Block global path traversal in router
|
||||||
|
- Fix: Set initial cursor position for the editor to beginning
|
||||||
|
- Fix: Highlight sidebar's active section
|
||||||
|
|
||||||
## 4.1.4
|
## 4.1.4
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user