mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Merge branch 'master' into fix/keep_fresh_resource_in_details_view
This commit is contained in:
commit
c27b1f423a
1062 files changed
+15851
-7478
No files matched your search
@@ -8,8 +8,6 @@ import type { GetCustomKubeConfigFilePath } from "../app-paths/get-custom-kube-c
|
||||
import getCustomKubeConfigFilePathInjectable from "../app-paths/get-custom-kube-config-directory/get-custom-kube-config-directory.injectable";
|
||||
import clusterStoreInjectable from "../cluster-store/cluster-store.injectable";
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import type { CreateCluster } from "../cluster/create-cluster-injection-token";
|
||||
import { createClusterInjectionToken } from "../cluster/create-cluster-injection-token";
|
||||
import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
import { getDiForUnitTesting } from "../../main/getDiForUnitTesting";
|
||||
import assert from "assert";
|
||||
@@ -27,6 +25,7 @@ import type { WriteFileSync } from "../fs/write-file-sync.injectable";
|
||||
import writeFileSyncInjectable from "../fs/write-file-sync.injectable";
|
||||
import type { WriteBufferSync } from "../fs/write-buffer-sync.injectable";
|
||||
import writeBufferSyncInjectable from "../fs/write-buffer-sync.injectable";
|
||||
import { Cluster } from "../cluster/cluster";
|
||||
|
||||
// NOTE: this is intended to read the actual file system
|
||||
const testDataIcon = readFileSync("test-data/cluster-store-migration-icon.png");
|
||||
@@ -58,7 +57,6 @@ users:
|
||||
describe("cluster-store", () => {
|
||||
let di: DiContainer;
|
||||
let clusterStore: ClusterStore;
|
||||
let createCluster: CreateCluster;
|
||||
let writeJsonSync: WriteJsonSync;
|
||||
let writeFileSync: WriteFileSync;
|
||||
let writeBufferSync: WriteBufferSync;
|
||||
@@ -67,15 +65,13 @@ describe("cluster-store", () => {
|
||||
let writeFileSyncAndReturnPath: (filePath: string, contents: string) => string;
|
||||
|
||||
beforeEach(async () => {
|
||||
di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
di = getDiForUnitTesting();
|
||||
|
||||
di.override(directoryForUserDataInjectable, () => "/some-directory-for-user-data");
|
||||
di.override(directoryForTempInjectable, () => "/some-temp-directory");
|
||||
di.override(kubectlBinaryNameInjectable, () => "kubectl");
|
||||
di.override(kubectlDownloadingNormalizedArchInjectable, () => "amd64");
|
||||
di.override(normalizedPlatformInjectable, () => "darwin");
|
||||
createCluster = di.inject(createClusterInjectionToken);
|
||||
getCustomKubeConfigFilePath = di.inject(getCustomKubeConfigFilePathInjectable);
|
||||
writeJsonSync = di.inject(writeJsonSyncInjectable);
|
||||
writeFileSync = di.inject(writeFileSyncInjectable);
|
||||
writeBufferSync = di.inject(writeBufferSyncInjectable);
|
||||
@@ -85,6 +81,8 @@ describe("cluster-store", () => {
|
||||
|
||||
describe("empty config", () => {
|
||||
beforeEach(async () => {
|
||||
getCustomKubeConfigFilePath = di.inject(getCustomKubeConfigFilePathInjectable);
|
||||
|
||||
writeJsonSync("/some-directory-for-user-data/lens-cluster-store.json", {});
|
||||
clusterStore = di.inject(clusterStoreInjectable);
|
||||
clusterStore.load();
|
||||
@@ -92,7 +90,7 @@ describe("cluster-store", () => {
|
||||
|
||||
describe("with foo cluster added", () => {
|
||||
beforeEach(() => {
|
||||
const cluster = createCluster({
|
||||
const cluster = new Cluster({
|
||||
id: "foo",
|
||||
contextName: "foo",
|
||||
preferences: {
|
||||
@@ -198,6 +196,9 @@ describe("cluster-store", () => {
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
getCustomKubeConfigFilePath = di.inject(getCustomKubeConfigFilePathInjectable);
|
||||
|
||||
clusterStore = di.inject(clusterStoreInjectable);
|
||||
clusterStore.load();
|
||||
});
|
||||
@@ -249,6 +250,9 @@ describe("cluster-store", () => {
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
getCustomKubeConfigFilePath = di.inject(getCustomKubeConfigFilePathInjectable);
|
||||
|
||||
clusterStore = di.inject(clusterStoreInjectable);
|
||||
clusterStore.load();
|
||||
});
|
||||
@@ -262,6 +266,10 @@ describe("cluster-store", () => {
|
||||
|
||||
describe("pre 3.6.0-beta.1 config with an existing cluster", () => {
|
||||
beforeEach(() => {
|
||||
di.override(storeMigrationVersionInjectable, () => "3.6.0");
|
||||
|
||||
getCustomKubeConfigFilePath = di.inject(getCustomKubeConfigFilePathInjectable);
|
||||
|
||||
writeJsonSync("/some-directory-for-user-data/lens-cluster-store.json", {
|
||||
__internal__: {
|
||||
migrations: {
|
||||
@@ -281,16 +289,15 @@ describe("cluster-store", () => {
|
||||
});
|
||||
writeBufferSync("/some-directory-for-user-data/icon_path", testDataIcon);
|
||||
|
||||
di.override(storeMigrationVersionInjectable, () => "3.6.0");
|
||||
|
||||
clusterStore = di.inject(clusterStoreInjectable);
|
||||
clusterStore.load();
|
||||
});
|
||||
|
||||
it("migrates to modern format with kubeconfig in a file", async () => {
|
||||
const config = clusterStore.clustersList[0].kubeConfigPath;
|
||||
const configPath = clusterStore.clustersList[0].kubeConfigPath.get();
|
||||
|
||||
expect(readFileSync(config)).toBe(minimalValidKubeConfig);
|
||||
expect(readFileSync(configPath)).toBe(minimalValidKubeConfig);
|
||||
});
|
||||
|
||||
it("migrates to modern format with icon not in file", async () => {
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import kubectlApplyAllInjectable from "../../main/kubectl/kubectl-apply-all.injectable";
|
||||
import { getDiForUnitTesting } from "../../main/getDiForUnitTesting";
|
||||
import type { KubernetesCluster } from "../catalog-entities";
|
||||
import readDirectoryInjectable from "../fs/read-directory.injectable";
|
||||
import readFileInjectable from "../fs/read-file.injectable";
|
||||
import createResourceStackInjectable from "../k8s/create-resource-stack.injectable";
|
||||
import appPathsStateInjectable from "../app-paths/app-paths-state.injectable";
|
||||
import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
|
||||
describe("create resource stack tests", () => {
|
||||
let di: DiContainer;
|
||||
let cluster: KubernetesCluster;
|
||||
|
||||
beforeEach(async () => {
|
||||
di = getDiForUnitTesting();
|
||||
cluster = {
|
||||
getId: () => "test-cluster",
|
||||
} as any;
|
||||
|
||||
di.override(readDirectoryInjectable, () => () => Promise.resolve(["file1"]) as any);
|
||||
di.override(readFileInjectable, () => () => Promise.resolve("filecontents"));
|
||||
di.override(appPathsStateInjectable, () => ({
|
||||
get: () => ({}),
|
||||
}));
|
||||
di.override(directoryForUserDataInjectable, () => "/some-directory-for-user-data");
|
||||
|
||||
});
|
||||
|
||||
describe("kubectlApplyFolder", () => {
|
||||
it("returns response", async () => {
|
||||
di.override(kubectlApplyAllInjectable, () => () => Promise.resolve({
|
||||
callWasSuccessful: true as const,
|
||||
response: "success",
|
||||
}));
|
||||
|
||||
const createResourceStack = di.inject(createResourceStackInjectable);
|
||||
const resourceStack = createResourceStack(cluster, "test");
|
||||
|
||||
const response = await resourceStack.kubectlApplyFolder("/foo/bar");
|
||||
|
||||
expect(response).toEqual("success");
|
||||
});
|
||||
|
||||
it("throws on error", async () => {
|
||||
di.override(kubectlApplyAllInjectable, () => () => Promise.resolve({
|
||||
callWasSuccessful: false as const,
|
||||
error: "No permissions",
|
||||
}));
|
||||
|
||||
const createResourceStack = di.inject(createResourceStackInjectable);
|
||||
const resourceStack = createResourceStack(cluster, "test");
|
||||
|
||||
await expect(() => resourceStack.kubectlApplyFolder("/foo/bar")).rejects.toThrow("No permissions");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -43,7 +43,7 @@ describe("HotbarStore", () => {
|
||||
let loggerMock: jest.Mocked<Logger>;
|
||||
|
||||
beforeEach(async () => {
|
||||
di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
di = getDiForUnitTesting();
|
||||
|
||||
testCluster = getMockCatalogEntity({
|
||||
apiVersion: "v1",
|
||||
|
||||
@@ -21,7 +21,7 @@ describe("user store tests", () => {
|
||||
let di: DiContainer;
|
||||
|
||||
beforeEach(async () => {
|
||||
di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
di = getDiForUnitTesting();
|
||||
|
||||
di.override(writeFileInjectable, () => () => Promise.resolve());
|
||||
di.override(directoryForUserDataInjectable, () => "/some-directory-for-user-data");
|
||||
@@ -30,9 +30,9 @@ describe("user store tests", () => {
|
||||
get: () => "latest" as const,
|
||||
init: async () => {},
|
||||
}));
|
||||
|
||||
await di.inject(defaultUpdateChannelInjectable).init();
|
||||
|
||||
userStore = di.inject(userStoreInjectable);
|
||||
});
|
||||
|
||||
describe("for an empty config", () => {
|
||||
@@ -42,6 +42,8 @@ describe("user store tests", () => {
|
||||
writeJsonSync("/some-directory-for-user-data/lens-user-store.json", {});
|
||||
writeJsonSync("/some-directory-for-user-data/kube_config", {});
|
||||
|
||||
userStore = di.inject(userStoreInjectable);
|
||||
|
||||
userStore.load();
|
||||
});
|
||||
|
||||
@@ -90,6 +92,8 @@ describe("user store tests", () => {
|
||||
|
||||
di.override(storeMigrationVersionInjectable, () => "10.0.0");
|
||||
|
||||
userStore = di.inject(userStoreInjectable);
|
||||
|
||||
userStore.load();
|
||||
});
|
||||
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverride } from "../test-utils/get-global-override";
|
||||
import { getGlobalOverride } from "@k8slens/test-utils";
|
||||
import pathToNpmCliInjectable from "./path-to-npm-cli.injectable";
|
||||
|
||||
export default getGlobalOverride(pathToNpmCliInjectable, () => "/some/npm/cli/path");
|
||||
@@ -7,7 +7,7 @@ import type Config from "conf";
|
||||
import type { Migrations, Options as ConfOptions } from "conf/dist/source/types";
|
||||
import type { IEqualsComparer } from "mobx";
|
||||
import { makeObservable, reaction } from "mobx";
|
||||
import { disposer, isPromiseLike, toJS } from "../utils";
|
||||
import { disposer, isPromiseLike } from "@k8slens/utilities";
|
||||
import { broadcastMessage } from "../ipc";
|
||||
import isEqual from "lodash/isEqual";
|
||||
import { kebabCase } from "lodash";
|
||||
@@ -16,6 +16,7 @@ import type { Logger } from "../logger";
|
||||
import type { PersistStateToConfig } from "./save-to-file";
|
||||
import type { GetBasenameOfPath } from "../path/get-basename.injectable";
|
||||
import type { EnlistMessageChannelListener } from "../utils/channel/enlist-message-channel-listener-injection-token";
|
||||
import { toJS } from "../utils";
|
||||
|
||||
export interface BaseStoreParams<T> extends Omit<ConfOptions<T>, "migrations"> {
|
||||
syncOptions?: {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { lifecycleEnum, getInjectable } from "@ogre-tools/injectable";
|
||||
import type Conf from "conf/dist/source";
|
||||
import type { Migrations } from "conf/dist/source/types";
|
||||
import loggerInjectable from "../logger.injectable";
|
||||
import { getOrInsert, iter } from "../utils";
|
||||
import { getOrInsert, iter } from "@k8slens/utilities";
|
||||
|
||||
export interface MigrationDeclaration {
|
||||
version: string;
|
||||
|
||||
@@ -12,7 +12,7 @@ describe("kubernetesClusterCategory", () => {
|
||||
let kubernetesClusterCategory: KubernetesClusterCategory;
|
||||
|
||||
beforeEach(() => {
|
||||
const di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
const di = getDiForUnitTesting();
|
||||
|
||||
kubernetesClusterCategory = di.inject(kubernetesClusterCategoryInjectable);
|
||||
});
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { generalCatalogEntityInjectionToken } from "../general-catalog-entity-injection-token";
|
||||
import { GeneralEntity } from "../../index";
|
||||
import { buildURL } from "../../../utils/buildUrl";
|
||||
import { buildURL } from "@k8slens/utilities";
|
||||
import catalogRouteInjectable from "../../../front-end-routing/routes/catalog/catalog-route.injectable";
|
||||
|
||||
const catalogCatalogEntityInjectable = getInjectable({
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { generalCatalogEntityInjectionToken } from "../general-catalog-entity-injection-token";
|
||||
import { GeneralEntity } from "../../index";
|
||||
import { buildURL } from "../../../utils/buildUrl";
|
||||
import { buildURL } from "@k8slens/utilities";
|
||||
import welcomeRouteInjectable from "../../../front-end-routing/routes/welcome/welcome-route.injectable";
|
||||
|
||||
const welcomeCatalogEntityInjectable = getInjectable({
|
||||
|
||||
@@ -13,6 +13,7 @@ import { requestClusterActivation, requestClusterDisconnection } from "../../ren
|
||||
import KubeClusterCategoryIcon from "./icons/kubernetes.svg";
|
||||
import getClusterByIdInjectable from "../cluster-store/get-by-id.injectable";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import clusterConnectionInjectable from "../../main/cluster/cluster-connection.injectable";
|
||||
|
||||
export interface KubernetesClusterPrometheusMetrics {
|
||||
address?: {
|
||||
@@ -79,8 +80,15 @@ export class KubernetesCluster<
|
||||
if (app) {
|
||||
const di = getLegacyGlobalDiForExtensionApi();
|
||||
const getClusterById = di.inject(getClusterByIdInjectable);
|
||||
const cluster = getClusterById(this.getId());
|
||||
|
||||
await getClusterById(this.getId())?.activate();
|
||||
if (!cluster) {
|
||||
return;
|
||||
}
|
||||
|
||||
const connectionCluster = di.inject(clusterConnectionInjectable, cluster);
|
||||
|
||||
await connectionCluster.activate();
|
||||
} else {
|
||||
await requestClusterActivation(this.getId(), false);
|
||||
}
|
||||
@@ -90,8 +98,15 @@ export class KubernetesCluster<
|
||||
if (app) {
|
||||
const di = getLegacyGlobalDiForExtensionApi();
|
||||
const getClusterById = di.inject(getClusterByIdInjectable);
|
||||
const cluster = getClusterById(this.getId());
|
||||
|
||||
getClusterById(this.getId())?.disconnect();
|
||||
if (!cluster) {
|
||||
return;
|
||||
}
|
||||
|
||||
const connectionCluster = di.inject(clusterConnectionInjectable, cluster);
|
||||
|
||||
connectionCluster.disconnect();
|
||||
} else {
|
||||
await requestClusterDisconnection(this.getId(), false);
|
||||
}
|
||||
@@ -127,7 +142,13 @@ export class KubernetesCluster<
|
||||
context.menuItems.push({
|
||||
title: "Disconnect",
|
||||
icon: "link_off",
|
||||
onClick: () => requestClusterDisconnection(this.getId()),
|
||||
onClick: () => {
|
||||
requestClusterDisconnection(this.getId());
|
||||
broadcastMessage(
|
||||
IpcRendererNavigationEvents.NAVIGATE_IN_APP,
|
||||
"/catalog",
|
||||
);
|
||||
},
|
||||
});
|
||||
break;
|
||||
case LensKubernetesClusterStatus.DISCONNECTED:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { Environments, getEnvironmentSpecificLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import { getEnvironmentSpecificLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import type { CatalogEntityContextMenuContext, CatalogEntityMetadata, CatalogEntityStatus } from "../catalog";
|
||||
import { CatalogCategory, CatalogEntity, categoryVersion } from "../catalog/catalog-entity";
|
||||
import productNameInjectable from "../vars/product-name.injectable";
|
||||
@@ -32,7 +32,7 @@ export class WebLink extends CatalogEntity<CatalogEntityMetadata, WebLinkStatus,
|
||||
|
||||
onContextMenuOpen(context: CatalogEntityContextMenuContext) {
|
||||
// NOTE: this is safe because `onContextMenuOpen` is only supposed to be called in the renderer
|
||||
const di = getEnvironmentSpecificLegacyGlobalDiForExtensionApi(Environments.renderer);
|
||||
const di = getEnvironmentSpecificLegacyGlobalDiForExtensionApi("renderer");
|
||||
const productName = di.inject(productNameInjectable);
|
||||
const weblinkStore = di.inject(weblinkStoreInjectable);
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ import EventEmitter from "events";
|
||||
import type TypedEmitter from "typed-emitter";
|
||||
import { observable, makeObservable } from "mobx";
|
||||
import { once } from "lodash";
|
||||
import type { Disposer } from "../utils";
|
||||
import { iter } from "../utils";
|
||||
import type { Disposer } from "@k8slens/utilities";
|
||||
import { iter } from "@k8slens/utilities";
|
||||
import type { CategoryColumnRegistration, TitleCellProps } from "../../renderer/components/+catalog/custom-category-columns";
|
||||
|
||||
export type { CategoryColumnRegistration, TitleCellProps };
|
||||
@@ -241,7 +241,7 @@ export interface CatalogEntityMetadata extends EntityMetadataObject {
|
||||
shortName?: string;
|
||||
description?: string;
|
||||
source?: string;
|
||||
labels: Record<string, string>;
|
||||
labels: Partial<Record<string, string>>;
|
||||
}
|
||||
|
||||
export interface CatalogEntityStatus {
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
import { action, computed, observable, makeObservable } from "mobx";
|
||||
import { once } from "lodash";
|
||||
import { iter, getOrInsertMap, strictSet } from "../utils";
|
||||
import type { Disposer } from "../utils";
|
||||
import { iter, getOrInsertMap, strictSet } from "@k8slens/utilities";
|
||||
import type { Disposer } from "@k8slens/utilities";
|
||||
import type { CatalogCategory, CatalogEntityData, CatalogEntityKindData } from "./catalog-entity";
|
||||
|
||||
export type CategoryFilter = (category: CatalogCategory) => any;
|
||||
@@ -34,6 +34,10 @@ export class CatalogCategoryRegistry {
|
||||
};
|
||||
}
|
||||
|
||||
getById(id: string) {
|
||||
return iter.find(this.categories.values(), (category) => category.getId() === id);
|
||||
}
|
||||
|
||||
@computed get items() {
|
||||
return Array.from(this.categories);
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverride } from "../test-utils/get-global-override";
|
||||
import { getGlobalOverride } from "@k8slens/test-utils";
|
||||
import lensProxyCertificateInjectable from "./lens-proxy-certificate.injectable";
|
||||
|
||||
export default getGlobalOverride(lensProxyCertificateInjectable, () => {
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { ClusterStore } from "./cluster-store";
|
||||
import { createClusterInjectionToken } from "../cluster/create-cluster-injection-token";
|
||||
import readClusterConfigSyncInjectable from "./read-cluster-config.injectable";
|
||||
import emitAppEventInjectable from "../app-event-bus/emit-event.injectable";
|
||||
import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
@@ -23,7 +22,6 @@ const clusterStoreInjectable = getInjectable({
|
||||
id: "cluster-store",
|
||||
|
||||
instantiate: (di) => new ClusterStore({
|
||||
createCluster: di.inject(createClusterInjectionToken),
|
||||
readClusterConfigSync: di.inject(readClusterConfigSyncInjectable),
|
||||
emitAppEvent: di.inject(emitAppEventInjectable),
|
||||
directoryForUserData: di.inject(directoryForUserDataInjectable),
|
||||
|
||||
@@ -10,7 +10,6 @@ import { BaseStore } from "../base-store/base-store";
|
||||
import { Cluster } from "../cluster/cluster";
|
||||
import { toJS } from "../utils";
|
||||
import type { ClusterModel, ClusterId } from "../cluster-types";
|
||||
import type { CreateCluster } from "../cluster/create-cluster-injection-token";
|
||||
import type { ReadClusterConfigSync } from "./read-cluster-config.injectable";
|
||||
import type { EmitAppEvent } from "../app-event-bus/emit-event.injectable";
|
||||
|
||||
@@ -19,7 +18,6 @@ export interface ClusterStoreModel {
|
||||
}
|
||||
|
||||
interface Dependencies extends BaseStoreDependencies {
|
||||
createCluster: CreateCluster;
|
||||
readClusterConfigSync: ReadClusterConfigSync;
|
||||
emitAppEvent: EmitAppEvent;
|
||||
}
|
||||
@@ -64,7 +62,7 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
||||
|
||||
const cluster = clusterOrModel instanceof Cluster
|
||||
? clusterOrModel
|
||||
: this.dependencies.createCluster(
|
||||
: new Cluster(
|
||||
clusterOrModel,
|
||||
this.dependencies.readClusterConfigSync(clusterOrModel),
|
||||
);
|
||||
@@ -87,7 +85,7 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
|
||||
if (cluster) {
|
||||
cluster.updateModel(clusterModel);
|
||||
} else {
|
||||
cluster = this.dependencies.createCluster(
|
||||
cluster = new Cluster(
|
||||
clusterModel,
|
||||
this.dependencies.readClusterConfigSync(clusterModel),
|
||||
);
|
||||
|
||||
@@ -39,10 +39,6 @@ export const updateClusterModelChecker = Joi.object<UpdateClusterModel>({
|
||||
contextName: Joi.string()
|
||||
.required()
|
||||
.min(1),
|
||||
workspace: Joi.string()
|
||||
.optional(),
|
||||
workspaces: Joi.array()
|
||||
.items(Joi.string()),
|
||||
preferences: Joi.object(),
|
||||
metadata: Joi.object(),
|
||||
accessibleNamespaces: Joi.array()
|
||||
@@ -70,18 +66,6 @@ export interface ClusterModel {
|
||||
/** Path to cluster kubeconfig */
|
||||
kubeConfigPath: string;
|
||||
|
||||
/**
|
||||
* Workspace id
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
workspace?: string;
|
||||
|
||||
/**
|
||||
* @deprecated this is used only for hotbar migrations from 4.2.X
|
||||
*/
|
||||
workspaces?: string[];
|
||||
|
||||
/** User context in kubeconfig */
|
||||
contextName: string;
|
||||
|
||||
@@ -97,7 +81,7 @@ export interface ClusterModel {
|
||||
/**
|
||||
* Labels for the catalog entity
|
||||
*/
|
||||
labels?: Record<string, string>;
|
||||
labels?: Partial<Record<string, string>>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -206,6 +190,6 @@ export interface ClusterState {
|
||||
ready: boolean;
|
||||
isAdmin: boolean;
|
||||
allowedNamespaces: string[];
|
||||
allowedResources: string[];
|
||||
resourcesToShow: string[];
|
||||
isGlobalWatchEnabled: boolean;
|
||||
}
|
||||
@@ -6,7 +6,6 @@
|
||||
import type { KubeConfig, V1ResourceAttributes } from "@kubernetes/client-node";
|
||||
import { AuthorizationV1Api } from "@kubernetes/client-node";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { Logger } from "../logger";
|
||||
import loggerInjectable from "../logger.injectable";
|
||||
|
||||
/**
|
||||
@@ -19,41 +18,33 @@ export type CanI = (resourceAttributes: V1ResourceAttributes) => Promise<boolean
|
||||
/**
|
||||
* @param proxyConfig This config's `currentContext` field must be set, and will be used as the target cluster
|
||||
*/
|
||||
export type AuthorizationReview = (proxyConfig: KubeConfig) => CanI;
|
||||
export type CreateAuthorizationReview = (proxyConfig: KubeConfig) => CanI;
|
||||
|
||||
interface Dependencies {
|
||||
logger: Logger;
|
||||
}
|
||||
|
||||
const authorizationReview = ({ logger }: Dependencies): AuthorizationReview => {
|
||||
return (proxyConfig) => {
|
||||
const api = proxyConfig.makeApiClient(AuthorizationV1Api);
|
||||
|
||||
return async (resourceAttributes: V1ResourceAttributes): Promise<boolean> => {
|
||||
try {
|
||||
const { body } = await api.createSelfSubjectAccessReview({
|
||||
apiVersion: "authorization.k8s.io/v1",
|
||||
kind: "SelfSubjectAccessReview",
|
||||
spec: { resourceAttributes },
|
||||
});
|
||||
|
||||
return body.status?.allowed ?? false;
|
||||
} catch (error) {
|
||||
logger.error(`[AUTHORIZATION-REVIEW]: failed to create access review: ${error}`, { resourceAttributes });
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
const authorizationReviewInjectable = getInjectable({
|
||||
const createAuthorizationReviewInjectable = getInjectable({
|
||||
id: "authorization-review",
|
||||
instantiate: (di) => {
|
||||
instantiate: (di): CreateAuthorizationReview => {
|
||||
const logger = di.inject(loggerInjectable);
|
||||
|
||||
return authorizationReview({ logger });
|
||||
return (proxyConfig) => {
|
||||
const api = proxyConfig.makeApiClient(AuthorizationV1Api);
|
||||
|
||||
return async (resourceAttributes: V1ResourceAttributes): Promise<boolean> => {
|
||||
try {
|
||||
const { body } = await api.createSelfSubjectAccessReview({
|
||||
apiVersion: "authorization.k8s.io/v1",
|
||||
kind: "SelfSubjectAccessReview",
|
||||
spec: { resourceAttributes },
|
||||
});
|
||||
|
||||
return body.status?.allowed ?? false;
|
||||
} catch (error) {
|
||||
logger.error(`[AUTHORIZATION-REVIEW]: failed to create access review: ${error}`, { resourceAttributes });
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default authorizationReviewInjectable;
|
||||
export default createAuthorizationReviewInjectable;
|
||||
@@ -3,164 +3,74 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { action, comparer, computed, makeObservable, observable, reaction, runInAction, when } from "mobx";
|
||||
import type { ClusterContextHandler } from "../../main/context-handler/context-handler";
|
||||
import type { KubeConfig } from "@kubernetes/client-node";
|
||||
import { HttpError } from "@kubernetes/client-node";
|
||||
import type { Kubectl } from "../../main/kubectl/kubectl";
|
||||
import type { KubeconfigManager } from "../../main/kubeconfig-manager/kubeconfig-manager";
|
||||
import type { KubeApiResource, KubeApiResourceDescriptor } from "../rbac";
|
||||
import { formatKubeApiResource } from "../rbac";
|
||||
import plimit from "p-limit";
|
||||
import type { ClusterState, ClusterMetricsResourceType, ClusterId, ClusterMetadata, ClusterModel, ClusterPreferences, ClusterPrometheusPreferences, UpdateClusterModel, KubeAuthUpdate, ClusterConfigData } from "../cluster-types";
|
||||
import { ClusterMetadataKey, initialNodeShellImage, ClusterStatus, clusterModelIdChecker, updateClusterModelChecker } from "../cluster-types";
|
||||
import { disposer, isDefined, isRequestError, toJS } from "../utils";
|
||||
import { clusterListNamespaceForbiddenChannel } from "../ipc/cluster";
|
||||
import type { CanI } from "./authorization-review.injectable";
|
||||
import type { ListNamespaces } from "./list-namespaces.injectable";
|
||||
import assert from "assert";
|
||||
import type { Logger } from "../logger";
|
||||
import type { BroadcastMessage } from "../ipc/broadcast-message.injectable";
|
||||
import type { LoadConfigfromFile } from "../kube-helpers/load-config-from-file.injectable";
|
||||
import type { CanListResource, RequestNamespaceListPermissions, RequestNamespaceListPermissionsFor } from "./request-namespace-list-permissions.injectable";
|
||||
import type { RequestApiResources } from "../../main/cluster/request-api-resources.injectable";
|
||||
import type { DetectClusterMetadata } from "../../main/cluster-detectors/detect-cluster-metadata.injectable";
|
||||
import type { FalibleOnlyClusterMetadataDetector } from "../../main/cluster-detectors/token";
|
||||
import { computed, observable, toJS, runInAction } from "mobx";
|
||||
import type { KubeApiResource } from "../rbac";
|
||||
import type { ClusterState, ClusterId, ClusterMetadata, ClusterModel, ClusterPreferences, ClusterPrometheusPreferences, UpdateClusterModel, ClusterConfigData } from "../cluster-types";
|
||||
import { ClusterMetadataKey, clusterModelIdChecker, updateClusterModelChecker } from "../cluster-types";
|
||||
import type { IObservableValue } from "mobx";
|
||||
import { replaceObservableObject } from "../utils/replace-observable-object";
|
||||
import { pick } from "lodash";
|
||||
|
||||
export interface ClusterDependencies {
|
||||
readonly directoryForKubeConfigs: string;
|
||||
readonly logger: Logger;
|
||||
readonly clusterVersionDetector: FalibleOnlyClusterMetadataDetector;
|
||||
detectClusterMetadata: DetectClusterMetadata;
|
||||
createKubeconfigManager: (cluster: Cluster) => KubeconfigManager;
|
||||
createContextHandler: (cluster: Cluster) => ClusterContextHandler;
|
||||
createKubectl: (clusterVersion: string) => Kubectl;
|
||||
createAuthorizationReview: (config: KubeConfig) => CanI;
|
||||
requestApiResources: RequestApiResources;
|
||||
requestNamespaceListPermissionsFor: RequestNamespaceListPermissionsFor;
|
||||
createListNamespaces: (config: KubeConfig) => ListNamespaces;
|
||||
broadcastMessage: BroadcastMessage;
|
||||
loadConfigfromFile: LoadConfigfromFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cluster
|
||||
*
|
||||
* @beta
|
||||
*/
|
||||
export class Cluster implements ClusterModel {
|
||||
/** Unique id for a cluster */
|
||||
public readonly id: ClusterId;
|
||||
private kubeCtl: Kubectl | undefined;
|
||||
export class Cluster {
|
||||
/**
|
||||
* Context handler
|
||||
*
|
||||
* @internal
|
||||
* Unique id for a cluster
|
||||
*/
|
||||
protected readonly _contextHandler: ClusterContextHandler | undefined;
|
||||
protected readonly _proxyKubeconfigManager: KubeconfigManager | undefined;
|
||||
protected readonly eventsDisposer = disposer();
|
||||
protected activated = false;
|
||||
|
||||
public get contextHandler() {
|
||||
// TODO: remove these once main/renderer are seperate classes
|
||||
assert(this._contextHandler, "contextHandler is only defined in the main environment");
|
||||
|
||||
return this._contextHandler;
|
||||
}
|
||||
|
||||
protected get proxyKubeconfigManager() {
|
||||
// TODO: remove these once main/renderer are seperate classes
|
||||
assert(this._proxyKubeconfigManager, "proxyKubeconfigManager is only defined in the main environment");
|
||||
|
||||
return this._proxyKubeconfigManager;
|
||||
}
|
||||
|
||||
get whenReady() {
|
||||
return when(() => this.ready);
|
||||
}
|
||||
readonly id: ClusterId;
|
||||
|
||||
/**
|
||||
* Kubeconfig context name
|
||||
*
|
||||
* @observable
|
||||
*/
|
||||
@observable contextName!: string;
|
||||
readonly contextName = observable.box() as IObservableValue<string>;
|
||||
|
||||
/**
|
||||
* Path to kubeconfig
|
||||
*
|
||||
* @observable
|
||||
*/
|
||||
@observable kubeConfigPath!: string;
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
@observable workspace?: string;
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
@observable workspaces?: string[];
|
||||
readonly kubeConfigPath = observable.box() as IObservableValue<string>;
|
||||
|
||||
/**
|
||||
* Kubernetes API server URL
|
||||
*
|
||||
* @observable
|
||||
*/
|
||||
@observable apiUrl: string; // cluster server url
|
||||
readonly apiUrl: IObservableValue<string>;
|
||||
|
||||
/**
|
||||
* Is cluster online
|
||||
*
|
||||
* @observable
|
||||
* Describes if we can detect that cluster is online
|
||||
*/
|
||||
@observable online = false; // describes if we can detect that cluster is online
|
||||
readonly online = observable.box(false);
|
||||
|
||||
/**
|
||||
* Can user access cluster resources
|
||||
*
|
||||
* @observable
|
||||
* Describes if user is able to access cluster resources
|
||||
*/
|
||||
@observable accessible = false; // if user is able to access cluster resources
|
||||
readonly accessible = observable.box(false);
|
||||
|
||||
/**
|
||||
* Is cluster instance in usable state
|
||||
*
|
||||
* @observable
|
||||
*/
|
||||
@observable ready = false; // cluster is in usable state
|
||||
/**
|
||||
* Is cluster currently reconnecting
|
||||
*
|
||||
* @observable
|
||||
*/
|
||||
@observable reconnecting = false;
|
||||
readonly ready = observable.box(false);
|
||||
|
||||
/**
|
||||
* Is cluster disconnected. False if user has selected to connect.
|
||||
*
|
||||
* @observable
|
||||
*/
|
||||
@observable disconnected = true;
|
||||
readonly disconnected = observable.box(true);
|
||||
|
||||
/**
|
||||
* Does user have admin like access
|
||||
*
|
||||
* @observable
|
||||
*/
|
||||
@observable isAdmin = false;
|
||||
readonly isAdmin = observable.box(false);
|
||||
|
||||
/**
|
||||
* Global watch-api accessibility , e.g. "/api/v1/services?watch=1"
|
||||
*
|
||||
* @observable
|
||||
*/
|
||||
@observable isGlobalWatchEnabled = false;
|
||||
readonly isGlobalWatchEnabled = observable.box(false);
|
||||
|
||||
/**
|
||||
* Preferences
|
||||
*
|
||||
* @observable
|
||||
*/
|
||||
@observable preferences: ClusterPreferences = {};
|
||||
readonly preferences = observable.object<ClusterPreferences>({});
|
||||
|
||||
/**
|
||||
* Metadata
|
||||
*
|
||||
* @observable
|
||||
*/
|
||||
@observable metadata: ClusterMetadata = {};
|
||||
readonly metadata = observable.object<ClusterMetadata>({});
|
||||
|
||||
/**
|
||||
* List of allowed namespaces verified via K8S::SelfSubjectAccessReview api
|
||||
@@ -172,73 +82,47 @@ export class Cluster implements ClusterModel {
|
||||
*/
|
||||
readonly accessibleNamespaces = observable.array<string>();
|
||||
|
||||
private readonly knownResources = observable.array<KubeApiResource>();
|
||||
/**
|
||||
* The list of all known resources associated with this cluster
|
||||
*/
|
||||
readonly knownResources = observable.array<KubeApiResource>();
|
||||
|
||||
// The formatting of this is `group.name` or `name` (if in core)
|
||||
private readonly allowedResources = observable.set<string>();
|
||||
/**
|
||||
* The formatting of this is `group.name` or `name` (if in core)
|
||||
*/
|
||||
readonly resourcesToShow = observable.set<string>();
|
||||
|
||||
/**
|
||||
* Labels for the catalog entity
|
||||
*/
|
||||
@observable labels: Record<string, string> = {};
|
||||
readonly labels = observable.object<Partial<Record<string, string>>>({});
|
||||
|
||||
/**
|
||||
* Is cluster available
|
||||
*
|
||||
* @computed
|
||||
*/
|
||||
@computed get available() {
|
||||
return this.accessible && !this.disconnected;
|
||||
}
|
||||
readonly available = computed(() => this.accessible.get() && !this.disconnected.get());
|
||||
|
||||
/**
|
||||
* Cluster name
|
||||
*
|
||||
* @computed
|
||||
*/
|
||||
@computed get name() {
|
||||
return this.preferences.clusterName || this.contextName;
|
||||
}
|
||||
readonly name = computed(() => this.preferences.clusterName || this.contextName.get());
|
||||
|
||||
/**
|
||||
* The detected kubernetes distribution
|
||||
*/
|
||||
@computed get distribution(): string {
|
||||
return this.metadata[ClusterMetadataKey.DISTRIBUTION]?.toString() || "unknown";
|
||||
}
|
||||
readonly distribution = computed(() => this.metadata[ClusterMetadataKey.DISTRIBUTION]?.toString() || "unknown");
|
||||
|
||||
/**
|
||||
* The detected kubernetes version
|
||||
*/
|
||||
@computed get version(): string {
|
||||
return this.metadata[ClusterMetadataKey.VERSION]?.toString() || "unknown";
|
||||
}
|
||||
readonly version = computed(() => this.metadata[ClusterMetadataKey.VERSION]?.toString() || "unknown");
|
||||
|
||||
/**
|
||||
* Prometheus preferences
|
||||
*
|
||||
* @computed
|
||||
* @internal
|
||||
*/
|
||||
@computed get prometheusPreferences(): ClusterPrometheusPreferences {
|
||||
const { prometheus, prometheusProvider } = this.preferences;
|
||||
|
||||
return toJS({ prometheus, prometheusProvider });
|
||||
}
|
||||
|
||||
/**
|
||||
* defaultNamespace preference
|
||||
*
|
||||
* @computed
|
||||
* @internal
|
||||
*/
|
||||
@computed get defaultNamespace(): string | undefined {
|
||||
return this.preferences.defaultNamespace;
|
||||
}
|
||||
|
||||
constructor(private readonly dependencies: ClusterDependencies, { id, ...model }: ClusterModel, configData: ClusterConfigData) {
|
||||
makeObservable(this);
|
||||
readonly prometheusPreferences = computed(() => pick(toJS(this.preferences), "prometheus", "prometheusProvider") as ClusterPrometheusPreferences);
|
||||
|
||||
constructor({ id, ...model }: ClusterModel, configData: ClusterConfigData) {
|
||||
const { error } = clusterModelIdChecker.validate({ id });
|
||||
|
||||
if (error) {
|
||||
@@ -247,16 +131,7 @@ export class Cluster implements ClusterModel {
|
||||
|
||||
this.id = id;
|
||||
this.updateModel(model);
|
||||
this.apiUrl = configData.clusterServerUrl;
|
||||
|
||||
// for the time being, until renderer gets its own cluster type
|
||||
this._contextHandler = this.dependencies.createContextHandler(this);
|
||||
this._proxyKubeconfigManager = this.dependencies.createKubeconfigManager(this);
|
||||
this.dependencies.logger.debug(`[CLUSTER]: Cluster init success`, {
|
||||
id: this.id,
|
||||
context: this.contextName,
|
||||
apiUrl: this.apiUrl,
|
||||
});
|
||||
this.apiUrl = observable.box(configData.clusterServerUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -264,7 +139,7 @@ export class Cluster implements ClusterModel {
|
||||
*
|
||||
* @param model
|
||||
*/
|
||||
@action updateModel(model: UpdateClusterModel) {
|
||||
updateModel(model: UpdateClusterModel) {
|
||||
// Note: do not assign ID as that should never be updated
|
||||
|
||||
const { error } = updateClusterModelChecker.validate(model, { allowUnknown: true });
|
||||
@@ -273,448 +148,83 @@ export class Cluster implements ClusterModel {
|
||||
throw error;
|
||||
}
|
||||
|
||||
this.kubeConfigPath = model.kubeConfigPath;
|
||||
this.contextName = model.contextName;
|
||||
|
||||
if (model.workspace) {
|
||||
this.workspace = model.workspace;
|
||||
}
|
||||
|
||||
if (model.workspaces) {
|
||||
this.workspaces = model.workspaces;
|
||||
}
|
||||
|
||||
if (model.preferences) {
|
||||
this.preferences = model.preferences;
|
||||
}
|
||||
|
||||
if (model.metadata) {
|
||||
this.metadata = model.metadata;
|
||||
}
|
||||
|
||||
if (model.accessibleNamespaces) {
|
||||
this.accessibleNamespaces.replace(model.accessibleNamespaces);
|
||||
}
|
||||
|
||||
if (model.labels) {
|
||||
this.labels = model.labels;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
protected bindEvents() {
|
||||
this.dependencies.logger.info(`[CLUSTER]: bind events`, this.getMeta());
|
||||
const refreshTimer = setInterval(() => !this.disconnected && this.refresh(), 30000); // every 30s
|
||||
const refreshMetadataTimer = setInterval(() => this.available && this.refreshAccessibilityAndMetadata(), 900000); // every 15 minutes
|
||||
|
||||
this.eventsDisposer.push(
|
||||
reaction(
|
||||
() => this.prometheusPreferences,
|
||||
prefs => this.contextHandler.setupPrometheus(prefs),
|
||||
{ equals: comparer.structural },
|
||||
),
|
||||
() => clearInterval(refreshTimer),
|
||||
() => clearInterval(refreshMetadataTimer),
|
||||
reaction(() => this.defaultNamespace, () => this.recreateProxyKubeconfig()),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
protected async recreateProxyKubeconfig() {
|
||||
this.dependencies.logger.info("[CLUSTER]: Recreating proxy kubeconfig");
|
||||
|
||||
try {
|
||||
await this.proxyKubeconfigManager.clear();
|
||||
await this.getProxyKubeconfig();
|
||||
} catch (error) {
|
||||
this.dependencies.logger.error(`[CLUSTER]: failed to recreate proxy kubeconfig`, error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param force force activation
|
||||
* @internal
|
||||
*/
|
||||
@action
|
||||
async activate(force = false) {
|
||||
if (this.activated && !force) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.dependencies.logger.info(`[CLUSTER]: activate`, this.getMeta());
|
||||
|
||||
if (!this.eventsDisposer.length) {
|
||||
this.bindEvents();
|
||||
}
|
||||
|
||||
if (this.disconnected || !this.accessible) {
|
||||
try {
|
||||
this.broadcastConnectUpdate("Starting connection ...");
|
||||
await this.reconnect();
|
||||
} catch (error) {
|
||||
this.broadcastConnectUpdate(`Failed to start connection: ${error}`, "error");
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
this.broadcastConnectUpdate("Refreshing connection status ...");
|
||||
await this.refreshConnectionStatus();
|
||||
} catch (error) {
|
||||
this.broadcastConnectUpdate(`Failed to connection status: ${error}`, "error");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.accessible) {
|
||||
try {
|
||||
this.broadcastConnectUpdate("Refreshing cluster accessibility ...");
|
||||
await this.refreshAccessibility();
|
||||
} catch (error) {
|
||||
this.broadcastConnectUpdate(`Failed to refresh accessibility: ${error}`, "error");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// download kubectl in background, so it's not blocking dashboard
|
||||
this.ensureKubectl()
|
||||
.catch(error => this.dependencies.logger.warn(`[CLUSTER]: failed to download kubectl for clusterId=${this.id}`, error));
|
||||
this.broadcastConnectUpdate("Connected, waiting for view to load ...");
|
||||
}
|
||||
|
||||
this.activated = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
async ensureKubectl() {
|
||||
this.kubeCtl ??= this.dependencies.createKubectl(this.version);
|
||||
|
||||
await this.kubeCtl.ensureKubectl();
|
||||
|
||||
return this.kubeCtl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
@action
|
||||
async reconnect() {
|
||||
this.dependencies.logger.info(`[CLUSTER]: reconnect`, this.getMeta());
|
||||
await this.contextHandler?.restartServer();
|
||||
this.disconnected = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
@action disconnect(): void {
|
||||
if (this.disconnected) {
|
||||
return void this.dependencies.logger.debug("[CLUSTER]: already disconnected", { id: this.id });
|
||||
}
|
||||
|
||||
this.dependencies.logger.info(`[CLUSTER]: disconnecting`, { id: this.id });
|
||||
this.eventsDisposer();
|
||||
this.contextHandler?.stopServer();
|
||||
this.disconnected = true;
|
||||
this.online = false;
|
||||
this.accessible = false;
|
||||
this.ready = false;
|
||||
this.activated = false;
|
||||
this.allowedNamespaces.clear();
|
||||
this.dependencies.logger.info(`[CLUSTER]: disconnected`, { id: this.id });
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
@action
|
||||
async refresh() {
|
||||
this.dependencies.logger.info(`[CLUSTER]: refresh`, this.getMeta());
|
||||
await this.refreshConnectionStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
@action
|
||||
async refreshAccessibilityAndMetadata() {
|
||||
await this.refreshAccessibility();
|
||||
await this.refreshMetadata();
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
async refreshMetadata() {
|
||||
this.dependencies.logger.info(`[CLUSTER]: refreshMetadata`, this.getMeta());
|
||||
|
||||
const newMetadata = await this.dependencies.detectClusterMetadata(this);
|
||||
|
||||
runInAction(() => {
|
||||
this.metadata = {
|
||||
...this.metadata,
|
||||
...newMetadata,
|
||||
};
|
||||
});
|
||||
}
|
||||
this.kubeConfigPath.set(model.kubeConfigPath);
|
||||
this.contextName.set(model.contextName);
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
private async refreshAccessibility(): Promise<void> {
|
||||
this.dependencies.logger.info(`[CLUSTER]: refreshAccessibility`, this.getMeta());
|
||||
const proxyConfig = await this.getProxyKubeconfig();
|
||||
const canI = this.dependencies.createAuthorizationReview(proxyConfig);
|
||||
const requestNamespaceListPermissions = this.dependencies.requestNamespaceListPermissionsFor(proxyConfig);
|
||||
|
||||
this.isAdmin = await canI({
|
||||
namespace: "kube-system",
|
||||
resource: "*",
|
||||
verb: "create",
|
||||
});
|
||||
this.isGlobalWatchEnabled = await canI({
|
||||
verb: "watch",
|
||||
resource: "*",
|
||||
});
|
||||
this.allowedNamespaces.replace(await this.requestAllowedNamespaces(proxyConfig));
|
||||
|
||||
const knownResources = await this.dependencies.requestApiResources(this);
|
||||
|
||||
if (knownResources.callWasSuccessful) {
|
||||
this.knownResources.replace(knownResources.response);
|
||||
} else if (this.knownResources.length > 0) {
|
||||
this.dependencies.logger.warn(`[CLUSTER]: failed to list KUBE resources, sticking with previous list`);
|
||||
} else {
|
||||
this.dependencies.logger.warn(`[CLUSTER]: failed to list KUBE resources for the first time, blocking connection to cluster...`);
|
||||
this.broadcastConnectUpdate("Failed to list kube API resources, please reconnect...", "error");
|
||||
}
|
||||
|
||||
this.allowedResources.replace(await this.getAllowedResources(requestNamespaceListPermissions));
|
||||
this.ready = this.knownResources.length > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
@action
|
||||
async refreshConnectionStatus() {
|
||||
const connectionStatus = await this.getConnectionStatus();
|
||||
|
||||
this.online = connectionStatus > ClusterStatus.Offline;
|
||||
this.accessible = connectionStatus == ClusterStatus.AccessGranted;
|
||||
}
|
||||
|
||||
async getKubeconfig(): Promise<KubeConfig> {
|
||||
const { config } = await this.dependencies.loadConfigfromFile(this.kubeConfigPath);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
async getProxyKubeconfig(): Promise<KubeConfig> {
|
||||
const proxyKCPath = await this.getProxyKubeconfigPath();
|
||||
const { config } = await this.dependencies.loadConfigfromFile(proxyKCPath);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
async getProxyKubeconfigPath(): Promise<string> {
|
||||
return this.proxyKubeconfigManager.getPath();
|
||||
}
|
||||
|
||||
protected async getConnectionStatus(): Promise<ClusterStatus> {
|
||||
try {
|
||||
const versionData = await this.dependencies.clusterVersionDetector.detect(this);
|
||||
|
||||
this.metadata.version = versionData.value;
|
||||
|
||||
return ClusterStatus.AccessGranted;
|
||||
} catch (error) {
|
||||
this.dependencies.logger.error(`[CLUSTER]: Failed to connect to "${this.contextName}": ${error}`);
|
||||
|
||||
if (isRequestError(error)) {
|
||||
if (error.statusCode) {
|
||||
if (error.statusCode >= 400 && error.statusCode < 500) {
|
||||
this.broadcastConnectUpdate("Invalid credentials", "error");
|
||||
|
||||
return ClusterStatus.AccessDenied;
|
||||
}
|
||||
|
||||
const message = String(error.error || error.message) || String(error);
|
||||
|
||||
this.broadcastConnectUpdate(message, "error");
|
||||
|
||||
return ClusterStatus.Offline;
|
||||
}
|
||||
|
||||
if (error.failed === true) {
|
||||
if (error.timedOut === true) {
|
||||
this.broadcastConnectUpdate("Connection timed out", "error");
|
||||
|
||||
return ClusterStatus.Offline;
|
||||
}
|
||||
|
||||
this.broadcastConnectUpdate("Failed to fetch credentials", "error");
|
||||
|
||||
return ClusterStatus.AccessDenied;
|
||||
}
|
||||
|
||||
const message = String(error.error || error.message) || String(error);
|
||||
|
||||
this.broadcastConnectUpdate(message, "error");
|
||||
} else if (error instanceof Error || typeof error === "string") {
|
||||
this.broadcastConnectUpdate(`${error}`, "error");
|
||||
} else {
|
||||
this.broadcastConnectUpdate("Unknown error has occurred", "error");
|
||||
if (model.preferences) {
|
||||
replaceObservableObject(this.preferences, model.preferences);
|
||||
}
|
||||
|
||||
return ClusterStatus.Offline;
|
||||
}
|
||||
if (model.metadata) {
|
||||
replaceObservableObject(this.metadata, model.metadata);
|
||||
}
|
||||
|
||||
if (model.accessibleNamespaces) {
|
||||
this.accessibleNamespaces.replace(model.accessibleNamespaces);
|
||||
}
|
||||
|
||||
if (model.labels) {
|
||||
replaceObservableObject(this.labels, model.labels);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
toJSON(): ClusterModel {
|
||||
return toJS({
|
||||
return {
|
||||
id: this.id,
|
||||
contextName: this.contextName,
|
||||
kubeConfigPath: this.kubeConfigPath,
|
||||
workspace: this.workspace,
|
||||
workspaces: this.workspaces,
|
||||
preferences: this.preferences,
|
||||
metadata: this.metadata,
|
||||
accessibleNamespaces: this.accessibleNamespaces,
|
||||
labels: this.labels,
|
||||
});
|
||||
contextName: this.contextName.get(),
|
||||
kubeConfigPath: this.kubeConfigPath.get(),
|
||||
preferences: toJS(this.preferences),
|
||||
metadata: toJS(this.metadata),
|
||||
accessibleNamespaces: this.accessibleNamespaces.toJSON(),
|
||||
labels: toJS(this.labels),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializable cluster-state used for sync btw main <-> renderer
|
||||
*/
|
||||
getState(): ClusterState {
|
||||
return toJS({
|
||||
apiUrl: this.apiUrl,
|
||||
online: this.online,
|
||||
ready: this.ready,
|
||||
disconnected: this.disconnected,
|
||||
accessible: this.accessible,
|
||||
isAdmin: this.isAdmin,
|
||||
allowedNamespaces: this.allowedNamespaces,
|
||||
allowedResources: [...this.allowedResources],
|
||||
isGlobalWatchEnabled: this.isGlobalWatchEnabled,
|
||||
});
|
||||
return {
|
||||
apiUrl: this.apiUrl.get(),
|
||||
online: this.online.get(),
|
||||
ready: this.ready.get(),
|
||||
disconnected: this.disconnected.get(),
|
||||
accessible: this.accessible.get(),
|
||||
isAdmin: this.isAdmin.get(),
|
||||
allowedNamespaces: this.allowedNamespaces.toJSON(),
|
||||
resourcesToShow: this.resourcesToShow.toJSON(),
|
||||
isGlobalWatchEnabled: this.isGlobalWatchEnabled.get(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @param state cluster state
|
||||
*/
|
||||
@action setState(state: ClusterState) {
|
||||
this.accessible = state.accessible;
|
||||
this.allowedNamespaces.replace(state.allowedNamespaces);
|
||||
this.allowedResources.replace(state.allowedResources);
|
||||
this.apiUrl = state.apiUrl;
|
||||
this.disconnected = state.disconnected;
|
||||
this.isAdmin = state.isAdmin;
|
||||
this.isGlobalWatchEnabled = state.isGlobalWatchEnabled;
|
||||
this.online = state.online;
|
||||
this.ready = state.ready;
|
||||
setState(state: ClusterState) {
|
||||
runInAction(() => {
|
||||
this.accessible.set(state.accessible);
|
||||
this.allowedNamespaces.replace(state.allowedNamespaces);
|
||||
this.resourcesToShow.replace(state.resourcesToShow);
|
||||
this.apiUrl.set(state.apiUrl);
|
||||
this.disconnected.set(state.disconnected);
|
||||
this.isAdmin.set(state.isAdmin);
|
||||
this.isGlobalWatchEnabled.set(state.isGlobalWatchEnabled);
|
||||
this.online.set(state.online);
|
||||
this.ready.set(state.ready);
|
||||
});
|
||||
}
|
||||
|
||||
// get cluster system meta, e.g. use in "logger"
|
||||
getMeta() {
|
||||
return {
|
||||
id: this.id,
|
||||
name: this.contextName,
|
||||
ready: this.ready,
|
||||
online: this.online,
|
||||
accessible: this.accessible,
|
||||
disconnected: this.disconnected,
|
||||
name: this.contextName.get(),
|
||||
ready: this.ready.get(),
|
||||
online: this.online.get(),
|
||||
accessible: this.accessible.get(),
|
||||
disconnected: this.disconnected.get(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* broadcast an authentication update concerning this cluster
|
||||
* @internal
|
||||
*/
|
||||
broadcastConnectUpdate(message: string, level: KubeAuthUpdate["level"] = "info"): void {
|
||||
const update: KubeAuthUpdate = { message, level };
|
||||
|
||||
this.dependencies.logger.debug(`[CLUSTER]: broadcasting connection update`, { ...update, meta: this.getMeta() });
|
||||
this.dependencies.broadcastMessage(`cluster:${this.id}:connection-update`, update);
|
||||
}
|
||||
|
||||
protected async requestAllowedNamespaces(proxyConfig: KubeConfig) {
|
||||
if (this.accessibleNamespaces.length) {
|
||||
return this.accessibleNamespaces;
|
||||
}
|
||||
|
||||
try {
|
||||
const listNamespaces = this.dependencies.createListNamespaces(proxyConfig);
|
||||
|
||||
return await listNamespaces();
|
||||
} catch (error) {
|
||||
const ctx = proxyConfig.getContextObject(this.contextName);
|
||||
const namespaceList = [ctx?.namespace].filter(isDefined);
|
||||
|
||||
if (namespaceList.length === 0 && error instanceof HttpError && error.statusCode === 403) {
|
||||
const { response } = error as HttpError & { response: { body: unknown }};
|
||||
|
||||
this.dependencies.logger.info("[CLUSTER]: listing namespaces is forbidden, broadcasting", { clusterId: this.id, error: response.body });
|
||||
this.dependencies.broadcastMessage(clusterListNamespaceForbiddenChannel, this.id);
|
||||
}
|
||||
|
||||
return namespaceList;
|
||||
}
|
||||
}
|
||||
|
||||
protected async getAllowedResources(requestNamespaceListPermissions: RequestNamespaceListPermissions) {
|
||||
if (!this.allowedNamespaces.length || !this.knownResources.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
try {
|
||||
const apiLimit = plimit(5); // 5 concurrent api requests
|
||||
const canListResourceCheckers = await Promise.all((
|
||||
this.allowedNamespaces.map(namespace => apiLimit(() => requestNamespaceListPermissions(namespace)))
|
||||
));
|
||||
const canListNamespacedResource: CanListResource = (resource) => canListResourceCheckers.some(fn => fn(resource));
|
||||
|
||||
return this.knownResources
|
||||
.filter(canListNamespacedResource)
|
||||
.map(formatKubeApiResource);
|
||||
} catch (error) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
shouldShowResource(resource: KubeApiResourceDescriptor): boolean {
|
||||
return this.allowedResources.has(formatKubeApiResource(resource));
|
||||
}
|
||||
|
||||
isMetricHidden(resource: ClusterMetricsResourceType): boolean {
|
||||
return Boolean(this.preferences.hiddenMetrics?.includes(resource));
|
||||
}
|
||||
|
||||
get nodeShellImage(): string {
|
||||
return this.preferences?.nodeShellImage || initialNodeShellImage;
|
||||
}
|
||||
|
||||
get imagePullSecret(): string | undefined {
|
||||
return this.preferences?.imagePullSecret;
|
||||
}
|
||||
|
||||
isInLocalKubeconfig() {
|
||||
return this.kubeConfigPath.startsWith(this.dependencies.directoryForKubeConfigs);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { ClusterConfigData, ClusterModel } from "../cluster-types";
|
||||
import type { Cluster } from "./cluster";
|
||||
|
||||
export type CreateCluster = (model: ClusterModel, configData: ClusterConfigData) => Cluster;
|
||||
|
||||
export const createClusterInjectionToken = getInjectionToken<CreateCluster>({
|
||||
id: "create-cluster-token",
|
||||
});
|
||||
@@ -5,25 +5,25 @@
|
||||
import type { KubeConfig } from "@kubernetes/client-node";
|
||||
import { CoreV1Api } from "@kubernetes/client-node";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { isDefined } from "../utils";
|
||||
import { isDefined } from "@k8slens/utilities";
|
||||
|
||||
export type ListNamespaces = () => Promise<string[]>;
|
||||
|
||||
export function listNamespaces(config: KubeConfig): ListNamespaces {
|
||||
const coreApi = config.makeApiClient(CoreV1Api);
|
||||
export type CreateListNamespaces = (config: KubeConfig) => ListNamespaces;
|
||||
|
||||
return async () => {
|
||||
const { body: { items }} = await coreApi.listNamespace();
|
||||
const createListNamespacesInjectable = getInjectable({
|
||||
id: "create-list-namespaces",
|
||||
instantiate: (): CreateListNamespaces => (config) => {
|
||||
const coreApi = config.makeApiClient(CoreV1Api);
|
||||
|
||||
return items
|
||||
.map(ns => ns.metadata?.name)
|
||||
.filter(isDefined);
|
||||
};
|
||||
}
|
||||
return async () => {
|
||||
const { body: { items }} = await coreApi.listNamespace();
|
||||
|
||||
const listNamespacesInjectable = getInjectable({
|
||||
id: "list-namespaces",
|
||||
instantiate: () => listNamespaces,
|
||||
return items
|
||||
.map(ns => ns.metadata?.name)
|
||||
.filter(isDefined);
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default listNamespacesInjectable;
|
||||
export default createListNamespacesInjectable;
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { KubeConfig } from "@kubernetes/client-node";
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import type { Cluster } from "./cluster";
|
||||
import loadConfigFromFileInjectable from "../kube-helpers/load-config-from-file.injectable";
|
||||
import type { ConfigResult } from "../kube-helpers";
|
||||
|
||||
export interface LoadKubeconfig {
|
||||
(fullResult?: false): Promise<KubeConfig>;
|
||||
(fullResult: true): Promise<ConfigResult>;
|
||||
}
|
||||
|
||||
const loadKubeconfigInjectable = getInjectable({
|
||||
id: "load-kubeconfig",
|
||||
instantiate: (di, cluster) => {
|
||||
const loadConfigFromFile = di.inject(loadConfigFromFileInjectable);
|
||||
|
||||
return (async (fullResult = false) => {
|
||||
const result = await loadConfigFromFile(cluster.kubeConfigPath.get());
|
||||
|
||||
if (fullResult) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return result.config;
|
||||
}) as LoadKubeconfig;
|
||||
},
|
||||
lifecycle: lifecycleEnum.keyedSingleton({
|
||||
getInstanceKey: (di, cluster: Cluster) => cluster.id,
|
||||
}),
|
||||
});
|
||||
|
||||
export default loadKubeconfigInjectable;
|
||||
@@ -47,9 +47,9 @@ const requestNamespaceListPermissionsForInjectable = getInjectable({
|
||||
const { resourceRules } = status;
|
||||
|
||||
return (resource) => {
|
||||
const resourceRule = resourceRules.find(({
|
||||
apiGroups = [],
|
||||
resources = [],
|
||||
const rules = resourceRules.filter(({
|
||||
apiGroups = ["*"],
|
||||
resources = ["*"],
|
||||
}) => {
|
||||
const isAboutRelevantApiGroup = apiGroups.includes("*") || apiGroups.includes(resource.group);
|
||||
const isAboutResource = resources.includes("*") || resources.includes(resource.apiName);
|
||||
@@ -57,13 +57,7 @@ const requestNamespaceListPermissionsForInjectable = getInjectable({
|
||||
return isAboutRelevantApiGroup && isAboutResource;
|
||||
});
|
||||
|
||||
if (!resourceRule) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const { verbs } = resourceRule;
|
||||
|
||||
return verbs.includes("*") || verbs.includes("list");
|
||||
return rules.some(({ verbs }) => verbs.includes("*") || verbs.includes("list"));
|
||||
};
|
||||
} catch (error) {
|
||||
logger.error(`[AUTHORIZATION-NAMESPACE-REVIEW]: failed to create subject rules review`, { namespace, error });
|
||||
|
||||
@@ -0,0 +1,336 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { V1SubjectRulesReviewStatus } from "@kubernetes/client-node";
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import { getDiForUnitTesting } from "../../main/getDiForUnitTesting";
|
||||
import type { RequestNamespaceListPermissionsFor } from "./request-namespace-list-permissions.injectable";
|
||||
import requestNamespaceListPermissionsForInjectable from "./request-namespace-list-permissions.injectable";
|
||||
|
||||
const createStubProxyConfig = (statusResponse: Promise<{ body: { status: V1SubjectRulesReviewStatus }}>) => ({
|
||||
makeApiClient: () => ({
|
||||
createSelfSubjectRulesReview: (): Promise<{ body: { status: V1SubjectRulesReviewStatus }}> => statusResponse,
|
||||
}),
|
||||
});
|
||||
|
||||
describe("requestNamespaceListPermissions", () => {
|
||||
let di: DiContainer;
|
||||
let requestNamespaceListPermissions: RequestNamespaceListPermissionsFor;
|
||||
|
||||
beforeEach(() => {
|
||||
di = getDiForUnitTesting();
|
||||
requestNamespaceListPermissions = di.inject(requestNamespaceListPermissionsForInjectable);
|
||||
});
|
||||
|
||||
describe("when api returns incomplete data", () => {
|
||||
it("returns truthy function", async () => {
|
||||
const requestPermissions = requestNamespaceListPermissions(createStubProxyConfig(
|
||||
new Promise((resolve) => resolve({
|
||||
body: {
|
||||
status: {
|
||||
incomplete: true,
|
||||
resourceRules: [],
|
||||
nonResourceRules: [],
|
||||
},
|
||||
},
|
||||
})),
|
||||
) as any);
|
||||
|
||||
const permissionCheck = await requestPermissions("irrelevant-namespace");
|
||||
|
||||
expect(permissionCheck({
|
||||
apiName: "pods",
|
||||
group: "",
|
||||
kind: "Pod",
|
||||
namespaced: true,
|
||||
})).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("when api rejects", () => {
|
||||
it("returns truthy function", async () => {
|
||||
const requestPermissions = requestNamespaceListPermissions(createStubProxyConfig(
|
||||
new Promise((resolve, reject) => reject("unknown error")),
|
||||
) as any);
|
||||
|
||||
const permissionCheck = await requestPermissions("irrelevant-namespace");
|
||||
|
||||
expect(permissionCheck({
|
||||
apiName: "pods",
|
||||
group: "",
|
||||
kind: "Pod",
|
||||
namespaced: true,
|
||||
})).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("when first resourceRule has all permissions for everything", () => {
|
||||
it("return truthy function", async () => {
|
||||
const requestPermissions = requestNamespaceListPermissions(createStubProxyConfig(
|
||||
new Promise((resolve) => resolve({
|
||||
body: {
|
||||
status: {
|
||||
incomplete: false,
|
||||
resourceRules: [
|
||||
{
|
||||
apiGroups: ["*"],
|
||||
verbs: ["*"],
|
||||
},
|
||||
{
|
||||
apiGroups: ["*"],
|
||||
verbs: ["get"],
|
||||
},
|
||||
],
|
||||
nonResourceRules: [],
|
||||
},
|
||||
},
|
||||
})),
|
||||
) as any);
|
||||
|
||||
const permissionCheck = await requestPermissions("irrelevant-namespace");
|
||||
|
||||
expect(permissionCheck({
|
||||
apiName: "pods",
|
||||
group: "",
|
||||
kind: "Pod",
|
||||
namespaced: true,
|
||||
})).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("when first resourceRule has list permissions for everything", () => {
|
||||
it("return truthy function", async () => {
|
||||
const requestPermissions = requestNamespaceListPermissions(createStubProxyConfig(
|
||||
new Promise((resolve) => resolve({
|
||||
body: {
|
||||
status: {
|
||||
incomplete: false,
|
||||
resourceRules: [
|
||||
{
|
||||
apiGroups: ["*"],
|
||||
verbs: ["list"],
|
||||
},
|
||||
{
|
||||
apiGroups: ["*"],
|
||||
verbs: ["get"],
|
||||
},
|
||||
],
|
||||
nonResourceRules: [],
|
||||
},
|
||||
},
|
||||
})),
|
||||
) as any);
|
||||
|
||||
const permissionCheck = await requestPermissions("irrelevant-namespace");
|
||||
|
||||
expect(permissionCheck({
|
||||
apiName: "pods",
|
||||
group: "",
|
||||
kind: "Pod",
|
||||
namespaced: true,
|
||||
})).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("when first resourceRule has list permissions for asked resource", () => {
|
||||
it("return truthy function", async () => {
|
||||
const requestPermissions = requestNamespaceListPermissions(createStubProxyConfig(
|
||||
new Promise((resolve) => resolve({
|
||||
body: {
|
||||
status: {
|
||||
incomplete: false,
|
||||
resourceRules: [
|
||||
{
|
||||
apiGroups: [""],
|
||||
resources: ["pods"],
|
||||
verbs: ["list"],
|
||||
},
|
||||
{
|
||||
apiGroups: ["*"],
|
||||
verbs: ["get"],
|
||||
},
|
||||
],
|
||||
nonResourceRules: [],
|
||||
},
|
||||
},
|
||||
})),
|
||||
) as any);
|
||||
|
||||
const permissionCheck = await requestPermissions("irrelevant-namespace");
|
||||
|
||||
expect(permissionCheck({
|
||||
apiName: "pods",
|
||||
group: "",
|
||||
kind: "Pod",
|
||||
namespaced: true,
|
||||
})).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("when last resourceRule has all permissions for everything", () => {
|
||||
it("return truthy function", async () => {
|
||||
const requestPermissions = requestNamespaceListPermissions(createStubProxyConfig(
|
||||
new Promise((resolve) => resolve({
|
||||
body: {
|
||||
status: {
|
||||
incomplete: false,
|
||||
resourceRules: [
|
||||
{
|
||||
apiGroups: ["*"],
|
||||
verbs: ["get"],
|
||||
},
|
||||
{
|
||||
apiGroups: ["*"],
|
||||
verbs: ["*"],
|
||||
},
|
||||
],
|
||||
nonResourceRules: [],
|
||||
},
|
||||
},
|
||||
})),
|
||||
) as any);
|
||||
|
||||
const permissionCheck = await requestPermissions("irrelevant-namespace");
|
||||
|
||||
expect(permissionCheck({
|
||||
apiName: "pods",
|
||||
group: "",
|
||||
kind: "Pod",
|
||||
namespaced: true,
|
||||
})).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("when last resourceRule has list permissions for everything", () => {
|
||||
it("return truthy function", async () => {
|
||||
const requestPermissions = requestNamespaceListPermissions(createStubProxyConfig(
|
||||
new Promise((resolve) => resolve({
|
||||
body: {
|
||||
status: {
|
||||
incomplete: false,
|
||||
resourceRules: [
|
||||
{
|
||||
apiGroups: ["*"],
|
||||
verbs: ["get"],
|
||||
},
|
||||
{
|
||||
apiGroups: ["*"],
|
||||
verbs: ["list"],
|
||||
},
|
||||
],
|
||||
nonResourceRules: [],
|
||||
},
|
||||
},
|
||||
})),
|
||||
) as any);
|
||||
|
||||
const permissionCheck = await requestPermissions("irrelevant-namespace");
|
||||
|
||||
expect(permissionCheck({
|
||||
apiName: "pods",
|
||||
group: "",
|
||||
kind: "Pod",
|
||||
namespaced: true,
|
||||
})).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("when last resourceRule has list permissions for asked resource", () => {
|
||||
it("return truthy function", async () => {
|
||||
const requestPermissions = requestNamespaceListPermissions(createStubProxyConfig(
|
||||
new Promise((resolve) => resolve({
|
||||
body: {
|
||||
status: {
|
||||
incomplete: false,
|
||||
resourceRules: [
|
||||
{
|
||||
apiGroups: ["*"],
|
||||
verbs: ["get"],
|
||||
},
|
||||
{
|
||||
apiGroups: [""],
|
||||
resources: ["pods"],
|
||||
verbs: ["list"],
|
||||
},
|
||||
],
|
||||
nonResourceRules: [],
|
||||
},
|
||||
},
|
||||
})),
|
||||
) as any);
|
||||
|
||||
const permissionCheck = await requestPermissions("irrelevant-namespace");
|
||||
|
||||
expect(permissionCheck({
|
||||
apiName: "pods",
|
||||
group: "",
|
||||
kind: "Pod",
|
||||
namespaced: true,
|
||||
})).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("when resourceRules has matching resource without list verb", () => {
|
||||
it("return falsy function", async () => {
|
||||
const requestPermissions = requestNamespaceListPermissions(createStubProxyConfig(
|
||||
new Promise((resolve) => resolve({
|
||||
body: {
|
||||
status: {
|
||||
incomplete: false,
|
||||
resourceRules: [
|
||||
{
|
||||
apiGroups: [""],
|
||||
resources: ["pods"],
|
||||
verbs: ["get"],
|
||||
},
|
||||
],
|
||||
nonResourceRules: [],
|
||||
},
|
||||
},
|
||||
})),
|
||||
) as any);
|
||||
|
||||
const permissionCheck = await requestPermissions("irrelevant-namespace");
|
||||
|
||||
expect(permissionCheck({
|
||||
apiName: "pods",
|
||||
group: "",
|
||||
kind: "Pod",
|
||||
namespaced: true,
|
||||
})).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("when resourceRules has no matching resource with list verb", () => {
|
||||
it("return falsy function", async () => {
|
||||
const requestPermissions = requestNamespaceListPermissions(createStubProxyConfig(
|
||||
new Promise((resolve) => resolve({
|
||||
body: {
|
||||
status: {
|
||||
incomplete: false,
|
||||
resourceRules: [
|
||||
{
|
||||
apiGroups: [""],
|
||||
resources: ["services"],
|
||||
verbs: ["list"],
|
||||
},
|
||||
],
|
||||
nonResourceRules: [],
|
||||
},
|
||||
},
|
||||
})),
|
||||
) as any);
|
||||
|
||||
const permissionCheck = await requestPermissions("irrelevant-namespace");
|
||||
|
||||
expect(permissionCheck({
|
||||
apiName: "pods",
|
||||
group: "",
|
||||
kind: "Pod",
|
||||
namespaced: true,
|
||||
})).toBeFalsy();
|
||||
});
|
||||
});
|
||||
});
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverride } from "../test-utils/get-global-override";
|
||||
import { getGlobalOverride } from "@k8slens/test-utils";
|
||||
import initializeSentryReportingWithInjectable from "./initialize-sentry-reporting.injectable";
|
||||
|
||||
export default getGlobalOverride(initializeSentryReportingWithInjectable, () => () => {});
|
||||
@@ -4,14 +4,14 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { RequestInit, Response } from "@k8slens/node-fetch";
|
||||
import type { AsyncResult } from "../utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import fetchInjectable from "./fetch.injectable";
|
||||
|
||||
export interface DownloadBinaryOptions {
|
||||
signal?: AbortSignal | null | undefined;
|
||||
}
|
||||
|
||||
export type DownloadBinary = (url: string, opts?: DownloadBinaryOptions) => Promise<AsyncResult<Buffer, string>>;
|
||||
export type DownloadBinary = (url: string, opts?: DownloadBinaryOptions) => AsyncResult<Buffer, string>;
|
||||
|
||||
const downloadBinaryInjectable = getInjectable({
|
||||
id: "download-binary",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { AsyncResult } from "../../utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import type { Fetch } from "../fetch.injectable";
|
||||
import type { RequestInit, Response } from "@k8slens/node-fetch";
|
||||
|
||||
@@ -10,7 +10,7 @@ export interface DownloadJsonOptions {
|
||||
signal?: AbortSignal | null | undefined;
|
||||
}
|
||||
|
||||
export type DownloadJson = (url: string, opts?: DownloadJsonOptions) => Promise<AsyncResult<unknown, string>>;
|
||||
export type DownloadJson = (url: string, opts?: DownloadJsonOptions) => AsyncResult<unknown, string>;
|
||||
|
||||
export const downloadJsonWith = (fetch: Fetch): DownloadJson => async (url, opts) => {
|
||||
let result: Response;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverrideForFunction } from "../test-utils/get-global-override-for-function";
|
||||
import { getGlobalOverrideForFunction } from "@k8slens/test-utils";
|
||||
import fetchInjectable from "./fetch.injectable";
|
||||
|
||||
export default getGlobalOverrideForFunction(fetchInjectable);
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverrideForFunction } from "../test-utils/get-global-override-for-function";
|
||||
import { getGlobalOverrideForFunction } from "@k8slens/test-utils";
|
||||
import lensFetchInjectable from "./lens-fetch.injectable";
|
||||
|
||||
export default getGlobalOverrideForFunction(lensFetchInjectable);
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { shouldShowResourceInjectionToken } from "../../../../../cluster-store/allowed-resources-injection-token";
|
||||
import { computedOr } from "../../../../../utils/computed-or";
|
||||
import { computedOr } from "@k8slens/utilities";
|
||||
import { frontEndRouteInjectionToken } from "../../../../front-end-route-injection-token";
|
||||
|
||||
const ingressesRouteInjectable = getInjectable({
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ import { pipeline } from "@ogre-tools/fp";
|
||||
|
||||
describe("verify-that-all-routes-have-component", () => {
|
||||
it("verify that routes have route component", () => {
|
||||
const rendererDi = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
const rendererDi = getDiForUnitTesting();
|
||||
|
||||
rendererDi.override(clusterStoreInjectable, () => ({
|
||||
getById: () => null,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverride } from "../test-utils/get-global-override";
|
||||
import { getGlobalOverride } from "@k8slens/test-utils";
|
||||
import copyInjectable from "./copy.injectable";
|
||||
|
||||
export default getGlobalOverride(copyInjectable, () => async () => {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverrideForFunction } from "../test-utils/get-global-override-for-function";
|
||||
import { getGlobalOverrideForFunction } from "@k8slens/test-utils";
|
||||
import execFileInjectable from "./exec-file.injectable";
|
||||
|
||||
export default getGlobalOverrideForFunction(execFileInjectable);
|
||||
@@ -5,14 +5,14 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { ExecFileException, ExecFileOptions } from "child_process";
|
||||
import { execFile } from "child_process";
|
||||
import type { AsyncResult } from "../utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
|
||||
export type ExecFileError = ExecFileException & { stderr: string };
|
||||
|
||||
export interface ExecFile {
|
||||
(filePath: string): Promise<AsyncResult<string, ExecFileError>>;
|
||||
(filePath: string, argsOrOptions: string[] | ExecFileOptions): Promise<AsyncResult<string, ExecFileError>>;
|
||||
(filePath: string, args: string[], options: ExecFileOptions): Promise<AsyncResult<string, ExecFileError>>;
|
||||
(filePath: string): AsyncResult<string, ExecFileError>;
|
||||
(filePath: string, argsOrOptions: string[] | ExecFileOptions): AsyncResult<string, ExecFileError>;
|
||||
(filePath: string, args: string[], options: ExecFileOptions): AsyncResult<string, ExecFileError>;
|
||||
}
|
||||
|
||||
const execFileInjectable = getInjectable({
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverride } from "../test-utils/get-global-override";
|
||||
import { getGlobalOverride } from "@k8slens/test-utils";
|
||||
import extractTarInjectable from "./extract-tar.injectable";
|
||||
|
||||
export default getGlobalOverride(extractTarInjectable, () => async () => {
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { ReadOptions } from "fs-extra";
|
||||
import fse from "fs-extra";
|
||||
|
||||
/**
|
||||
* NOTE: Add corrisponding a corrisponding override of this injecable in `src/test-utils/override-fs-with-fakes.ts`
|
||||
* NOTE: Add corresponding override of this injectable in `src/test-utils/override-fs-with-fakes.ts`
|
||||
*/
|
||||
const fsInjectable = getInjectable({
|
||||
id: "fs",
|
||||
@@ -21,6 +21,7 @@ const fsInjectable = getInjectable({
|
||||
rm,
|
||||
access,
|
||||
stat,
|
||||
unlink,
|
||||
},
|
||||
ensureDir,
|
||||
ensureDirSync,
|
||||
@@ -56,6 +57,7 @@ const fsInjectable = getInjectable({
|
||||
ensureDirSync,
|
||||
createReadStream,
|
||||
stat,
|
||||
unlink,
|
||||
};
|
||||
},
|
||||
causesSideEffects: true,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverride } from "../test-utils/get-global-override";
|
||||
import { getGlobalOverride } from "@k8slens/test-utils";
|
||||
import lstatInjectable from "./lstat.injectable";
|
||||
|
||||
export default getGlobalOverride(lstatInjectable, () => async () => {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverride } from "../test-utils/get-global-override";
|
||||
import { getGlobalOverride } from "@k8slens/test-utils";
|
||||
import readDirectoryInjectable from "./read-directory.injectable";
|
||||
|
||||
export default getGlobalOverride(readDirectoryInjectable, () => async () => {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverride } from "../test-utils/get-global-override";
|
||||
import { getGlobalOverride } from "@k8slens/test-utils";
|
||||
import removePathInjectable from "./remove.injectable";
|
||||
|
||||
export default getGlobalOverride(removePathInjectable, () => async () => {
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import fsInjectable from "./fs.injectable";
|
||||
|
||||
export type Unlink = (path: string) => Promise<void>;
|
||||
|
||||
const unlinkInjectable = getInjectable({
|
||||
id: "unlink",
|
||||
instantiate: (di): Unlink => di.inject(fsInjectable).unlink,
|
||||
});
|
||||
|
||||
export default unlinkInjectable;
|
||||
@@ -3,13 +3,13 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { AsyncResult } from "../utils/async-result";
|
||||
import { isErrnoException } from "../utils";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import { isErrnoException } from "@k8slens/utilities";
|
||||
import type { Stats } from "fs-extra";
|
||||
import { lowerFirst } from "lodash/fp";
|
||||
import statInjectable from "./stat.injectable";
|
||||
|
||||
export type ValidateDirectory = (path: string) => Promise<AsyncResult<undefined>>;
|
||||
export type ValidateDirectory = (path: string) => AsyncResult<undefined>;
|
||||
|
||||
function getUserReadableFileType(stats: Stats): string {
|
||||
if (stats.isFile()) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getGlobalOverride } from "../../test-utils/get-global-override";
|
||||
import { getGlobalOverride } from "@k8slens/test-utils";
|
||||
import watchInjectable from "./watch.injectable";
|
||||
|
||||
export default getGlobalOverride(watchInjectable, () => () => {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { watch } from "chokidar";
|
||||
import type { Stats } from "fs";
|
||||
import type TypedEventEmitter from "typed-emitter";
|
||||
import type { SingleOrMany } from "../../utils";
|
||||
import type { SingleOrMany } from "@k8slens/utilities";
|
||||
|
||||
export interface AlwaysStatWatcherEvents {
|
||||
add: (path: string, stats: Stats) => void;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverride } from "../test-utils/get-global-override";
|
||||
import { getGlobalOverride } from "@k8slens/test-utils";
|
||||
import writeFileInjectable from "./write-file.injectable";
|
||||
|
||||
export default getGlobalOverride(writeFileInjectable, () => async () => {
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
|
||||
import assert from "assert";
|
||||
import path from "path";
|
||||
import { getGlobalOverride } from "../test-utils/get-global-override";
|
||||
import { getGlobalOverride } from "@k8slens/test-utils";
|
||||
import getConfigurationFileModelInjectable from "./get-configuration-file-model.injectable";
|
||||
import type Config from "conf";
|
||||
import readJsonSyncInjectable from "../fs/read-json-sync.injectable";
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { HelmRepo } from "./helm-repo";
|
||||
import type { AsyncResult } from "../utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token";
|
||||
|
||||
export type AddHelmRepositoryChannel = RequestChannel<HelmRepo, AsyncResult<void, string>>;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { HelmRepo } from "./helm-repo";
|
||||
import type { AsyncResult } from "../utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token";
|
||||
|
||||
export type GetActiveHelmRepositoriesChannel = RequestChannel<void, AsyncResult<HelmRepo[]>>;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { AsyncResult } from "../utils/async-result";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import type { RequestChannel } from "../utils/channel/request-channel-listener-injection-token";
|
||||
import type { HelmRepo } from "./helm-repo";
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
*/
|
||||
|
||||
import * as uuid from "uuid";
|
||||
import type { Tuple } from "../utils";
|
||||
import { tuple } from "../utils";
|
||||
import type { Tuple } from "@k8slens/utilities";
|
||||
import { tuple } from "@k8slens/utilities";
|
||||
|
||||
export interface HotbarItem {
|
||||
entity: {
|
||||
|
||||
@@ -15,7 +15,7 @@ describe("InitializableState tests", () => {
|
||||
let di: DiContainer;
|
||||
|
||||
beforeEach(() => {
|
||||
di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
di = getDiForUnitTesting();
|
||||
});
|
||||
|
||||
describe("when created", () => {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverrideForFunction } from "../test-utils/get-global-override-for-function";
|
||||
import { getGlobalOverrideForFunction } from "@k8slens/test-utils";
|
||||
import broadcastMessageInjectable from "./broadcast-message.injectable";
|
||||
|
||||
export default getGlobalOverrideForFunction(broadcastMessageInjectable);
|
||||
@@ -11,7 +11,7 @@ import { ipcMain, ipcRenderer, webContents } from "electron";
|
||||
import { toJS } from "../utils/toJS";
|
||||
import type { ClusterFrameInfo } from "../cluster-frames";
|
||||
import { clusterFrameMap } from "../cluster-frames";
|
||||
import type { Disposer } from "../utils";
|
||||
import type { Disposer } from "@k8slens/utilities";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import ipcRendererInjectable from "../../renderer/utils/channel/ipc-renderer.injectable";
|
||||
import loggerInjectable from "../logger.injectable";
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import autoBind from "auto-bind";
|
||||
import orderBy from "lodash/orderBy";
|
||||
import { autoBind } from "./utils";
|
||||
import { action, computed, observable, when, makeObservable } from "mobx";
|
||||
|
||||
export interface ItemObject {
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
*/
|
||||
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import createClusterInjectable from "../../../main/create-cluster/create-cluster.injectable";
|
||||
import clusterFrameContextForNamespacedResourcesInjectable from "../../../renderer/cluster-frame-context/for-namespaced-resources.injectable";
|
||||
import hostedClusterInjectable from "../../../renderer/cluster-frame-context/hosted-cluster.injectable";
|
||||
import { getDiForUnitTesting } from "../../../renderer/getDiForUnitTesting";
|
||||
@@ -19,6 +18,10 @@ import { KubeObject } from "../kube-object";
|
||||
import { KubeObjectStore } from "../kube-object.store";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import { KubeApi as ExternalKubeApi } from "../../../extensions/common-api/k8s-api";
|
||||
import { Cluster } from "../../cluster/cluster";
|
||||
|
||||
class TestApi extends KubeApi<KubeObject> {
|
||||
protected async checkPreferredVersion() {
|
||||
return;
|
||||
@@ -34,15 +37,13 @@ describe("ApiManager", () => {
|
||||
let di: DiContainer;
|
||||
|
||||
beforeEach(() => {
|
||||
di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
di = getDiForUnitTesting();
|
||||
|
||||
di.override(directoryForUserDataInjectable, () => "/some-user-store-path");
|
||||
di.override(directoryForKubeConfigsInjectable, () => "/some-kube-configs");
|
||||
di.override(storesAndApisCanBeCreatedInjectable, () => true);
|
||||
|
||||
const createCluster = di.inject(createClusterInjectable);
|
||||
|
||||
di.override(hostedClusterInjectable, () => createCluster({
|
||||
di.override(hostedClusterInjectable, () => new Cluster({
|
||||
contextName: "some-context-name",
|
||||
id: "some-cluster-id",
|
||||
kubeConfigPath: "/some-path-to-a-kubeconfig",
|
||||
@@ -54,7 +55,7 @@ describe("ApiManager", () => {
|
||||
});
|
||||
|
||||
describe("registerApi", () => {
|
||||
it("re-register store if apiBase changed", async () => {
|
||||
it("re-register store if apiBase changed", () => {
|
||||
const apiBase = "apis/v1/foo";
|
||||
const fallbackApiBase = "/apis/extensions/v1beta1/foo";
|
||||
const kubeApi = new TestApi({
|
||||
@@ -72,21 +73,48 @@ describe("ApiManager", () => {
|
||||
logger: di.inject(loggerInjectable),
|
||||
}, kubeApi);
|
||||
|
||||
apiManager.registerApi(apiBase, kubeApi);
|
||||
apiManager.registerApi(kubeApi);
|
||||
|
||||
// Define to use test api for ingress store
|
||||
Object.defineProperty(kubeStore, "api", { value: kubeApi });
|
||||
apiManager.registerStore(kubeStore, [kubeApi]);
|
||||
apiManager.registerStore(kubeStore);
|
||||
|
||||
// Test that store is returned with original apiBase
|
||||
expect(apiManager.getStore(kubeApi)).toBe(kubeStore);
|
||||
|
||||
// Change apiBase similar as checkPreferredVersion does
|
||||
Object.defineProperty(kubeApi, "apiBase", { value: fallbackApiBase });
|
||||
apiManager.registerApi(fallbackApiBase, kubeApi);
|
||||
apiManager.registerApi(kubeApi);
|
||||
|
||||
// Test that store is returned with new apiBase
|
||||
expect(apiManager.getStore(kubeApi)).toBe(kubeStore);
|
||||
});
|
||||
});
|
||||
|
||||
describe("technical tests for autorun", () => {
|
||||
it("given two extensions register apis with the same apibase, settle into using the second", () => {
|
||||
const apiBase = "/apis/aquasecurity.github.io/v1alpha1/vulnerabilityreports";
|
||||
const firstApi = Object.assign(new ExternalKubeApi({
|
||||
objectConstructor: KubeObject,
|
||||
apiBase,
|
||||
kind: "VulnerabilityReport",
|
||||
}), {
|
||||
myField: 1,
|
||||
});
|
||||
const secondApi = Object.assign(new ExternalKubeApi({
|
||||
objectConstructor: KubeObject,
|
||||
apiBase,
|
||||
kind: "VulnerabilityReport",
|
||||
}), {
|
||||
myField: 2,
|
||||
});
|
||||
|
||||
void firstApi;
|
||||
void secondApi;
|
||||
|
||||
expect(apiManager.getApi(apiBase)).toMatchObject({
|
||||
myField: 2,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -15,7 +15,7 @@ describe("DeploymentApi", () => {
|
||||
let kubeJsonApi: jest.Mocked<KubeJsonApi>;
|
||||
|
||||
beforeEach(() => {
|
||||
const di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
const di = getDiForUnitTesting();
|
||||
|
||||
di.override(storesAndApisCanBeCreatedInjectable, () => true);
|
||||
kubeJsonApi = {
|
||||
|
||||
@@ -10,12 +10,11 @@ import type { Fetch } from "../../fetch/fetch.injectable";
|
||||
import fetchInjectable from "../../fetch/fetch.injectable";
|
||||
import type { AsyncFnMock } from "@async-fn/jest";
|
||||
import asyncFn from "@async-fn/jest";
|
||||
import { flushPromises } from "../../test-utils/flush-promises";
|
||||
import { flushPromises } from "@k8slens/test-utils";
|
||||
import setupAutoRegistrationInjectable from "../../../renderer/before-frame-starts/runnables/setup-auto-registration.injectable";
|
||||
import { createMockResponseFromString } from "../../../test-utils/mock-responses";
|
||||
import storesAndApisCanBeCreatedInjectable from "../../../renderer/stores-apis-can-be-created.injectable";
|
||||
import directoryForUserDataInjectable from "../../app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
import createClusterInjectable from "../../../main/create-cluster/create-cluster.injectable";
|
||||
import hostedClusterInjectable from "../../../renderer/cluster-frame-context/hosted-cluster.injectable";
|
||||
import directoryForKubeConfigsInjectable from "../../app-paths/directory-for-kube-configs/directory-for-kube-configs.injectable";
|
||||
import apiManagerInjectable from "../api-manager/manager.injectable";
|
||||
@@ -23,6 +22,7 @@ import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import ingressApiInjectable from "../endpoints/ingress.api.injectable";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
import { Cluster } from "../../cluster/cluster";
|
||||
|
||||
describe("KubeApi", () => {
|
||||
let fetchMock: AsyncFnMock<Fetch>;
|
||||
@@ -30,7 +30,7 @@ describe("KubeApi", () => {
|
||||
let di: DiContainer;
|
||||
|
||||
beforeEach(async () => {
|
||||
di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
di = getDiForUnitTesting();
|
||||
|
||||
fetchMock = asyncFn();
|
||||
di.override(fetchInjectable, () => fetchMock);
|
||||
@@ -39,9 +39,7 @@ describe("KubeApi", () => {
|
||||
di.override(directoryForKubeConfigsInjectable, () => "/some-kube-configs");
|
||||
di.override(storesAndApisCanBeCreatedInjectable, () => true);
|
||||
|
||||
const createCluster = di.inject(createClusterInjectable);
|
||||
|
||||
di.override(hostedClusterInjectable, () => createCluster({
|
||||
di.override(hostedClusterInjectable, () => new Cluster({
|
||||
contextName: "some-context-name",
|
||||
id: "some-cluster-id",
|
||||
kubeConfigPath: "/some-path-to-a-kubeconfig",
|
||||
@@ -121,7 +119,7 @@ describe("KubeApi", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
describe("when resource request fufills with a resource", () => {
|
||||
describe("when resource request fulfills with a resource", () => {
|
||||
beforeEach(async () => {
|
||||
await fetchMock.resolveSpecific(
|
||||
["https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1"],
|
||||
@@ -283,7 +281,7 @@ describe("KubeApi", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("when resource request fufills with no resource", () => {
|
||||
describe("when resource request fulfills with no resource", () => {
|
||||
beforeEach(async () => {
|
||||
await fetchMock.resolveSpecific(
|
||||
["https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1"],
|
||||
@@ -307,7 +305,7 @@ describe("KubeApi", () => {
|
||||
|
||||
|
||||
|
||||
describe("when resource request fufills with a resource", () => {
|
||||
describe("when resource request fulfills with a resource", () => {
|
||||
beforeEach(async () => {
|
||||
await fetchMock.resolveSpecific(
|
||||
["https://127.0.0.1:12345/api-kube/apis/networking.k8s.io/v1beta1"],
|
||||
@@ -509,7 +507,7 @@ describe("KubeApi", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
describe("when resource request fufills with a resource", () => {
|
||||
describe("when resource request fulfills with a resource", () => {
|
||||
beforeEach(async () => {
|
||||
await fetchMock.resolveSpecific(
|
||||
["https://127.0.0.1:12345/api-kube/apis/extensions"],
|
||||
|
||||
@@ -15,7 +15,7 @@ import type { CreateKubeApiForRemoteCluster } from "../create-kube-api-for-remot
|
||||
import createKubeApiForRemoteClusterInjectable from "../create-kube-api-for-remote-cluster.injectable";
|
||||
import type { AsyncFnMock } from "@async-fn/jest";
|
||||
import asyncFn from "@async-fn/jest";
|
||||
import { flushPromises } from "../../test-utils/flush-promises";
|
||||
import { flushPromises } from "@k8slens/test-utils";
|
||||
import createKubeJsonApiInjectable from "../create-kube-json-api.injectable";
|
||||
import type { IKubeWatchEvent } from "../kube-watch-event";
|
||||
import type { KubeJsonApiDataFor } from "../kube-object";
|
||||
@@ -24,7 +24,6 @@ import setupAutoRegistrationInjectable from "../../../renderer/before-frame-star
|
||||
import { createMockResponseFromStream, createMockResponseFromString } from "../../../test-utils/mock-responses";
|
||||
import storesAndApisCanBeCreatedInjectable from "../../../renderer/stores-apis-can-be-created.injectable";
|
||||
import directoryForUserDataInjectable from "../../app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
import createClusterInjectable from "../../../main/create-cluster/create-cluster.injectable";
|
||||
import hostedClusterInjectable from "../../../renderer/cluster-frame-context/hosted-cluster.injectable";
|
||||
import directoryForKubeConfigsInjectable from "../../app-paths/directory-for-kube-configs/directory-for-kube-configs.injectable";
|
||||
import apiKubeInjectable from "../../../renderer/k8s/api-kube.injectable";
|
||||
@@ -36,21 +35,20 @@ import namespaceApiInjectable from "../endpoints/namespace.api.injectable";
|
||||
// NOTE: this is fine because we are testing something that only exported
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import { PodsApi } from "../../../extensions/common-api/k8s-api";
|
||||
import { Cluster } from "../../cluster/cluster";
|
||||
|
||||
describe("createKubeApiForRemoteCluster", () => {
|
||||
let createKubeApiForRemoteCluster: CreateKubeApiForRemoteCluster;
|
||||
let fetchMock: AsyncFnMock<Fetch>;
|
||||
|
||||
beforeEach(async () => {
|
||||
const di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
const di = getDiForUnitTesting();
|
||||
|
||||
di.override(directoryForUserDataInjectable, () => "/some-user-store-path");
|
||||
di.override(directoryForKubeConfigsInjectable, () => "/some-kube-configs");
|
||||
di.override(storesAndApisCanBeCreatedInjectable, () => true);
|
||||
|
||||
const createCluster = di.inject(createClusterInjectable);
|
||||
|
||||
di.override(hostedClusterInjectable, () => createCluster({
|
||||
di.override(hostedClusterInjectable, () => new Cluster({
|
||||
contextName: "some-context-name",
|
||||
id: "some-cluster-id",
|
||||
kubeConfigPath: "/some-path-to-a-kubeconfig",
|
||||
@@ -145,7 +143,7 @@ describe("KubeApi", () => {
|
||||
let di: DiContainer;
|
||||
|
||||
beforeEach(async () => {
|
||||
di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
di = getDiForUnitTesting();
|
||||
|
||||
di.override(directoryForUserDataInjectable, () => "/some-user-store-path");
|
||||
di.override(directoryForKubeConfigsInjectable, () => "/some-kube-configs");
|
||||
@@ -154,10 +152,9 @@ describe("KubeApi", () => {
|
||||
fetchMock = asyncFn();
|
||||
di.override(fetchInjectable, () => fetchMock);
|
||||
|
||||
const createCluster = di.inject(createClusterInjectable);
|
||||
const createKubeJsonApi = di.inject(createKubeJsonApiInjectable);
|
||||
|
||||
di.override(hostedClusterInjectable, () => createCluster({
|
||||
di.override(hostedClusterInjectable, () => new Cluster({
|
||||
contextName: "some-context-name",
|
||||
id: "some-cluster-id",
|
||||
kubeConfigPath: "/some-path-to-a-kubeconfig",
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { noop } from "../../utils";
|
||||
import { noop } from "@k8slens/utilities";
|
||||
import type { KubeApi } from "../kube-api";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { KubeObjectStoreLoadingParams } from "../kube-object.store";
|
||||
|
||||
@@ -15,7 +15,7 @@ describe("StatefulSetApi", () => {
|
||||
let kubeJsonApi: jest.Mocked<KubeJsonApi>;
|
||||
|
||||
beforeEach(() => {
|
||||
const di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
const di = getDiForUnitTesting();
|
||||
|
||||
di.override(storesAndApisCanBeCreatedInjectable, () => true);
|
||||
kubeJsonApi = {
|
||||
|
||||
@@ -10,7 +10,7 @@ import { autorun, action, observable } from "mobx";
|
||||
import type { KubeApi } from "../kube-api";
|
||||
import type { KubeObject, ObjectReference } from "../kube-object";
|
||||
import { parseKubeApi, createKubeApiURL } from "../kube-api-parse";
|
||||
import { chain, find } from "../../utils/iter";
|
||||
import { iter } from "@k8slens/utilities";
|
||||
|
||||
export type RegisterableStore<Store> = Store extends KubeObjectStore<any, any, any>
|
||||
? Store
|
||||
@@ -38,28 +38,31 @@ export class ApiManager {
|
||||
constructor(private readonly dependencies: Dependencies) {
|
||||
// NOTE: this is done to preserve the old behaviour of an API being discoverable using all previous apiBases
|
||||
autorun(() => {
|
||||
const apis = chain(this.dependencies.apis.get().values())
|
||||
const apis = iter.chain(this.dependencies.apis.get().values())
|
||||
.concat(this.externalApis.values());
|
||||
const removedApis = new Set(this.apis.values());
|
||||
const newState = new Map(this.apis);
|
||||
|
||||
for (const api of apis) {
|
||||
removedApis.delete(api);
|
||||
this.apis.set(api.apiBase, api);
|
||||
newState.set(api.apiBase, api);
|
||||
}
|
||||
|
||||
for (const api of removedApis) {
|
||||
for (const [apiBase, storedApi] of this.apis) {
|
||||
for (const [apiBase, storedApi] of newState) {
|
||||
if (storedApi === api) {
|
||||
this.apis.delete(apiBase);
|
||||
newState.delete(apiBase);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.apis.replace(newState);
|
||||
});
|
||||
}
|
||||
|
||||
getApi(pathOrCallback: string | FindApiCallback) {
|
||||
if (typeof pathOrCallback === "function") {
|
||||
return find(this.apis.values(), pathOrCallback);
|
||||
return iter.find(this.apis.values(), pathOrCallback);
|
||||
}
|
||||
|
||||
const { apiBase } = parseKubeApi(pathOrCallback);
|
||||
@@ -127,7 +130,7 @@ export class ApiManager {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return chain(this.dependencies.stores.get().values())
|
||||
return iter.chain(this.dependencies.stores.get().values())
|
||||
.concat(this.externalStores.values())
|
||||
.find(store => store.api.apiBase === api.apiBase);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import { KubeObject } from "../kube-object";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { autoBind } from "../../utils";
|
||||
import autoBind from "auto-bind";
|
||||
|
||||
export interface ConfigMapData extends KubeJsonApiData<KubeObjectMetadata<KubeObjectScope.Namespace>, void, void> {
|
||||
data?: Partial<Record<string, string>>;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import moment from "moment";
|
||||
import type { NamespaceScopedMetadata, ObjectReference } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { formatDuration } from "../../utils/formatDuration";
|
||||
import { formatDuration } from "@k8slens/utilities";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { JobTemplateSpec } from "./types/job-template-spec";
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import customResourcesRouteInjectable from "../../front-end-routing/routes/cluster/custom-resources/custom-resources/custom-resources-route.injectable";
|
||||
import { buildURL } from "../../utils/buildUrl";
|
||||
import { buildURL } from "@k8slens/utilities";
|
||||
import type { BaseKubeObjectCondition, ClusterScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
|
||||
@@ -10,7 +10,7 @@ import { KubeApi } from "../kube-api";
|
||||
import type { PodSpec } from "./pod.api";
|
||||
import type { KubeObjectStatus, LabelSelector, NamespaceScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { hasTypedProperty, isNumber, isObject } from "../../utils";
|
||||
import { hasTypedProperty, isNumber, isObject } from "@k8slens/utilities";
|
||||
|
||||
export class DeploymentApi extends KubeApi<Deployment> {
|
||||
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { autoBind } from "../../utils";
|
||||
import autoBind from "auto-bind";
|
||||
import type { KubeObjectMetadata, KubeObjectScope, NamespaceScopedMetadata, ObjectReference } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import moment from "moment";
|
||||
import type { KubeObjectMetadata, KubeObjectScope, ObjectReference } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { formatDuration } from "../../utils/formatDuration";
|
||||
import { formatDuration } from "@k8slens/utilities";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { autoBind, bifurcateArray } from "../../utils";
|
||||
import { array } from "@k8slens/utilities";
|
||||
import autoBind from "auto-bind";
|
||||
import Joi from "joi";
|
||||
|
||||
export interface RawHelmChart {
|
||||
@@ -263,7 +264,7 @@ export class HelmChart implements HelmChartData {
|
||||
return new HelmChart(result.value);
|
||||
}
|
||||
|
||||
const [actualErrors, unknownDetails] = bifurcateArray(result.error.details, ({ type }) => type === "object.unknown");
|
||||
const [actualErrors, unknownDetails] = array.bifurcate(result.error.details, ({ type }) => type === "object.unknown");
|
||||
|
||||
if (unknownDetails.length > 0) {
|
||||
console.warn("HelmChart data has unexpected fields", { original: data, unknownFields: unknownDetails.flatMap(d => d.path) });
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { RawHelmChart } from "../helm-charts.api";
|
||||
import { HelmChart } from "../helm-charts.api";
|
||||
import { isDefined } from "../../../utils";
|
||||
import { isDefined } from "@k8slens/utilities";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
export type RequestHelmCharts = () => Promise<HelmChart[]>;
|
||||
|
||||
+3
-3
@@ -3,13 +3,13 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { AsyncResult } from "../../../utils/async-result";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import { urlBuilderFor } from "@k8slens/utilities";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
const requestReadmeEndpoint = urlBuilderFor("/v2/charts/:repo/:name/readme");
|
||||
|
||||
export type RequestHelmChartReadme = (repo: string, name: string, version?: string) => Promise<AsyncResult<string>>;
|
||||
export type RequestHelmChartReadme = (repo: string, name: string, version?: string) => AsyncResult<string>;
|
||||
|
||||
const requestHelmChartReadmeInjectable = getInjectable({
|
||||
id: "request-helm-chart-readme",
|
||||
|
||||
+3
-3
@@ -3,13 +3,13 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { AsyncResult } from "../../../utils/async-result";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import { urlBuilderFor } from "@k8slens/utilities";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
const requestValuesEndpoint = urlBuilderFor("/v2/charts/:repo/:name/values");
|
||||
|
||||
export type RequestHelmChartValues = (repo: string, name: string, version: string) => Promise<AsyncResult<string>>;
|
||||
export type RequestHelmChartValues = (repo: string, name: string, version: string) => AsyncResult<string>;
|
||||
|
||||
const requestHelmChartValuesInjectable = getInjectable({
|
||||
id: "request-helm-chart-values",
|
||||
|
||||
+1
-2
@@ -3,10 +3,9 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import { urlBuilderFor, isDefined } from "@k8slens/utilities";
|
||||
import { HelmChart } from "../helm-charts.api";
|
||||
import type { RawHelmChart } from "../helm-charts.api";
|
||||
import { isDefined } from "../../../utils";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
const requestVersionsEndpoint = urlBuilderFor("/v2/charts/:repo/:name/versions");
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverride } from "../../../test-utils/get-global-override";
|
||||
import { getGlobalOverride } from "@k8slens/test-utils";
|
||||
import requestHelmReleaseConfigurationInjectable from "./request-configuration.injectable";
|
||||
|
||||
export default getGlobalOverride(requestHelmReleaseConfigurationInjectable, () => () => {
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import { urlBuilderFor } from "@k8slens/utilities";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
export type RequestHelmReleaseConfiguration = (
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
import yaml from "js-yaml";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { HelmReleaseUpdateDetails } from "../helm-releases.api";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import { urlBuilderFor } from "@k8slens/utilities";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
interface HelmReleaseCreatePayload {
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import { urlBuilderFor } from "@k8slens/utilities";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
export type RequestDeleteHelmRelease = (name: string, namespace: string) => Promise<void>;
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { KubeJsonApiData } from "../../kube-json-api";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import { urlBuilderFor } from "@k8slens/utilities";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
export interface HelmReleaseDetails {
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import { urlBuilderFor } from "@k8slens/utilities";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
export interface HelmReleaseRevision {
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import { urlBuilderFor } from "@k8slens/utilities";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
import type { HelmReleaseDto } from "../helm-releases.api";
|
||||
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import { urlBuilderFor } from "@k8slens/utilities";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
export type RequestHelmReleaseRollback = (name: string, namespace: string, revision: number) => Promise<void>;
|
||||
|
||||
+3
-3
@@ -3,8 +3,8 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import type { AsyncResult } from "../../../utils/async-result";
|
||||
import { urlBuilderFor } from "@k8slens/utilities";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
interface HelmReleaseUpdatePayload {
|
||||
@@ -18,7 +18,7 @@ export type RequestHelmReleaseUpdate = (
|
||||
name: string,
|
||||
namespace: string,
|
||||
payload: HelmReleaseUpdatePayload
|
||||
) => Promise<AsyncResult<void, unknown>>;
|
||||
) => AsyncResult<void, unknown>;
|
||||
|
||||
const requestUpdateEndpoint = urlBuilderFor("/v2/releases/:namespace/:name");
|
||||
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { urlBuilderFor } from "../../../utils/buildUrl";
|
||||
import { urlBuilderFor } from "@k8slens/utilities";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
|
||||
export type RequestHelmReleaseValues = (name: string, namespace: string, all?: boolean) => Promise<string>;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { OptionVarient } from "../../utils";
|
||||
import type { OptionVariant } from "@k8slens/utilities";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { BaseKubeObjectCondition, LabelSelector, NamespaceScopedMetadata } from "../kube-object";
|
||||
@@ -46,7 +46,7 @@ export interface V2Beta1ContainerResourceMetricSource {
|
||||
targetAverageValue?: string;
|
||||
}
|
||||
|
||||
export type ContainerResourceMetricSource =
|
||||
export type ContainerResourceMetricSource =
|
||||
| V2ContainerResourceMetricSource
|
||||
| V2Beta1ContainerResourceMetricSource;
|
||||
|
||||
@@ -74,7 +74,7 @@ export interface V2Beta1ExternalMetricSource {
|
||||
};
|
||||
}
|
||||
|
||||
export type ExternalMetricSource =
|
||||
export type ExternalMetricSource =
|
||||
| V2Beta1ExternalMetricSource
|
||||
| V2ExternalMetricSource;
|
||||
|
||||
@@ -152,11 +152,11 @@ export interface BaseHorizontalPodAutoscalerMetricSpec {
|
||||
}
|
||||
|
||||
export type HorizontalPodAutoscalerMetricSpec =
|
||||
| OptionVarient<HpaMetricType.Resource, BaseHorizontalPodAutoscalerMetricSpec, "resource">
|
||||
| OptionVarient<HpaMetricType.External, BaseHorizontalPodAutoscalerMetricSpec, "external">
|
||||
| OptionVarient<HpaMetricType.Object, BaseHorizontalPodAutoscalerMetricSpec, "object">
|
||||
| OptionVarient<HpaMetricType.Pods, BaseHorizontalPodAutoscalerMetricSpec, "pods">
|
||||
| OptionVarient<HpaMetricType.ContainerResource, BaseHorizontalPodAutoscalerMetricSpec, "containerResource">;
|
||||
| OptionVariant<HpaMetricType.Resource, BaseHorizontalPodAutoscalerMetricSpec, "resource">
|
||||
| OptionVariant<HpaMetricType.External, BaseHorizontalPodAutoscalerMetricSpec, "external">
|
||||
| OptionVariant<HpaMetricType.Object, BaseHorizontalPodAutoscalerMetricSpec, "object">
|
||||
| OptionVariant<HpaMetricType.Pods, BaseHorizontalPodAutoscalerMetricSpec, "pods">
|
||||
| OptionVariant<HpaMetricType.ContainerResource, BaseHorizontalPodAutoscalerMetricSpec, "containerResource">;
|
||||
|
||||
interface HorizontalPodAutoscalerBehavior {
|
||||
scaleUp?: HPAScalingRules;
|
||||
@@ -294,11 +294,11 @@ export interface BaseHorizontalPodAutoscalerMetricStatus {
|
||||
}
|
||||
|
||||
export type HorizontalPodAutoscalerMetricStatus =
|
||||
| OptionVarient<HpaMetricType.Resource, BaseHorizontalPodAutoscalerMetricStatus, "resource">
|
||||
| OptionVarient<HpaMetricType.External, BaseHorizontalPodAutoscalerMetricStatus, "external">
|
||||
| OptionVarient<HpaMetricType.Object, BaseHorizontalPodAutoscalerMetricStatus, "object">
|
||||
| OptionVarient<HpaMetricType.Pods, BaseHorizontalPodAutoscalerMetricStatus, "pods">
|
||||
| OptionVarient<HpaMetricType.ContainerResource, BaseHorizontalPodAutoscalerMetricStatus, "containerResource">;
|
||||
| OptionVariant<HpaMetricType.Resource, BaseHorizontalPodAutoscalerMetricStatus, "resource">
|
||||
| OptionVariant<HpaMetricType.External, BaseHorizontalPodAutoscalerMetricStatus, "external">
|
||||
| OptionVariant<HpaMetricType.Object, BaseHorizontalPodAutoscalerMetricStatus, "object">
|
||||
| OptionVariant<HpaMetricType.Pods, BaseHorizontalPodAutoscalerMetricStatus, "pods">
|
||||
| OptionVariant<HpaMetricType.ContainerResource, BaseHorizontalPodAutoscalerMetricStatus, "containerResource">;
|
||||
|
||||
export interface HorizontalPodAutoscalerSpec {
|
||||
scaleTargetRef: CrossVersionObjectReference;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import type { NamespaceScopedMetadata, TypedLocalObjectReference } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { hasTypedProperty, isString, iter } from "../../utils";
|
||||
import { hasTypedProperty, isString, iter } from "@k8slens/utilities";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { RequireExactlyOne } from "type-fest";
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// Metrics api
|
||||
|
||||
import moment from "moment";
|
||||
import { isDefined, object } from "../../utils";
|
||||
import { isDefined, object } from "@k8slens/utilities";
|
||||
|
||||
export interface MetricData {
|
||||
status: string;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import type { BaseKubeObjectCondition, ClusterScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { cpuUnitsToNumber, unitsToBytes, isObject } from "../../../renderer/utils";
|
||||
import { cpuUnitsToNumber, unitsToBytes, isObject } from "@k8slens/utilities";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { TypedRegEx } from "typed-regex";
|
||||
|
||||
@@ -8,7 +8,7 @@ import { KubeObject } from "../kube-object";
|
||||
import type { Pod } from "./pod.api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { object } from "../../utils";
|
||||
import { object } from "@k8slens/utilities";
|
||||
import type { ResourceRequirements } from "./types/resource-requirements";
|
||||
|
||||
export class PersistentVolumeClaimApi extends KubeApi<PersistentVolumeClaim> {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import type { ClusterScopedMetadata, LabelSelector, ObjectReference, TypedLocalObjectReference } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { unitsToBytes } from "../../utils";
|
||||
import { unitsToBytes } from "@k8slens/utilities";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { ResourceRequirements } from "./types/resource-requirements";
|
||||
|
||||
@@ -10,7 +10,7 @@ import type { KubeObjectMetadata, LocalObjectReference, Affinity, Toleration, Na
|
||||
import type { SecretReference } from "./secret.api";
|
||||
import type { PersistentVolumeClaimSpec } from "./persistent-volume-claim.api";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { isDefined } from "../../utils";
|
||||
import { isDefined } from "@k8slens/utilities";
|
||||
import type { PodSecurityContext } from "./types/pod-security-context";
|
||||
import type { Probe } from "./types/probe";
|
||||
import type { Container } from "./types/container";
|
||||
|
||||
+3
-3
@@ -5,10 +5,10 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { Patch } from "rfc6902";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
import type { AsyncResult } from "../../../utils/async-result";
|
||||
import type { AsyncResult, Result } from "@k8slens/utilities";
|
||||
import type { KubeJsonApiData } from "../../kube-json-api";
|
||||
|
||||
export type RequestKubeObjectPatch = (name: string, kind: string, ns: string | undefined, patch: Patch) => Promise<AsyncResult<KubeJsonApiData, string>>;
|
||||
export type RequestKubeObjectPatch = (name: string, kind: string, ns: string | undefined, patch: Patch) => AsyncResult<KubeJsonApiData, string>;
|
||||
|
||||
const requestKubeObjectPatchInjectable = getInjectable({
|
||||
id: "request-kube-object-patch",
|
||||
@@ -23,7 +23,7 @@ const requestKubeObjectPatchInjectable = getInjectable({
|
||||
ns,
|
||||
patch,
|
||||
},
|
||||
}) as AsyncResult<string, string>;
|
||||
}) as Result<string, string>;
|
||||
|
||||
if (!result.callWasSuccessful) {
|
||||
return result;
|
||||
|
||||
+3
-3
@@ -4,10 +4,10 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import apiBaseInjectable from "../../api-base.injectable";
|
||||
import type { AsyncResult } from "../../../utils/async-result";
|
||||
import type { AsyncResult, Result } from "@k8slens/utilities";
|
||||
import type { KubeJsonApiData } from "../../kube-json-api";
|
||||
|
||||
export type RequestKubeObjectCreation = (resourceDescriptor: string) => Promise<AsyncResult<KubeJsonApiData, string>>;
|
||||
export type RequestKubeObjectCreation = (resourceDescriptor: string) => AsyncResult<KubeJsonApiData, string>;
|
||||
|
||||
const requestKubeObjectCreationInjectable = getInjectable({
|
||||
id: "request-kube-object-creation",
|
||||
@@ -15,7 +15,7 @@ const requestKubeObjectCreationInjectable = getInjectable({
|
||||
const apiBase = di.inject(apiBaseInjectable);
|
||||
|
||||
return async (data) => {
|
||||
const result = await apiBase.post("/stack", { data }) as AsyncResult<string, string>;
|
||||
const result = await apiBase.post("/stack", { data }) as Result<string, string>;
|
||||
|
||||
if (!result.callWasSuccessful) {
|
||||
return result;
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
import type { KubeObjectMetadata, KubeObjectScope, NamespaceScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import { autoBind } from "../../utils";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import autoBind from "auto-bind";
|
||||
|
||||
export enum SecretType {
|
||||
Opaque = "Opaque",
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { autoBind } from "../../utils";
|
||||
import type { ClusterScopedMetadata, KubeObjectMetadata, KubeObjectScope } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import autoBind from "auto-bind";
|
||||
|
||||
export interface TopologySelectorLabelRequirement {
|
||||
key: string;
|
||||
|
||||
@@ -15,8 +15,8 @@ import type { PartialDeep, ValueOf } from "type-fest";
|
||||
import { EventEmitter } from "../../common/event-emitter";
|
||||
import type { Logger } from "../../common/logger";
|
||||
import type { Fetch } from "../fetch/fetch.injectable";
|
||||
import type { Defaulted } from "../utils";
|
||||
import { json } from "../utils";
|
||||
import type { Defaulted } from "@k8slens/utilities";
|
||||
import { isObject, isString, json } from "@k8slens/utilities";
|
||||
|
||||
export interface JsonApiData {}
|
||||
|
||||
@@ -184,20 +184,17 @@ export class JsonApi<Data = JsonApiData, Params extends JsonApiParams<Data> = Js
|
||||
|
||||
const res = await this.dependencies.fetch(reqUrl, reqInit);
|
||||
|
||||
return this.parseResponse<OutData>(res, infoLog);
|
||||
return await this.parseResponse(res, infoLog) as OutData;
|
||||
}
|
||||
|
||||
protected async parseResponse<OutData>(res: Response, log: JsonApiLog): Promise<OutData> {
|
||||
protected async parseResponse(res: Response, log: JsonApiLog): Promise<Data> {
|
||||
const { status } = res;
|
||||
|
||||
const text = await res.text();
|
||||
let data: any;
|
||||
|
||||
try {
|
||||
data = text ? json.parse(text) : ""; // DELETE-requests might not have response-body
|
||||
} catch (e) {
|
||||
data = text;
|
||||
}
|
||||
const parseResponse = json.parse(text || "{}");
|
||||
const data = parseResponse.callWasSuccessful
|
||||
? parseResponse.response as Data
|
||||
: text as Data;
|
||||
|
||||
if (status >= 200 && status < 300) {
|
||||
this.onData.emit(data, res);
|
||||
@@ -211,7 +208,7 @@ export class JsonApi<Data = JsonApiData, Params extends JsonApiParams<Data> = Js
|
||||
throw data;
|
||||
}
|
||||
|
||||
const error = new JsonApiErrorParsed(data, this.parseError(data, res));
|
||||
const error = new JsonApiErrorParsed(data as JsonApiError, this.parseError(data, res));
|
||||
|
||||
this.onError.emit(error, res);
|
||||
this.writeLog({ ...log, error });
|
||||
@@ -219,16 +216,20 @@ export class JsonApi<Data = JsonApiData, Params extends JsonApiParams<Data> = Js
|
||||
throw error;
|
||||
}
|
||||
|
||||
protected parseError(error: JsonApiError | string, res: Response): string[] {
|
||||
if (typeof error === "string") {
|
||||
protected parseError(error: unknown, res: Response): string[] {
|
||||
if (isString(error)) {
|
||||
return [error];
|
||||
}
|
||||
|
||||
if (!isObject(error)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (Array.isArray(error.errors)) {
|
||||
return error.errors.map(error => error.title);
|
||||
}
|
||||
|
||||
if (error.message) {
|
||||
if (isString(error.message)) {
|
||||
return [error.message];
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
// Parse kube-api path and get api-version, group, etc.
|
||||
|
||||
import { splitArray } from "../utils";
|
||||
import { array } from "@k8slens/utilities";
|
||||
|
||||
export interface IKubeApiLinkRef {
|
||||
apiPrefix?: string;
|
||||
@@ -26,7 +26,7 @@ export function parseKubeApi(path: string): IKubeApiParsed {
|
||||
const apiPath = new URL(path, "https://localhost").pathname;
|
||||
const [, prefix, ...parts] = apiPath.split("/");
|
||||
const apiPrefix = `/${prefix}`;
|
||||
const [left, right, namespaced] = splitArray(parts, "namespaces");
|
||||
const [left, right, namespaced] = array.split(parts, "namespaces");
|
||||
let apiGroup!: string;
|
||||
let apiVersion!: string;
|
||||
let namespace!: string;
|
||||
|
||||
@@ -13,8 +13,8 @@ import { KubeObject, KubeStatus, isKubeStatusData } from "./kube-object";
|
||||
import byline from "byline";
|
||||
import type { IKubeWatchEvent } from "./kube-watch-event";
|
||||
import type { KubeJsonApiData, KubeJsonApi } from "./kube-json-api";
|
||||
import type { Disposer } from "../utils";
|
||||
import { isDefined, noop, WrappedAbortController } from "../utils";
|
||||
import type { Disposer } from "@k8slens/utilities";
|
||||
import { isDefined, noop, WrappedAbortController } from "@k8slens/utilities";
|
||||
import type { RequestInit, Response } from "@k8slens/node-fetch";
|
||||
import type { Patch } from "rfc6902";
|
||||
import assert from "assert";
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
*/
|
||||
|
||||
import { action, computed, makeObservable, observable, reaction } from "mobx";
|
||||
import type { Disposer } from "../utils";
|
||||
import { waitUntilDefined, autoBind, includes, rejectPromiseBy } from "../utils";
|
||||
import type { Disposer } from "@k8slens/utilities";
|
||||
import { waitUntilDefined, includes, rejectPromiseBy, object } from "@k8slens/utilities";
|
||||
import type { KubeJsonApiDataFor, KubeObject } from "./kube-object";
|
||||
import { KubeStatus } from "./kube-object";
|
||||
import type { IKubeWatchEvent } from "./kube-watch-event";
|
||||
@@ -17,9 +17,9 @@ import type { Patch } from "rfc6902";
|
||||
import type { Logger } from "../logger";
|
||||
import assert from "assert";
|
||||
import type { PartialDeep } from "type-fest";
|
||||
import { entries } from "../utils/objects";
|
||||
import AbortController from "abort-controller";
|
||||
import type { ClusterContext } from "../../renderer/cluster-frame-context/cluster-frame-context";
|
||||
import autoBind from "auto-bind";
|
||||
|
||||
export type OnLoadFailure = (error: unknown) => void;
|
||||
|
||||
@@ -179,7 +179,7 @@ export abstract class KubeObjectStore<
|
||||
return this.items.filter((item: K) => {
|
||||
const itemLabels = item.metadata.labels || {};
|
||||
|
||||
return entries(labels)
|
||||
return object.entries(labels)
|
||||
.every(([key, value]) => itemLabels[key] === value);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
import moment from "moment";
|
||||
import type { KubeJsonApiData, KubeJsonApiDataList, KubeJsonApiListMetadata } from "./kube-json-api";
|
||||
import { autoBind, formatDuration, hasOptionalTypedProperty, hasTypedProperty, isObject, isString, isNumber, bindPredicate, isTypedArray, isRecord, json } from "../utils";
|
||||
import { formatDuration, hasOptionalTypedProperty, hasTypedProperty, isObject, isString, isNumber, bindPredicate, isTypedArray, isRecord } from "@k8slens/utilities";
|
||||
import type { ItemObject } from "../item.store";
|
||||
import type { Patch } from "rfc6902";
|
||||
import assert from "assert";
|
||||
@@ -17,6 +17,7 @@ import { apiKubeInjectionToken } from "./api-kube";
|
||||
import requestKubeObjectCreationInjectable from "./endpoints/resource-applier.api/request-update.injectable";
|
||||
import { dump } from "js-yaml";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import autoBind from "auto-bind";
|
||||
|
||||
export type KubeJsonApiDataFor<K> = K extends KubeObject<infer Metadata, infer Status, infer Spec>
|
||||
? KubeJsonApiData<Metadata, Status, Spec>
|
||||
@@ -624,7 +625,7 @@ export class KubeObject<
|
||||
}
|
||||
|
||||
toPlainObject() {
|
||||
return json.parse(JSON.stringify(this)) as JsonObject;
|
||||
return JSON.parse(JSON.stringify(this)) as JsonObject;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { computed } from "mobx";
|
||||
import namespaceStoreInjectable from "../../renderer/components/+namespaces/store.injectable";
|
||||
import clusterFrameContextForNamespacedResourcesInjectable from "../../renderer/cluster-frame-context/for-namespaced-resources.injectable";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "./stores-apis-can-be-created.token";
|
||||
|
||||
const selectedFilterNamespacesInjectable = getInjectable({
|
||||
@@ -15,9 +15,9 @@ const selectedFilterNamespacesInjectable = getInjectable({
|
||||
return computed(() => []);
|
||||
}
|
||||
|
||||
const store = di.inject(namespaceStoreInjectable);
|
||||
const context = di.inject(clusterFrameContextForNamespacedResourcesInjectable);
|
||||
|
||||
return computed(() => [...store.contextNamespaces]);
|
||||
return computed(() => [...context.contextNamespaces]);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverride } from "../test-utils/get-global-override";
|
||||
import { getGlobalOverride } from "@k8slens/test-utils";
|
||||
import windowLocationInjectable from "./window-location.injectable";
|
||||
|
||||
export default getGlobalOverride(windowLocationInjectable, () => ({
|
||||
|
||||
Loaded 100 of 1062 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user