mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Remove a lot of usages of legacy globals (#6825)
* Remove all usages of legacy global logger Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global storageClassApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global serviceApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global secretApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global resourceQuotaApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global persistentVolumeClaimApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global nodeApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global networkPolicyApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix formatting Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global configMapApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global jobApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global cronJobApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global podApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global roleApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove exports of NonInjected components - To improve auto-complete Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global catalogEntityRegistry Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add lint against using legacy global works Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lint in KubeObject file Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global catalogCategoryRegistry Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global navigation Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global navigate Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove unneeded index file Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global customResourceDefinitionStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global eventStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global podSecurityPolicyStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global storageClassStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global persistentVolumeStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global clusterRoleBindingStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global clusterRoleStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global roleBindingStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move files around Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global roleStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global serviceAccountStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove usages of legacy global podStore Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove final uses of asLegacyGlobalForExtensionApi in application code Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lint rule and start fixing lint errors Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make listHelmReleases injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make installHelmChart injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make deleteHelmRelease injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make getHelmReleaseValues injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make getHelmReleaseHistory injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make rollbackHelmRelease injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove unnecessary overrides from getDiForUnitTesting Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add global override for logger Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add global override for history Signed-off-by: Sebastian Malton <sebastian@malton.name> * Cleanup typing around getting injectables within jest Signed-off-by: Sebastian Malton <sebastian@malton.name> * Move some more overrides to global if needed Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add global override for forcusWindow Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lint in KubeApi Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lint in catalog/index.ts Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove last usages of legacy global getDetailsUrl Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove last usages of legacy global showDetails Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add functions back to extension API Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove all uses of legacy global Notification functions Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove no longer existing export Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove unnecessary overrides Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix injecting side effects by using more injectables Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix cluster role binding dialog Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix cluster role dialog Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix create service account dialog Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix history override Signed-off-by: Sebastian Malton <sebastian@malton.name> * Make KubeApi consume its dependencies while not breaking the extension API Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Update snapshots Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix CephFs tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix user store tests by using override of config Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in hotbar store tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Add direct devDep of memfs Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in cluster store tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in router tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in kube auth proxy tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in log resource selector tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in hotbar remove command tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in the select component tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove mock-fs as a dependency Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove no longer necessary mocks Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix namespace select filter tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove use of mockFs in the extension loader tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fixing edit-namespace-from-new-tab test Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix app paths tests by making the tests run in "production" mode Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove last vestiges of isTestEnv and the is* globals Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix delete-cluster-dialog tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix install-helm-chart-from-previously-opened-tab tests - Split out storage initialization to a runnable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove unnecessary override of non side effect injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix disable-kube-object-detail-items-when-cluster-is-not-relevant tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix reactively-hide-kube-object-detail-item tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix lint Signed-off-by: Sebastian Malton <sebastian@malton.name> * Update snapshots Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix sidebar-and-tab-navigation-for-core tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove need to override lensLocalStoragePath in tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Replace more overrides with global ones Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix tests Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix typings Signed-off-by: Sebastian Malton <sebastian@malton.name> * Remove no longer needed technical test Signed-off-by: Sebastian Malton <sebastian@malton.name> * Update snapshots Signed-off-by: Sebastian Malton <sebastian@malton.name> Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
900a8bbda3
commit
2b33d5eed6
@ -283,6 +283,15 @@ module.exports = {
|
||||
],
|
||||
message: "No importing from the extension api definitions in application code",
|
||||
},
|
||||
{
|
||||
"group": [
|
||||
"**/extensions/as-legacy-globals-for-extension-api/as-legacy-global-function-for-extension-api",
|
||||
"**/extensions/as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api-with-modifications",
|
||||
"**/extensions/as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api",
|
||||
"**/extensions/as-legacy-globals-for-extension-api/as-legacy-global-singleton-object-for-extension-api",
|
||||
],
|
||||
message: "No importing the legacy global functions in non-ExtensionApi code",
|
||||
},
|
||||
],
|
||||
}],
|
||||
},
|
||||
|
||||
@ -273,7 +273,6 @@
|
||||
"mobx-observable-history": "^2.0.3",
|
||||
"mobx-react": "^7.6.0",
|
||||
"mobx-utils": "^6.0.4",
|
||||
"mock-fs": "^5.2.0",
|
||||
"moment": "^2.29.4",
|
||||
"moment-timezone": "^0.5.40",
|
||||
"node-fetch": "^3.3.0",
|
||||
@ -408,6 +407,7 @@
|
||||
"jest-environment-jsdom": "^28.1.3",
|
||||
"jest-mock-extended": "^2.0.9",
|
||||
"make-plural": "^6.2.2",
|
||||
"memfs": "^3.4.12",
|
||||
"memorystream": "^0.3.1",
|
||||
"mini-css-extract-plugin": "^2.7.2",
|
||||
"mock-http": "^1.1.0",
|
||||
|
||||
@ -3,34 +3,33 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import fs from "fs";
|
||||
import mockFs from "mock-fs";
|
||||
import path from "path";
|
||||
import fse from "fs-extra";
|
||||
import type { ClusterStore } from "../cluster-store/cluster-store";
|
||||
import { Console } from "console";
|
||||
import { stdout, stderr } from "process";
|
||||
import getCustomKubeConfigDirectoryInjectable from "../app-paths/get-custom-kube-config-directory/get-custom-kube-config-directory.injectable";
|
||||
import type { GetCustomKubeConfigFilePath } from "../app-paths/get-custom-kube-config-directory/get-custom-kube-config-directory.injectable";
|
||||
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 getConfigurationFileModelInjectable from "../get-configuration-file-model/get-configuration-file-model.injectable";
|
||||
import assert from "assert";
|
||||
import directoryForTempInjectable from "../app-paths/directory-for-temp/directory-for-temp.injectable";
|
||||
import kubectlBinaryNameInjectable from "../../main/kubectl/binary-name.injectable";
|
||||
import kubectlDownloadingNormalizedArchInjectable from "../../main/kubectl/normalized-arch.injectable";
|
||||
import normalizedPlatformInjectable from "../vars/normalized-platform.injectable";
|
||||
import fsInjectable from "../fs/fs.injectable";
|
||||
import storeMigrationVersionInjectable from "../vars/store-migration-version.injectable";
|
||||
import type { WriteJsonSync } from "../fs/write-json-sync.injectable";
|
||||
import writeJsonSyncInjectable from "../fs/write-json-sync.injectable";
|
||||
import type { ReadFileSync } from "../fs/read-file-sync.injectable";
|
||||
import readFileSyncInjectable from "../fs/read-file-sync.injectable";
|
||||
import { readFileSync } from "fs";
|
||||
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";
|
||||
|
||||
console = new Console(stdout, stderr);
|
||||
|
||||
const testDataIcon = fs.readFileSync(
|
||||
"test-data/cluster-store-migration-icon.png",
|
||||
);
|
||||
// NOTE: this is intended to read the actual file system
|
||||
const testDataIcon = readFileSync("test-data/cluster-store-migration-icon.png");
|
||||
const clusterServerUrl = "https://localhost";
|
||||
const kubeconfig = `
|
||||
apiVersion: v1
|
||||
@ -56,75 +55,41 @@ users:
|
||||
token: kubeconfig-user-q4lm4:xxxyyyy
|
||||
`;
|
||||
|
||||
const embed = (directoryName: string, contents: any): string => {
|
||||
fse.ensureDirSync(path.dirname(directoryName));
|
||||
fse.writeFileSync(directoryName, contents, {
|
||||
encoding: "utf-8",
|
||||
mode: 0o600,
|
||||
});
|
||||
|
||||
return directoryName;
|
||||
};
|
||||
|
||||
jest.mock("electron", () => ({
|
||||
ipcMain: {
|
||||
handle: jest.fn(),
|
||||
on: jest.fn(),
|
||||
removeAllListeners: jest.fn(),
|
||||
off: jest.fn(),
|
||||
send: jest.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
describe("cluster-store", () => {
|
||||
let mainDi: DiContainer;
|
||||
let di: DiContainer;
|
||||
let clusterStore: ClusterStore;
|
||||
let createCluster: CreateCluster;
|
||||
let writeJsonSync: WriteJsonSync;
|
||||
let writeFileSync: WriteFileSync;
|
||||
let writeBufferSync: WriteBufferSync;
|
||||
let readFileSync: ReadFileSync;
|
||||
let getCustomKubeConfigFilePath: GetCustomKubeConfigFilePath;
|
||||
let writeFileSyncAndReturnPath: (filePath: string, contents: string) => string;
|
||||
|
||||
beforeEach(async () => {
|
||||
mainDi = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
|
||||
mockFs();
|
||||
|
||||
mainDi.override(directoryForUserDataInjectable, () => "some-directory-for-user-data");
|
||||
mainDi.override(directoryForTempInjectable, () => "some-temp-directory");
|
||||
mainDi.override(kubectlBinaryNameInjectable, () => "kubectl");
|
||||
mainDi.override(kubectlDownloadingNormalizedArchInjectable, () => "amd64");
|
||||
mainDi.override(normalizedPlatformInjectable, () => "darwin");
|
||||
|
||||
mainDi.permitSideEffects(getConfigurationFileModelInjectable);
|
||||
mainDi.unoverride(getConfigurationFileModelInjectable);
|
||||
|
||||
mainDi.permitSideEffects(fsInjectable);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockFs.restore();
|
||||
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);
|
||||
readFileSync = di.inject(readFileSyncInjectable);
|
||||
writeFileSyncAndReturnPath = (filePath, contents) => (writeFileSync(filePath, contents), filePath);
|
||||
});
|
||||
|
||||
describe("empty config", () => {
|
||||
let getCustomKubeConfigDirectory: (directoryName: string) => string;
|
||||
|
||||
beforeEach(async () => {
|
||||
getCustomKubeConfigDirectory = mainDi.inject(getCustomKubeConfigDirectoryInjectable);
|
||||
|
||||
mockFs({
|
||||
"some-directory-for-user-data": {
|
||||
"lens-cluster-store.json": JSON.stringify({}),
|
||||
},
|
||||
});
|
||||
|
||||
createCluster = mainDi.inject(createClusterInjectionToken);
|
||||
|
||||
clusterStore = mainDi.inject(clusterStoreInjectable);
|
||||
|
||||
writeJsonSync("/some-directory-for-user-data/lens-cluster-store.json", {});
|
||||
clusterStore = di.inject(clusterStoreInjectable);
|
||||
clusterStore.load();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockFs.restore();
|
||||
});
|
||||
|
||||
describe("with foo cluster added", () => {
|
||||
beforeEach(() => {
|
||||
const cluster = createCluster({
|
||||
@ -135,8 +100,8 @@ describe("cluster-store", () => {
|
||||
icon: "data:image/jpeg;base64, iVBORw0KGgoAAAANSUhEUgAAA1wAAAKoCAYAAABjkf5",
|
||||
clusterName: "minikube",
|
||||
},
|
||||
kubeConfigPath: embed(
|
||||
getCustomKubeConfigDirectory("foo"),
|
||||
kubeConfigPath: writeFileSyncAndReturnPath(
|
||||
getCustomKubeConfigFilePath("foo"),
|
||||
kubeconfig,
|
||||
),
|
||||
}, {
|
||||
@ -169,8 +134,8 @@ describe("cluster-store", () => {
|
||||
preferences: {
|
||||
clusterName: "prod",
|
||||
},
|
||||
kubeConfigPath: embed(
|
||||
getCustomKubeConfigDirectory("prod"),
|
||||
kubeConfigPath: writeFileSyncAndReturnPath(
|
||||
getCustomKubeConfigFilePath("prod"),
|
||||
kubeconfig,
|
||||
),
|
||||
});
|
||||
@ -180,8 +145,8 @@ describe("cluster-store", () => {
|
||||
preferences: {
|
||||
clusterName: "dev",
|
||||
},
|
||||
kubeConfigPath: embed(
|
||||
getCustomKubeConfigDirectory("dev"),
|
||||
kubeConfigPath: writeFileSyncAndReturnPath(
|
||||
getCustomKubeConfigFilePath("dev"),
|
||||
kubeconfig,
|
||||
),
|
||||
});
|
||||
@ -193,61 +158,49 @@ describe("cluster-store", () => {
|
||||
});
|
||||
|
||||
it("check if cluster's kubeconfig file saved", () => {
|
||||
const file = embed(getCustomKubeConfigDirectory("boo"), "kubeconfig");
|
||||
const file = writeFileSyncAndReturnPath(getCustomKubeConfigFilePath("boo"), "kubeconfig");
|
||||
|
||||
expect(fs.readFileSync(file, "utf8")).toBe("kubeconfig");
|
||||
expect(readFileSync(file)).toBe("kubeconfig");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("config with existing clusters", () => {
|
||||
beforeEach(() => {
|
||||
mockFs({
|
||||
"temp-kube-config": kubeconfig,
|
||||
"some-directory-for-user-data": {
|
||||
"lens-cluster-store.json": JSON.stringify({
|
||||
__internal__: {
|
||||
migrations: {
|
||||
version: "99.99.99",
|
||||
},
|
||||
},
|
||||
clusters: [
|
||||
{
|
||||
id: "cluster1",
|
||||
kubeConfigPath: "./temp-kube-config",
|
||||
contextName: "foo",
|
||||
preferences: { terminalCWD: "/foo" },
|
||||
workspace: "default",
|
||||
},
|
||||
{
|
||||
id: "cluster2",
|
||||
kubeConfigPath: "./temp-kube-config",
|
||||
contextName: "foo2",
|
||||
preferences: { terminalCWD: "/foo2" },
|
||||
},
|
||||
{
|
||||
id: "cluster3",
|
||||
kubeConfigPath: "./temp-kube-config",
|
||||
contextName: "foo",
|
||||
preferences: { terminalCWD: "/foo" },
|
||||
workspace: "foo",
|
||||
ownerRef: "foo",
|
||||
},
|
||||
],
|
||||
}),
|
||||
writeFileSync("/temp-kube-config", kubeconfig);
|
||||
writeJsonSync("/some-directory-for-user-data/lens-cluster-store.json", {
|
||||
__internal__: {
|
||||
migrations: {
|
||||
version: "99.99.99",
|
||||
},
|
||||
},
|
||||
clusters: [
|
||||
{
|
||||
id: "cluster1",
|
||||
kubeConfigPath: "/temp-kube-config",
|
||||
contextName: "foo",
|
||||
preferences: { terminalCWD: "/foo" },
|
||||
workspace: "default",
|
||||
},
|
||||
{
|
||||
id: "cluster2",
|
||||
kubeConfigPath: "/temp-kube-config",
|
||||
contextName: "foo2",
|
||||
preferences: { terminalCWD: "/foo2" },
|
||||
},
|
||||
{
|
||||
id: "cluster3",
|
||||
kubeConfigPath: "/temp-kube-config",
|
||||
contextName: "foo",
|
||||
preferences: { terminalCWD: "/foo" },
|
||||
workspace: "foo",
|
||||
ownerRef: "foo",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
createCluster = mainDi.inject(createClusterInjectionToken);
|
||||
|
||||
clusterStore = mainDi.inject(clusterStoreInjectable);
|
||||
clusterStore = di.inject(clusterStoreInjectable);
|
||||
clusterStore.load();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockFs.restore();
|
||||
});
|
||||
|
||||
it("allows to retrieve a cluster", () => {
|
||||
const storedCluster = clusterStore.getById("cluster1");
|
||||
|
||||
@ -271,66 +224,35 @@ describe("cluster-store", () => {
|
||||
|
||||
describe("config with invalid cluster kubeconfig", () => {
|
||||
beforeEach(() => {
|
||||
const invalidKubeconfig = `
|
||||
apiVersion: v1
|
||||
clusters:
|
||||
- cluster:
|
||||
server: https://localhost
|
||||
name: test2
|
||||
contexts:
|
||||
- context:
|
||||
cluster: test
|
||||
user: test
|
||||
name: test
|
||||
current-context: test
|
||||
kind: Config
|
||||
preferences: {}
|
||||
users:
|
||||
- name: test
|
||||
user:
|
||||
token: kubeconfig-user-q4lm4:xxxyyyy
|
||||
`;
|
||||
|
||||
mockFs({
|
||||
"invalid-kube-config": invalidKubeconfig,
|
||||
"valid-kube-config": kubeconfig,
|
||||
"some-directory-for-user-data": {
|
||||
"lens-cluster-store.json": JSON.stringify({
|
||||
__internal__: {
|
||||
migrations: {
|
||||
version: "99.99.99",
|
||||
},
|
||||
},
|
||||
clusters: [
|
||||
{
|
||||
id: "cluster1",
|
||||
kubeConfigPath: "./invalid-kube-config",
|
||||
contextName: "test",
|
||||
preferences: { terminalCWD: "/foo" },
|
||||
workspace: "foo",
|
||||
},
|
||||
{
|
||||
id: "cluster2",
|
||||
kubeConfigPath: "./valid-kube-config",
|
||||
contextName: "foo",
|
||||
preferences: { terminalCWD: "/foo" },
|
||||
workspace: "default",
|
||||
},
|
||||
],
|
||||
}),
|
||||
writeFileSync("/invalid-kube-config", invalidKubeconfig);
|
||||
writeFileSync("/valid-kube-config", kubeconfig);
|
||||
writeJsonSync("/some-directory-for-user-data/lens-cluster-store.json", {
|
||||
__internal__: {
|
||||
migrations: {
|
||||
version: "99.99.99",
|
||||
},
|
||||
},
|
||||
clusters: [
|
||||
{
|
||||
id: "cluster1",
|
||||
kubeConfigPath: "/invalid-kube-config",
|
||||
contextName: "test",
|
||||
preferences: { terminalCWD: "/foo" },
|
||||
workspace: "foo",
|
||||
},
|
||||
{
|
||||
id: "cluster2",
|
||||
kubeConfigPath: "/valid-kube-config",
|
||||
contextName: "foo",
|
||||
preferences: { terminalCWD: "/foo" },
|
||||
workspace: "default",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
createCluster = mainDi.inject(createClusterInjectionToken);
|
||||
|
||||
clusterStore = mainDi.inject(clusterStoreInjectable);
|
||||
clusterStore = di.inject(clusterStoreInjectable);
|
||||
clusterStore.load();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockFs.restore();
|
||||
});
|
||||
|
||||
it("does not enable clusters with invalid kubeconfig", () => {
|
||||
const storedClusters = clusterStore.clustersList;
|
||||
|
||||
@ -340,56 +262,69 @@ users:
|
||||
|
||||
describe("pre 3.6.0-beta.1 config with an existing cluster", () => {
|
||||
beforeEach(() => {
|
||||
mockFs({
|
||||
"some-directory-for-user-data": {
|
||||
"lens-cluster-store.json": JSON.stringify({
|
||||
__internal__: {
|
||||
migrations: {
|
||||
version: "3.5.0",
|
||||
},
|
||||
},
|
||||
clusters: [
|
||||
{
|
||||
id: "cluster1",
|
||||
kubeConfig: minimalValidKubeConfig,
|
||||
contextName: "cluster",
|
||||
preferences: {
|
||||
icon: "store://icon_path",
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
icon_path: testDataIcon,
|
||||
writeJsonSync("/some-directory-for-user-data/lens-cluster-store.json", {
|
||||
__internal__: {
|
||||
migrations: {
|
||||
version: "3.5.0",
|
||||
},
|
||||
},
|
||||
clusters: [
|
||||
{
|
||||
id: "cluster1",
|
||||
kubeConfig: minimalValidKubeConfig,
|
||||
contextName: "cluster",
|
||||
preferences: {
|
||||
icon: "store://icon_path",
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
writeBufferSync("/some-directory-for-user-data/icon_path", testDataIcon);
|
||||
|
||||
mainDi.override(storeMigrationVersionInjectable, () => "3.6.0");
|
||||
di.override(storeMigrationVersionInjectable, () => "3.6.0");
|
||||
|
||||
createCluster = mainDi.inject(createClusterInjectionToken);
|
||||
|
||||
clusterStore = mainDi.inject(clusterStoreInjectable);
|
||||
clusterStore = di.inject(clusterStoreInjectable);
|
||||
clusterStore.load();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockFs.restore();
|
||||
});
|
||||
|
||||
it("migrates to modern format with kubeconfig in a file", async () => {
|
||||
const config = clusterStore.clustersList[0].kubeConfigPath;
|
||||
|
||||
expect(fs.readFileSync(config, "utf8")).toBe(minimalValidKubeConfig);
|
||||
expect(readFileSync(config)).toBe(minimalValidKubeConfig);
|
||||
});
|
||||
|
||||
it("migrates to modern format with icon not in file", async () => {
|
||||
const { icon } = clusterStore.clustersList[0].preferences;
|
||||
|
||||
assert(icon);
|
||||
expect(icon.startsWith("data:;base64,")).toBe(true);
|
||||
expect(clusterStore.clustersList[0].preferences.icon).toMatch(/data:;base64,/);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const invalidKubeconfig = JSON.stringify({
|
||||
apiVersion: "v1",
|
||||
clusters: [{
|
||||
cluster: {
|
||||
server: "https://localhost",
|
||||
},
|
||||
name: "test2",
|
||||
}],
|
||||
contexts: [{
|
||||
context: {
|
||||
cluster: "test",
|
||||
user: "test",
|
||||
},
|
||||
name: "test",
|
||||
}],
|
||||
"current-context": "test",
|
||||
kind: "Config",
|
||||
preferences: {},
|
||||
users: [{
|
||||
user: {
|
||||
token: "kubeconfig-user-q4lm4:xxxyyyy",
|
||||
},
|
||||
name: "test",
|
||||
}],
|
||||
});
|
||||
|
||||
const minimalValidKubeConfig = JSON.stringify({
|
||||
apiVersion: "v1",
|
||||
clusters: [
|
||||
|
||||
@ -4,10 +4,8 @@
|
||||
*/
|
||||
|
||||
import { anyObject } from "jest-mock-extended";
|
||||
import mockFs from "mock-fs";
|
||||
import type { CatalogEntity, CatalogEntityData, CatalogEntityKindData } from "../catalog";
|
||||
import { getDiForUnitTesting } from "../../main/getDiForUnitTesting";
|
||||
import getConfigurationFileModelInjectable from "../get-configuration-file-model/get-configuration-file-model.injectable";
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import hotbarStoreInjectable from "../hotbars/store.injectable";
|
||||
import type { HotbarStore } from "../hotbars/store";
|
||||
@ -19,7 +17,7 @@ import loggerInjectable from "../logger.injectable";
|
||||
import type { Logger } from "../logger";
|
||||
import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
import storeMigrationVersionInjectable from "../vars/store-migration-version.injectable";
|
||||
import fsInjectable from "../fs/fs.injectable";
|
||||
import writeJsonSyncInjectable from "../fs/write-json-sync.injectable";
|
||||
|
||||
function getMockCatalogEntity(data: Partial<CatalogEntityData> & CatalogEntityKindData): CatalogEntity {
|
||||
return {
|
||||
@ -47,8 +45,6 @@ describe("HotbarStore", () => {
|
||||
beforeEach(async () => {
|
||||
di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
|
||||
di.unoverride(hotbarStoreInjectable);
|
||||
|
||||
testCluster = getMockCatalogEntity({
|
||||
apiVersion: "v1",
|
||||
kind: "Cluster",
|
||||
@ -101,7 +97,7 @@ describe("HotbarStore", () => {
|
||||
|
||||
di.override(loggerInjectable, () => loggerMock);
|
||||
|
||||
di.override(directoryForUserDataInjectable, () => "some-directory-for-user-data");
|
||||
di.override(directoryForUserDataInjectable, () => "/some-directory-for-user-data");
|
||||
|
||||
const catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable);
|
||||
const catalogCatalogEntity = di.inject(catalogCatalogEntityInjectable);
|
||||
@ -112,20 +108,10 @@ describe("HotbarStore", () => {
|
||||
awsCluster,
|
||||
catalogCatalogEntity,
|
||||
]));
|
||||
|
||||
di.permitSideEffects(fsInjectable);
|
||||
di.permitSideEffects(getConfigurationFileModelInjectable);
|
||||
di.unoverride(getConfigurationFileModelInjectable);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockFs.restore();
|
||||
});
|
||||
|
||||
describe("given no previous data in store, running all migrations", () => {
|
||||
beforeEach(() => {
|
||||
mockFs();
|
||||
|
||||
hotbarStore = di.inject(hotbarStoreInjectable);
|
||||
|
||||
hotbarStore.load();
|
||||
@ -276,66 +262,64 @@ describe("HotbarStore", () => {
|
||||
|
||||
describe("given data from 5.0.0-beta.3 and version being 5.0.0-beta.10", () => {
|
||||
beforeEach(() => {
|
||||
mockFs({
|
||||
"some-directory-for-user-data": {
|
||||
"lens-hotbar-store.json": JSON.stringify({
|
||||
__internal__: {
|
||||
migrations: {
|
||||
version: "5.0.0-beta.3",
|
||||
},
|
||||
},
|
||||
hotbars: [
|
||||
{
|
||||
id: "3caac17f-aec2-4723-9694-ad204465d935",
|
||||
name: "myhotbar",
|
||||
items: [
|
||||
{
|
||||
entity: {
|
||||
uid: "some-aws-id",
|
||||
},
|
||||
},
|
||||
{
|
||||
entity: {
|
||||
uid: "55b42c3c7ba3b04193416cda405269a5",
|
||||
},
|
||||
},
|
||||
{
|
||||
entity: {
|
||||
uid: "176fd331968660832f62283219d7eb6e",
|
||||
},
|
||||
},
|
||||
{
|
||||
entity: {
|
||||
uid: "61c4fb45528840ebad1badc25da41d14",
|
||||
name: "user1-context",
|
||||
source: "local",
|
||||
},
|
||||
},
|
||||
{
|
||||
entity: {
|
||||
uid: "27d6f99fe9e7548a6e306760bfe19969",
|
||||
name: "foo2",
|
||||
source: "local",
|
||||
},
|
||||
},
|
||||
null,
|
||||
{
|
||||
entity: {
|
||||
uid: "c0b20040646849bb4dcf773e43a0bf27",
|
||||
name: "multinode-demo",
|
||||
source: "local",
|
||||
},
|
||||
},
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
],
|
||||
},
|
||||
],
|
||||
}),
|
||||
const writeJsonSync = di.inject(writeJsonSyncInjectable);
|
||||
|
||||
writeJsonSync("/some-directory-for-user-data/lens-hotbar-store.json", {
|
||||
__internal__: {
|
||||
migrations: {
|
||||
version: "5.0.0-beta.3",
|
||||
},
|
||||
},
|
||||
hotbars: [
|
||||
{
|
||||
id: "3caac17f-aec2-4723-9694-ad204465d935",
|
||||
name: "myhotbar",
|
||||
items: [
|
||||
{
|
||||
entity: {
|
||||
uid: "some-aws-id",
|
||||
},
|
||||
},
|
||||
{
|
||||
entity: {
|
||||
uid: "55b42c3c7ba3b04193416cda405269a5",
|
||||
},
|
||||
},
|
||||
{
|
||||
entity: {
|
||||
uid: "176fd331968660832f62283219d7eb6e",
|
||||
},
|
||||
},
|
||||
{
|
||||
entity: {
|
||||
uid: "61c4fb45528840ebad1badc25da41d14",
|
||||
name: "user1-context",
|
||||
source: "local",
|
||||
},
|
||||
},
|
||||
{
|
||||
entity: {
|
||||
uid: "27d6f99fe9e7548a6e306760bfe19969",
|
||||
name: "foo2",
|
||||
source: "local",
|
||||
},
|
||||
},
|
||||
null,
|
||||
{
|
||||
entity: {
|
||||
uid: "c0b20040646849bb4dcf773e43a0bf27",
|
||||
name: "multinode-demo",
|
||||
source: "local",
|
||||
},
|
||||
},
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
di.override(storeMigrationVersionInjectable, () => "5.0.0-beta.10");
|
||||
|
||||
@ -2,28 +2,7 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import mockFs from "mock-fs";
|
||||
|
||||
jest.mock("electron", () => ({
|
||||
app: {
|
||||
getVersion: () => "99.99.99",
|
||||
getName: () => "lens",
|
||||
setName: jest.fn(),
|
||||
setPath: jest.fn(),
|
||||
getPath: () => "tmp",
|
||||
getLocale: () => "en",
|
||||
setLoginItemSettings: jest.fn(),
|
||||
},
|
||||
ipcMain: {
|
||||
on: jest.fn(),
|
||||
handle: jest.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
import type { UserStore } from "../user-store";
|
||||
import { Console } from "console";
|
||||
import { stdout, stderr } from "process";
|
||||
import userStoreInjectable from "../user-store/user-store.injectable";
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
@ -31,13 +10,11 @@ import type { ClusterStoreModel } from "../cluster-store/cluster-store";
|
||||
import { defaultThemeId } from "../vars";
|
||||
import writeFileInjectable from "../fs/write-file.injectable";
|
||||
import { getDiForUnitTesting } from "../../main/getDiForUnitTesting";
|
||||
import getConfigurationFileModelInjectable from "../get-configuration-file-model/get-configuration-file-model.injectable";
|
||||
import storeMigrationVersionInjectable from "../vars/store-migration-version.injectable";
|
||||
import releaseChannelInjectable from "../vars/release-channel.injectable";
|
||||
import defaultUpdateChannelInjectable from "../../features/application-update/common/selected-update-channel/default-update-channel.injectable";
|
||||
import fsInjectable from "../fs/fs.injectable";
|
||||
|
||||
console = new Console(stdout, stderr);
|
||||
import writeJsonSyncInjectable from "../fs/write-json-sync.injectable";
|
||||
import writeFileSyncInjectable from "../fs/write-file-sync.injectable";
|
||||
|
||||
describe("user store tests", () => {
|
||||
let userStore: UserStore;
|
||||
@ -46,14 +23,8 @@ describe("user store tests", () => {
|
||||
beforeEach(async () => {
|
||||
di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
|
||||
mockFs();
|
||||
|
||||
di.override(writeFileInjectable, () => () => Promise.resolve());
|
||||
di.override(directoryForUserDataInjectable, () => "some-directory-for-user-data");
|
||||
|
||||
di.permitSideEffects(getConfigurationFileModelInjectable);
|
||||
di.unoverride(getConfigurationFileModelInjectable);
|
||||
di.permitSideEffects(fsInjectable);
|
||||
di.override(directoryForUserDataInjectable, () => "/some-directory-for-user-data");
|
||||
|
||||
di.override(releaseChannelInjectable, () => ({
|
||||
get: () => "latest" as const,
|
||||
@ -64,13 +35,12 @@ describe("user store tests", () => {
|
||||
userStore = di.inject(userStoreInjectable);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockFs.restore();
|
||||
});
|
||||
|
||||
describe("for an empty config", () => {
|
||||
beforeEach(() => {
|
||||
mockFs({ "some-directory-for-user-data": { "lens-user-store.json": "{}", "kube_config": "{}" }});
|
||||
const writeJsonSync = di.inject(writeJsonSyncInjectable);
|
||||
|
||||
writeJsonSync("/some-directory-for-user-data/lens-user-store.json", {});
|
||||
writeJsonSync("/some-directory-for-user-data/kube_config", {});
|
||||
|
||||
userStore.load();
|
||||
});
|
||||
@ -94,40 +64,38 @@ describe("user store tests", () => {
|
||||
|
||||
describe("migrations", () => {
|
||||
beforeEach(() => {
|
||||
mockFs({
|
||||
"some-directory-for-user-data": {
|
||||
"lens-user-store.json": JSON.stringify({
|
||||
preferences: { colorTheme: "light" },
|
||||
}),
|
||||
"lens-cluster-store.json": JSON.stringify({
|
||||
clusters: [
|
||||
{
|
||||
id: "foobar",
|
||||
kubeConfigPath: "some-directory-for-user-data/extension_data/foo/bar",
|
||||
},
|
||||
{
|
||||
id: "barfoo",
|
||||
kubeConfigPath: "some/other/path",
|
||||
},
|
||||
],
|
||||
} as ClusterStoreModel),
|
||||
"extension_data": {},
|
||||
},
|
||||
"some": {
|
||||
"other": {
|
||||
"path": "is file",
|
||||
},
|
||||
},
|
||||
const writeJsonSync = di.inject(writeJsonSyncInjectable);
|
||||
const writeFileSync = di.inject(writeFileSyncInjectable);
|
||||
|
||||
writeJsonSync("/some-directory-for-user-data/lens-user-store.json", {
|
||||
preferences: { colorTheme: "light" },
|
||||
});
|
||||
|
||||
writeJsonSync("/some-directory-for-user-data/lens-cluster-store.json", {
|
||||
clusters: [
|
||||
{
|
||||
id: "foobar",
|
||||
kubeConfigPath: "/some-directory-for-user-data/extension_data/foo/bar",
|
||||
},
|
||||
{
|
||||
id: "barfoo",
|
||||
kubeConfigPath: "/some/other/path",
|
||||
},
|
||||
],
|
||||
} as ClusterStoreModel);
|
||||
|
||||
writeJsonSync("/some-directory-for-user-data/extension_data", {});
|
||||
|
||||
writeFileSync("/some/other/path", "is file");
|
||||
|
||||
di.override(storeMigrationVersionInjectable, () => "10.0.0");
|
||||
|
||||
userStore.load();
|
||||
});
|
||||
|
||||
it("skips clusters for adding to kube-sync with files under extension_data/", () => {
|
||||
expect(userStore.syncKubeconfigEntries.has("some-directory-for-user-data/extension_data/foo/bar")).toBe(false);
|
||||
expect(userStore.syncKubeconfigEntries.has("some/other/path")).toBe(true);
|
||||
expect(userStore.syncKubeconfigEntries.has("/some-directory-for-user-data/extension_data/foo/bar")).toBe(false);
|
||||
expect(userStore.syncKubeconfigEntries.has("/some/other/path")).toBe(true);
|
||||
});
|
||||
|
||||
it("allows access to the colorTheme preference", () => {
|
||||
|
||||
@ -19,23 +19,23 @@ describe("app-paths", () => {
|
||||
builder = getApplicationBuilder();
|
||||
|
||||
const defaultAppPathsStub: AppPaths = {
|
||||
currentApp: "some-current-app",
|
||||
appData: "some-app-data",
|
||||
cache: "some-cache",
|
||||
crashDumps: "some-crash-dumps",
|
||||
desktop: "some-desktop",
|
||||
documents: "some-documents",
|
||||
downloads: "some-downloads",
|
||||
exe: "some-exe",
|
||||
home: "some-home-path",
|
||||
logs: "some-logs",
|
||||
module: "some-module",
|
||||
music: "some-music",
|
||||
pictures: "some-pictures",
|
||||
recent: "some-recent",
|
||||
temp: "some-temp",
|
||||
videos: "some-videos",
|
||||
userData: "some-irrelevant-user-data",
|
||||
currentApp: "/some-current-app",
|
||||
appData: "/some-app-data",
|
||||
cache: "/some-cache",
|
||||
crashDumps: "/some-crash-dumps",
|
||||
desktop: "/some-desktop",
|
||||
documents: "/some-documents",
|
||||
downloads: "/some-downloads",
|
||||
exe: "/some-exe",
|
||||
home: "/some-home-path",
|
||||
logs: "/some-logs",
|
||||
module: "/some-module",
|
||||
music: "/some-music",
|
||||
pictures: "/some-pictures",
|
||||
recent: "/some-recent",
|
||||
temp: "/some-temp",
|
||||
videos: "/some-videos",
|
||||
userData: "/some-irrelevant-user-data",
|
||||
};
|
||||
|
||||
builder.beforeApplicationStart((mainDi) => {
|
||||
@ -71,23 +71,23 @@ describe("app-paths", () => {
|
||||
const actual = windowDi.inject(appPathsInjectable);
|
||||
|
||||
expect(actual).toEqual({
|
||||
currentApp: "some-current-app",
|
||||
appData: "some-app-data",
|
||||
cache: "some-cache",
|
||||
crashDumps: "some-crash-dumps",
|
||||
desktop: "some-desktop",
|
||||
documents: "some-documents",
|
||||
downloads: "some-downloads",
|
||||
exe: "some-exe",
|
||||
home: "some-home-path",
|
||||
logs: "some-logs",
|
||||
module: "some-module",
|
||||
music: "some-music",
|
||||
pictures: "some-pictures",
|
||||
recent: "some-recent",
|
||||
temp: "some-temp",
|
||||
videos: "some-videos",
|
||||
userData: "some-app-data/some-product-name",
|
||||
currentApp: "/some-current-app",
|
||||
appData: "/some-app-data",
|
||||
cache: "/some-cache",
|
||||
crashDumps: "/some-crash-dumps",
|
||||
desktop: "/some-desktop",
|
||||
documents: "/some-documents",
|
||||
downloads: "/some-downloads",
|
||||
exe: "/some-exe",
|
||||
home: "/some-home-path",
|
||||
logs: "/some-logs",
|
||||
module: "/some-module",
|
||||
music: "/some-music",
|
||||
pictures: "/some-pictures",
|
||||
recent: "/some-recent",
|
||||
temp: "/some-temp",
|
||||
videos: "/some-videos",
|
||||
userData: "/some-app-data/some-product-name",
|
||||
});
|
||||
});
|
||||
|
||||
@ -95,23 +95,23 @@ describe("app-paths", () => {
|
||||
const actual = mainDi.inject(appPathsInjectable);
|
||||
|
||||
expect(actual).toEqual({
|
||||
currentApp: "some-current-app",
|
||||
appData: "some-app-data",
|
||||
cache: "some-cache",
|
||||
crashDumps: "some-crash-dumps",
|
||||
desktop: "some-desktop",
|
||||
documents: "some-documents",
|
||||
downloads: "some-downloads",
|
||||
exe: "some-exe",
|
||||
home: "some-home-path",
|
||||
logs: "some-logs",
|
||||
module: "some-module",
|
||||
music: "some-music",
|
||||
pictures: "some-pictures",
|
||||
recent: "some-recent",
|
||||
temp: "some-temp",
|
||||
videos: "some-videos",
|
||||
userData: "some-app-data/some-product-name",
|
||||
currentApp: "/some-current-app",
|
||||
appData: "/some-app-data",
|
||||
cache: "/some-cache",
|
||||
crashDumps: "/some-crash-dumps",
|
||||
desktop: "/some-desktop",
|
||||
documents: "/some-documents",
|
||||
downloads: "/some-downloads",
|
||||
exe: "/some-exe",
|
||||
home: "/some-home-path",
|
||||
logs: "/some-logs",
|
||||
module: "/some-module",
|
||||
music: "/some-music",
|
||||
pictures: "/some-pictures",
|
||||
recent: "/some-recent",
|
||||
temp: "/some-temp",
|
||||
videos: "/some-videos",
|
||||
userData: "/some-app-data/some-product-name",
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -123,7 +123,7 @@ describe("app-paths", () => {
|
||||
builder.beforeApplicationStart((mainDi) => {
|
||||
mainDi.override(
|
||||
directoryForIntegrationTestingInjectable,
|
||||
() => "some-integration-testing-app-data",
|
||||
() => "/some-integration-testing-app-data",
|
||||
);
|
||||
});
|
||||
|
||||
@ -136,8 +136,8 @@ describe("app-paths", () => {
|
||||
const { appData, userData } = windowDi.inject(appPathsInjectable);
|
||||
|
||||
expect({ appData, userData }).toEqual({
|
||||
appData: "some-integration-testing-app-data",
|
||||
userData: `some-integration-testing-app-data/some-product-name`,
|
||||
appData: "/some-integration-testing-app-data",
|
||||
userData: "/some-integration-testing-app-data/some-product-name",
|
||||
});
|
||||
});
|
||||
|
||||
@ -145,8 +145,8 @@ describe("app-paths", () => {
|
||||
const { appData, userData } = windowDi.inject(appPathsInjectable);
|
||||
|
||||
expect({ appData, userData }).toEqual({
|
||||
appData: "some-integration-testing-app-data",
|
||||
userData: "some-integration-testing-app-data/some-product-name",
|
||||
appData: "/some-integration-testing-app-data",
|
||||
userData: "/some-integration-testing-app-data/some-product-name",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -6,15 +6,17 @@ import { getInjectable } from "@ogre-tools/injectable";
|
||||
import directoryForKubeConfigsInjectable from "../directory-for-kube-configs/directory-for-kube-configs.injectable";
|
||||
import joinPathsInjectable from "../../path/join-paths.injectable";
|
||||
|
||||
const getCustomKubeConfigDirectoryInjectable = getInjectable({
|
||||
export type GetCustomKubeConfigFilePath = (fileName: string) => string;
|
||||
|
||||
const getCustomKubeConfigFilePathInjectable = getInjectable({
|
||||
id: "get-custom-kube-config-directory",
|
||||
|
||||
instantiate: (di) => {
|
||||
instantiate: (di): GetCustomKubeConfigFilePath => {
|
||||
const directoryForKubeConfigs = di.inject(directoryForKubeConfigsInjectable);
|
||||
const joinPaths = di.inject(joinPathsInjectable);
|
||||
|
||||
return (directoryName: string) => joinPaths(directoryForKubeConfigs, directoryName);
|
||||
return (fileName) => joinPaths(directoryForKubeConfigs, fileName);
|
||||
},
|
||||
});
|
||||
|
||||
export default getCustomKubeConfigDirectoryInjectable;
|
||||
export default getCustomKubeConfigFilePathInjectable;
|
||||
|
||||
@ -4,8 +4,6 @@
|
||||
*/
|
||||
|
||||
import { getGlobalOverride } from "../test-utils/get-global-override";
|
||||
import ensureDirInjectable from "./ensure-dir.injectable";
|
||||
import pathToNpmCliInjectable from "./path-to-npm-cli.injectable";
|
||||
|
||||
export default getGlobalOverride(ensureDirInjectable, () => async () => {
|
||||
throw new Error("tried to ensure directory without override");
|
||||
});
|
||||
export default getGlobalOverride(pathToNpmCliInjectable, () => "/some/npm/cli/path");
|
||||
13
src/common/app-paths/path-to-npm-cli.injectable.ts
Normal file
13
src/common/app-paths/path-to-npm-cli.injectable.ts
Normal file
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* 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";
|
||||
|
||||
const pathToNpmCliInjectable = getInjectable({
|
||||
id: "path-to-npm-cli",
|
||||
instantiate: () => __non_webpack_require__.resolve("npm"),
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default pathToNpmCliInjectable;
|
||||
@ -3,8 +3,8 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { navigate } from "../../renderer/navigation";
|
||||
import type { CatalogEntityMetadata, CatalogEntitySpec, CatalogEntityStatus } from "../catalog";
|
||||
import type { CatalogEntityActionContext } from "../catalog/catalog-entity";
|
||||
import { CatalogCategory, CatalogEntity, categoryVersion } from "../catalog/catalog-entity";
|
||||
|
||||
interface GeneralEntitySpec extends CatalogEntitySpec {
|
||||
@ -19,8 +19,8 @@ export class GeneralEntity extends CatalogEntity<CatalogEntityMetadata, CatalogE
|
||||
public readonly apiVersion = "entity.k8slens.dev/v1alpha1";
|
||||
public readonly kind = "General";
|
||||
|
||||
async onRun() {
|
||||
navigate(this.spec.path);
|
||||
async onRun(context: CatalogEntityActionContext) {
|
||||
context.navigate(this.spec.path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -11,8 +11,8 @@ import type { CatalogEntityConstructor, CatalogEntitySpec } from "../catalog/cat
|
||||
import { IpcRendererNavigationEvents } from "../../renderer/navigation/events";
|
||||
import { requestClusterActivation, requestClusterDisconnection } from "../../renderer/ipc";
|
||||
import KubeClusterCategoryIcon from "./icons/kubernetes.svg";
|
||||
import { asLegacyGlobalFunctionForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/as-legacy-global-function-for-extension-api";
|
||||
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";
|
||||
|
||||
export interface KubernetesClusterPrometheusMetrics {
|
||||
address?: {
|
||||
@ -64,8 +64,6 @@ export function isKubernetesCluster(item: unknown): item is KubernetesCluster {
|
||||
return item instanceof KubernetesCluster;
|
||||
}
|
||||
|
||||
const getClusterById = asLegacyGlobalFunctionForExtensionApi(getClusterByIdInjectable);
|
||||
|
||||
export class KubernetesCluster<
|
||||
Metadata extends KubernetesClusterMetadata = KubernetesClusterMetadata,
|
||||
Status extends KubernetesClusterStatus = KubernetesClusterStatus,
|
||||
@ -79,6 +77,9 @@ export class KubernetesCluster<
|
||||
|
||||
async connect(): Promise<void> {
|
||||
if (app) {
|
||||
const di = getLegacyGlobalDiForExtensionApi();
|
||||
const getClusterById = di.inject(getClusterByIdInjectable);
|
||||
|
||||
await getClusterById(this.getId())?.activate();
|
||||
} else {
|
||||
await requestClusterActivation(this.getId(), false);
|
||||
@ -87,6 +88,9 @@ export class KubernetesCluster<
|
||||
|
||||
async disconnect(): Promise<void> {
|
||||
if (app) {
|
||||
const di = getLegacyGlobalDiForExtensionApi();
|
||||
const getClusterById = di.inject(getClusterByIdInjectable);
|
||||
|
||||
getClusterById(this.getId())?.disconnect();
|
||||
} else {
|
||||
await requestClusterDisconnection(this.getId(), false);
|
||||
|
||||
29
src/common/fs/write-buffer-sync.injectable.ts
Normal file
29
src/common/fs/write-buffer-sync.injectable.ts
Normal file
@ -0,0 +1,29 @@
|
||||
/**
|
||||
* 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 getDirnameOfPathInjectable from "../path/get-dirname.injectable";
|
||||
import fsInjectable from "./fs.injectable";
|
||||
|
||||
export type WriteBufferSync = (filePath: string, contents: Buffer) => void;
|
||||
|
||||
const writeBufferSyncInjectable = getInjectable({
|
||||
id: "write-buffer-sync",
|
||||
instantiate: (di): WriteBufferSync => {
|
||||
const {
|
||||
writeFileSync,
|
||||
ensureDirSync,
|
||||
} = di.inject(fsInjectable);
|
||||
const getDirnameOfPath = di.inject(getDirnameOfPathInjectable);
|
||||
|
||||
return (filePath, contents) => {
|
||||
ensureDirSync(getDirnameOfPath(filePath), {
|
||||
mode: 0o755,
|
||||
});
|
||||
writeFileSync(filePath, contents);
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default writeBufferSyncInjectable;
|
||||
@ -10,6 +10,34 @@ import getConfigurationFileModelInjectable from "./get-configuration-file-model.
|
||||
import type Config from "conf";
|
||||
import readJsonSyncInjectable from "../fs/read-json-sync.injectable";
|
||||
import writeJsonSyncInjectable from "../fs/write-json-sync.injectable";
|
||||
import { get, set } from "lodash";
|
||||
import semver from "semver";
|
||||
|
||||
const MIGRATION_KEY = `__internal__.migrations.version`;
|
||||
|
||||
const _isVersionInRangeFormat = (version: string) => {
|
||||
return semver.clean(version) === null;
|
||||
};
|
||||
|
||||
const _shouldPerformMigration = (candidateVersion: string, previousMigratedVersion: string, versionToMigrate: string) => {
|
||||
if (_isVersionInRangeFormat(candidateVersion)) {
|
||||
if (previousMigratedVersion !== "0.0.0" && semver.satisfies(previousMigratedVersion, candidateVersion)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return semver.satisfies(versionToMigrate, candidateVersion);
|
||||
}
|
||||
|
||||
if (semver.lte(candidateVersion, previousMigratedVersion)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (semver.gt(candidateVersion, versionToMigrate)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
export default getGlobalOverride(getConfigurationFileModelInjectable, (di) => {
|
||||
const readJsonSync = di.inject(readJsonSyncInjectable);
|
||||
@ -18,6 +46,7 @@ export default getGlobalOverride(getConfigurationFileModelInjectable, (di) => {
|
||||
return (options) => {
|
||||
assert(options.cwd, "Missing options.cwd");
|
||||
assert(options.configName, "Missing options.configName");
|
||||
assert(options.projectVersion, "Missing options.projectVersion");
|
||||
|
||||
const configFilePath = path.posix.join(options.cwd, `${options.configName}.json`);
|
||||
let store: object = {};
|
||||
@ -28,11 +57,12 @@ export default getGlobalOverride(getConfigurationFileModelInjectable, (di) => {
|
||||
// ignore
|
||||
}
|
||||
|
||||
return {
|
||||
const config = {
|
||||
get store() {
|
||||
return store;
|
||||
},
|
||||
path: configFilePath,
|
||||
get: (key: string) => get(store, key),
|
||||
set: (key: string, value: unknown) => {
|
||||
let currentState: object;
|
||||
|
||||
@ -49,5 +79,35 @@ export default getGlobalOverride(getConfigurationFileModelInjectable, (di) => {
|
||||
store = readJsonSync(configFilePath);
|
||||
},
|
||||
} as Partial<Config> as Config<any>;
|
||||
|
||||
// Migrate
|
||||
{
|
||||
const migrations = options.migrations ?? [];
|
||||
const versionToMigrate = options.projectVersion;
|
||||
let previousMigratedVersion = get(store, MIGRATION_KEY) || "0.0.0";
|
||||
const newerVersions = Object.entries(migrations)
|
||||
.filter(([candidateVersion]) => _shouldPerformMigration(candidateVersion, previousMigratedVersion, versionToMigrate));
|
||||
|
||||
let storeBackup = { ...store };
|
||||
|
||||
for (const [version, migration] of newerVersions) {
|
||||
try {
|
||||
migration(config);
|
||||
set(store, MIGRATION_KEY, version);
|
||||
previousMigratedVersion = version;
|
||||
storeBackup = { ...store };
|
||||
}
|
||||
catch (error) {
|
||||
store = storeBackup;
|
||||
throw new Error(`Something went wrong during the migration! Changes applied to the store until this failed migration will be restored. ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (_isVersionInRangeFormat(previousMigratedVersion) || !semver.eq(previousMigratedVersion, versionToMigrate)) {
|
||||
set(store, MIGRATION_KEY, versionToMigrate);
|
||||
}
|
||||
}
|
||||
|
||||
return config;
|
||||
};
|
||||
});
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverrideForFunction } from "../test-utils/get-global-override-for-function";
|
||||
import broadcastMessageInjectable from "./broadcast-message.injectable";
|
||||
|
||||
export default getGlobalOverrideForFunction(broadcastMessageInjectable);
|
||||
@ -9,13 +9,13 @@
|
||||
|
||||
import { ipcMain, ipcRenderer, webContents } from "electron";
|
||||
import { toJS } from "../utils/toJS";
|
||||
import logger from "../../main/logger";
|
||||
import type { ClusterFrameInfo } from "../cluster-frames";
|
||||
import { clusterFrameMap } from "../cluster-frames";
|
||||
import type { Disposer } from "../utils";
|
||||
import ipcMainInjectable from "../../main/utils/channel/ipc-main/ipc-main.injectable";
|
||||
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";
|
||||
|
||||
export const broadcastMainChannel = "ipc:broadcast-main";
|
||||
|
||||
@ -42,6 +42,9 @@ export async function broadcastMessage(channel: string, ...args: any[]): Promise
|
||||
return;
|
||||
}
|
||||
|
||||
const di = getLegacyGlobalDiForExtensionApi();
|
||||
const logger = di.inject(loggerInjectable);
|
||||
|
||||
ipcMain.listeners(channel).forEach((func) => func({
|
||||
processId: undefined, frameId: undefined, sender: undefined, senderFrame: undefined,
|
||||
}, ...args));
|
||||
|
||||
@ -11,11 +11,13 @@ import { getDiForUnitTesting } from "../../../renderer/getDiForUnitTesting";
|
||||
import storesAndApisCanBeCreatedInjectable from "../../../renderer/stores-apis-can-be-created.injectable";
|
||||
import directoryForKubeConfigsInjectable from "../../app-paths/directory-for-kube-configs/directory-for-kube-configs.injectable";
|
||||
import directoryForUserDataInjectable from "../../app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import type { ApiManager } from "../api-manager";
|
||||
import apiManagerInjectable from "../api-manager/manager.injectable";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { KubeObjectStore } from "../kube-object.store";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
class TestApi extends KubeApi<KubeObject> {
|
||||
protected async checkPreferredVersion() {
|
||||
@ -56,6 +58,9 @@ describe("ApiManager", () => {
|
||||
const apiBase = "apis/v1/foo";
|
||||
const fallbackApiBase = "/apis/extensions/v1beta1/foo";
|
||||
const kubeApi = new TestApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
}, {
|
||||
objectConstructor: KubeObject,
|
||||
apiBase,
|
||||
kind: "foo",
|
||||
@ -64,6 +69,7 @@ describe("ApiManager", () => {
|
||||
});
|
||||
const kubeStore = new TestStore({
|
||||
context: di.inject(clusterFrameContextForNamespacedResourcesInjectable),
|
||||
logger: di.inject(loggerInjectable),
|
||||
}, kubeApi);
|
||||
|
||||
apiManager.registerApi(apiBase, kubeApi);
|
||||
|
||||
@ -2,9 +2,9 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { KubeJsonApi } from "../kube-json-api";
|
||||
import type { ApiManager } from "../api-manager";
|
||||
import { Ingress, IngressApi } from "../endpoints";
|
||||
import type { IngressApi } from "../endpoints";
|
||||
import { Ingress } from "../endpoints";
|
||||
import { getDiForUnitTesting } from "../../../renderer/getDiForUnitTesting";
|
||||
import apiManagerInjectable from "../api-manager/manager.injectable";
|
||||
import type { Fetch } from "../../fetch/fetch.injectable";
|
||||
@ -20,14 +20,17 @@ import directoryForUserDataInjectable from "../../app-paths/directory-for-user-d
|
||||
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";
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import ingressApiInjectable from "../endpoints/ingress.api.injectable";
|
||||
|
||||
describe("KubeApi", () => {
|
||||
let request: KubeJsonApi;
|
||||
let di: DiContainer;
|
||||
let registerApiSpy: jest.SpiedFunction<ApiManager["registerApi"]>;
|
||||
let fetchMock: AsyncFnMock<Fetch>;
|
||||
|
||||
beforeEach(async () => {
|
||||
const di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
|
||||
fetchMock = asyncFn();
|
||||
di.override(fetchInjectable, () => fetchMock);
|
||||
@ -37,6 +40,7 @@ describe("KubeApi", () => {
|
||||
di.override(storesAndApisCanBeCreatedInjectable, () => true);
|
||||
|
||||
const createCluster = di.inject(createClusterInjectable);
|
||||
const createKubeJsonApi = di.inject(createKubeJsonApiInjectable);
|
||||
|
||||
di.override(hostedClusterInjectable, () => createCluster({
|
||||
contextName: "some-context-name",
|
||||
@ -46,12 +50,11 @@ describe("KubeApi", () => {
|
||||
clusterServerUrl: "https://localhost:8080",
|
||||
}));
|
||||
|
||||
const createKubeJsonApi = di.inject(createKubeJsonApiInjectable);
|
||||
|
||||
request = createKubeJsonApi({
|
||||
di.override(apiKubeInjectable, () => createKubeJsonApi({
|
||||
serverAddress: `http://127.0.0.1:9999`,
|
||||
apiBase: "/api-kube",
|
||||
});
|
||||
}));
|
||||
|
||||
registerApiSpy = jest.spyOn(di.inject(apiManagerInjectable), "registerApi");
|
||||
|
||||
const setupAutoRegistration = di.inject(setupAutoRegistrationInjectable);
|
||||
@ -64,13 +67,7 @@ describe("KubeApi", () => {
|
||||
let getCall: Promise<Ingress | null>;
|
||||
|
||||
beforeEach(async () => {
|
||||
ingressApi = new IngressApi({
|
||||
request,
|
||||
objectConstructor: Ingress,
|
||||
apiBase: "/apis/networking.k8s.io/v1/ingresses",
|
||||
fallbackApiBases: ["/apis/extensions/v1beta1/ingresses"],
|
||||
checkPreferredVersion: true,
|
||||
});
|
||||
ingressApi = di.inject(ingressApiInjectable);
|
||||
getCall = ingressApi.get({
|
||||
name: "foo",
|
||||
namespace: "default",
|
||||
|
||||
@ -4,9 +4,10 @@
|
||||
*/
|
||||
import type { KubeApiWatchCallback } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApi, KubeJsonApiData } from "../kube-json-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import { PassThrough } from "stream";
|
||||
import { Deployment, DeploymentApi, NamespaceApi, Pod, PodApi } from "../endpoints";
|
||||
import type { DeploymentApi, NamespaceApi } from "../endpoints";
|
||||
import { Deployment, Pod, PodApi } from "../endpoints";
|
||||
import { getDiForUnitTesting } from "../../../renderer/getDiForUnitTesting";
|
||||
import type { Fetch } from "../../fetch/fetch.injectable";
|
||||
import fetchInjectable from "../../fetch/fetch.injectable";
|
||||
@ -26,6 +27,15 @@ import directoryForUserDataInjectable from "../../app-paths/directory-for-user-d
|
||||
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";
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import deploymentApiInjectable from "../endpoints/deployment.api.injectable";
|
||||
import podApiInjectable from "../endpoints/pod.api.injectable";
|
||||
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";
|
||||
|
||||
describe("createKubeApiForRemoteCluster", () => {
|
||||
let createKubeApiForRemoteCluster: CreateKubeApiForRemoteCluster;
|
||||
@ -78,7 +88,7 @@ describe("createKubeApiForRemoteCluster", () => {
|
||||
user: {
|
||||
token: "daa",
|
||||
},
|
||||
}, Pod, PodApi);
|
||||
}, Pod, PodsApi);
|
||||
});
|
||||
|
||||
it("uses the constructor", () => {
|
||||
@ -131,17 +141,21 @@ describe("createKubeApiForRemoteCluster", () => {
|
||||
});
|
||||
|
||||
describe("KubeApi", () => {
|
||||
let request: KubeJsonApi;
|
||||
let fetchMock: AsyncFnMock<Fetch>;
|
||||
let di: DiContainer;
|
||||
|
||||
beforeEach(async () => {
|
||||
const di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
|
||||
di.override(directoryForUserDataInjectable, () => "/some-user-store-path");
|
||||
di.override(directoryForKubeConfigsInjectable, () => "/some-kube-configs");
|
||||
di.override(storesAndApisCanBeCreatedInjectable, () => true);
|
||||
|
||||
fetchMock = asyncFn();
|
||||
di.override(fetchInjectable, () => fetchMock);
|
||||
|
||||
const createCluster = di.inject(createClusterInjectable);
|
||||
const createKubeJsonApi = di.inject(createKubeJsonApiInjectable);
|
||||
|
||||
di.override(hostedClusterInjectable, () => createCluster({
|
||||
contextName: "some-context-name",
|
||||
@ -151,15 +165,10 @@ describe("KubeApi", () => {
|
||||
clusterServerUrl: "https://localhost:8080",
|
||||
}));
|
||||
|
||||
fetchMock = asyncFn();
|
||||
di.override(fetchInjectable, () => fetchMock);
|
||||
|
||||
const createKubeJsonApi = di.inject(createKubeJsonApiInjectable);
|
||||
|
||||
request = createKubeJsonApi({
|
||||
di.override(apiKubeInjectable, () => createKubeJsonApi({
|
||||
serverAddress: `http://127.0.0.1:9999`,
|
||||
apiBase: "/api-kube",
|
||||
});
|
||||
}));
|
||||
|
||||
const setupAutoRegistration = di.inject(setupAutoRegistrationInjectable);
|
||||
|
||||
@ -170,9 +179,7 @@ describe("KubeApi", () => {
|
||||
let api: DeploymentApi;
|
||||
|
||||
beforeEach(() => {
|
||||
api = new DeploymentApi({
|
||||
request,
|
||||
});
|
||||
api = di.inject(deploymentApiInjectable);
|
||||
});
|
||||
|
||||
describe("when patching a resource without providing a strategy", () => {
|
||||
@ -337,9 +344,7 @@ describe("KubeApi", () => {
|
||||
let api: PodApi;
|
||||
|
||||
beforeEach(() => {
|
||||
api = new PodApi({
|
||||
request,
|
||||
});
|
||||
api = di.inject(podApiInjectable);
|
||||
});
|
||||
|
||||
describe("when deleting by just name", () => {
|
||||
@ -455,9 +460,7 @@ describe("KubeApi", () => {
|
||||
let api: NamespaceApi;
|
||||
|
||||
beforeEach(() => {
|
||||
api = new NamespaceApi({
|
||||
request,
|
||||
});
|
||||
api = di.inject(namespaceApiInjectable);
|
||||
});
|
||||
|
||||
describe("when deleting by just name", () => {
|
||||
@ -544,9 +547,7 @@ describe("KubeApi", () => {
|
||||
let stream: PassThrough;
|
||||
|
||||
beforeEach(() => {
|
||||
api = new PodApi({
|
||||
request,
|
||||
});
|
||||
api = di.inject(podApiInjectable);
|
||||
stream = new PassThrough();
|
||||
});
|
||||
|
||||
@ -873,9 +874,7 @@ describe("KubeApi", () => {
|
||||
let api: PodApi;
|
||||
|
||||
beforeEach(() => {
|
||||
api = new PodApi({
|
||||
request,
|
||||
});
|
||||
api = di.inject(podApiInjectable);
|
||||
});
|
||||
|
||||
describe("when creating a pod", () => {
|
||||
@ -988,9 +987,7 @@ describe("KubeApi", () => {
|
||||
let api: PodApi;
|
||||
|
||||
beforeEach(() => {
|
||||
api = new PodApi({
|
||||
request,
|
||||
});
|
||||
api = di.inject(podApiInjectable);
|
||||
});
|
||||
|
||||
describe("when updating a pod", () => {
|
||||
@ -1100,9 +1097,7 @@ describe("KubeApi", () => {
|
||||
let api: PodApi;
|
||||
|
||||
beforeEach(() => {
|
||||
api = new PodApi({
|
||||
request,
|
||||
});
|
||||
api = di.inject(podApiInjectable);
|
||||
});
|
||||
|
||||
describe("when listing pods with no descriptor", () => {
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { noop } from "../../utils";
|
||||
import type { KubeApi } from "../kube-api";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { KubeObjectStoreLoadingParams } from "../kube-object.store";
|
||||
@ -18,6 +19,13 @@ class FakeKubeObjectStore extends KubeObjectStore<KubeObject> {
|
||||
isGlobalWatchEnabled: () => true,
|
||||
isLoadingAll: () => true,
|
||||
},
|
||||
logger: {
|
||||
debug: noop,
|
||||
error: noop,
|
||||
info: noop,
|
||||
silly: noop,
|
||||
warn: noop,
|
||||
},
|
||||
}, api as KubeApi<KubeObject>);
|
||||
}
|
||||
|
||||
|
||||
@ -3,11 +3,12 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import loggerInjectable from "../logger.injectable";
|
||||
import { apiKubePrefix } from "../vars";
|
||||
import isDevelopmentInjectable from "../vars/is-development.injectable";
|
||||
import apiBaseInjectable from "./api-base.injectable";
|
||||
import type { KubeApiConstructor } from "./create-kube-api-for-remote-cluster.injectable";
|
||||
import createKubeJsonApiInjectable from "./create-kube-json-api.injectable";
|
||||
import type { KubeApiOptions } from "./kube-api";
|
||||
import { KubeApi } from "./kube-api";
|
||||
import type { KubeJsonApiDataFor, KubeObject, KubeObjectConstructor } from "./kube-object";
|
||||
|
||||
@ -21,12 +22,12 @@ export interface CreateKubeApiForCluster {
|
||||
<Object extends KubeObject, Api extends KubeApi<Object>, Data extends KubeJsonApiDataFor<Object>>(
|
||||
cluster: CreateKubeApiForLocalClusterConfig,
|
||||
kubeClass: KubeObjectConstructor<Object, Data>,
|
||||
apiClass: new (apiOpts: KubeApiOptions<Object>) => Api
|
||||
apiClass: KubeApiConstructor<Object, Api>,
|
||||
): Api;
|
||||
<Object extends KubeObject, Data extends KubeJsonApiDataFor<Object>>(
|
||||
cluster: CreateKubeApiForLocalClusterConfig,
|
||||
kubeClass: KubeObjectConstructor<Object, Data>,
|
||||
apiClass?: new (apiOpts: KubeApiOptions<Object>) => KubeApi<Object>
|
||||
apiClass?: KubeApiConstructor<Object, KubeApi<Object>>,
|
||||
): KubeApi<Object>;
|
||||
}
|
||||
|
||||
@ -36,27 +37,42 @@ const createKubeApiForClusterInjectable = getInjectable({
|
||||
const apiBase = di.inject(apiBaseInjectable);
|
||||
const isDevelopment = di.inject(isDevelopmentInjectable);
|
||||
const createKubeJsonApi = di.inject(createKubeJsonApiInjectable);
|
||||
const logger = di.inject(loggerInjectable);
|
||||
|
||||
return (
|
||||
cluster: CreateKubeApiForLocalClusterConfig,
|
||||
kubeClass: KubeObjectConstructor<KubeObject, KubeJsonApiDataFor<KubeObject>>,
|
||||
apiClass = KubeApi,
|
||||
) => (
|
||||
new apiClass({
|
||||
objectConstructor: kubeClass,
|
||||
request: createKubeJsonApi(
|
||||
{
|
||||
serverAddress: apiBase.config.serverAddress,
|
||||
apiBase: apiKubePrefix,
|
||||
debug: isDevelopment,
|
||||
}, {
|
||||
headers: {
|
||||
"Host": `${cluster.metadata.uid}.lens.app:${new URL(apiBase.config.serverAddress).port}`,
|
||||
},
|
||||
apiClass?: KubeApiConstructor<KubeObject, KubeApi<KubeObject>>,
|
||||
) => {
|
||||
const request = createKubeJsonApi(
|
||||
{
|
||||
serverAddress: apiBase.config.serverAddress,
|
||||
apiBase: apiKubePrefix,
|
||||
debug: isDevelopment,
|
||||
}, {
|
||||
headers: {
|
||||
"Host": `${cluster.metadata.uid}.lens.app:${new URL(apiBase.config.serverAddress).port}`,
|
||||
},
|
||||
),
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
if (apiClass) {
|
||||
return new apiClass({
|
||||
objectConstructor: kubeClass,
|
||||
request,
|
||||
});
|
||||
}
|
||||
|
||||
return new KubeApi(
|
||||
{
|
||||
logger,
|
||||
maybeKubeApi: undefined,
|
||||
},
|
||||
{
|
||||
objectConstructor: kubeClass,
|
||||
request,
|
||||
},
|
||||
);
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { AgentOptions } from "https";
|
||||
import { Agent } from "https";
|
||||
import type { RequestInit } from "node-fetch";
|
||||
import loggerInjectable from "../logger.injectable";
|
||||
import isDevelopmentInjectable from "../vars/is-development.injectable";
|
||||
import createKubeJsonApiInjectable from "./create-kube-json-api.injectable";
|
||||
import type { KubeApiOptions } from "./kube-api";
|
||||
@ -32,16 +33,18 @@ export interface CreateKubeApiForRemoteClusterConfig {
|
||||
agent?: Agent;
|
||||
}
|
||||
|
||||
export type KubeApiConstructor<Object extends KubeObject, Api extends KubeApi<Object>> = new (apiOpts: KubeApiOptions<Object>) => Api;
|
||||
|
||||
export interface CreateKubeApiForRemoteCluster {
|
||||
<Object extends KubeObject, Api extends KubeApi<Object>, Data extends KubeJsonApiDataFor<Object>>(
|
||||
config: CreateKubeApiForRemoteClusterConfig,
|
||||
kubeClass: KubeObjectConstructor<Object, Data>,
|
||||
apiClass: new (apiOpts: KubeApiOptions<Object>) => Api,
|
||||
apiClass: KubeApiConstructor<Object, Api>,
|
||||
): Api;
|
||||
<Object extends KubeObject, Data extends KubeJsonApiDataFor<Object>>(
|
||||
config: CreateKubeApiForRemoteClusterConfig,
|
||||
kubeClass: KubeObjectConstructor<Object, Data>,
|
||||
apiClass?: new (apiOpts: KubeApiOptions<Object>) => KubeApi<Object>,
|
||||
apiClass?: KubeApiConstructor<Object, KubeApi<Object>>,
|
||||
): KubeApi<Object>;
|
||||
}
|
||||
|
||||
@ -50,8 +53,13 @@ const createKubeApiForRemoteClusterInjectable = getInjectable({
|
||||
instantiate: (di): CreateKubeApiForRemoteCluster => {
|
||||
const isDevelopment = di.inject(isDevelopmentInjectable);
|
||||
const createKubeJsonApi = di.inject(createKubeJsonApiInjectable);
|
||||
const logger = di.inject(loggerInjectable);
|
||||
|
||||
return (config: CreateKubeApiForRemoteClusterConfig, kubeClass: KubeObjectConstructor<KubeObject, KubeJsonApiDataFor<KubeObject>>, apiClass = KubeApi) => {
|
||||
return (
|
||||
config: CreateKubeApiForRemoteClusterConfig,
|
||||
kubeClass: KubeObjectConstructor<KubeObject, KubeJsonApiDataFor<KubeObject>>,
|
||||
apiClass?: KubeApiConstructor<KubeObject, KubeApi<KubeObject>>,
|
||||
) => {
|
||||
const reqInit: RequestInit = {};
|
||||
const agentOptions: AgentOptions = {};
|
||||
|
||||
@ -93,10 +101,23 @@ const createKubeApiForRemoteClusterInjectable = getInjectable({
|
||||
} : {}),
|
||||
}, reqInit);
|
||||
|
||||
return new apiClass({
|
||||
objectConstructor: kubeClass,
|
||||
request,
|
||||
});
|
||||
if (apiClass) {
|
||||
return new apiClass({
|
||||
objectConstructor: kubeClass,
|
||||
request,
|
||||
});
|
||||
}
|
||||
|
||||
return new KubeApi(
|
||||
{
|
||||
logger,
|
||||
maybeKubeApi: undefined,
|
||||
},
|
||||
{
|
||||
objectConstructor: kubeClass,
|
||||
request,
|
||||
},
|
||||
);
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
26
src/common/k8s-api/create-kube-api.injectable.ts
Normal file
26
src/common/k8s-api/create-kube-api.injectable.ts
Normal file
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* 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 loggerInjectable from "../logger.injectable";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "./kube-api";
|
||||
import maybeKubeApiInjectable from "./maybe-kube-api.injectable";
|
||||
|
||||
export interface CreateKubeApi {
|
||||
<Api>(ctor: new (deps: KubeApiDependencies, opts: DerivedKubeApiOptions) => Api, opts?: DerivedKubeApiOptions): Api;
|
||||
}
|
||||
|
||||
const createKubeApiInjectable = getInjectable({
|
||||
id: "create-kube-api",
|
||||
instantiate: (di): CreateKubeApi => {
|
||||
const deps: KubeApiDependencies = {
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
};
|
||||
|
||||
return (ctor, opts) => new ctor(deps, opts ?? {});
|
||||
},
|
||||
});
|
||||
|
||||
export default createKubeApiInjectable;
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { ClusterRoleBindingApi } from "./cluster-role-binding.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const clusterRoleBindingApiInjectable = getInjectable({
|
||||
id: "cluster-role-binding-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "clusterRoleBindingApi is only accessible in certain environments");
|
||||
|
||||
return new ClusterRoleBindingApi();
|
||||
return new ClusterRoleBindingApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -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 { DerivedKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import type { ClusterScopedMetadata, KubeObjectMetadata, KubeObjectScope } from "../kube-object";
|
||||
@ -47,8 +47,8 @@ export class ClusterRoleBinding extends KubeObject<
|
||||
}
|
||||
|
||||
export class ClusterRoleBindingApi extends KubeApi<ClusterRoleBinding, ClusterRoleBindingData> {
|
||||
constructor(opts: DerivedKubeApiOptions = {}) {
|
||||
super({
|
||||
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
|
||||
super(deps, {
|
||||
...opts,
|
||||
objectConstructor: ClusterRoleBinding,
|
||||
});
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { ClusterRoleApi } from "./cluster-role.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const clusterRoleApiInjectable = getInjectable({
|
||||
id: "cluster-role-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "clusterRoleApi is only available in certain environments");
|
||||
|
||||
return new ClusterRoleApi();
|
||||
return new ClusterRoleApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { DerivedKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import type { ClusterScopedMetadata, KubeObjectMetadata, KubeObjectScope } from "../kube-object";
|
||||
@ -40,8 +40,8 @@ export class ClusterRole extends KubeObject<
|
||||
}
|
||||
|
||||
export class ClusterRoleApi extends KubeApi<ClusterRole, ClusterRoleData> {
|
||||
constructor(opts: DerivedKubeApiOptions = {}) {
|
||||
super({
|
||||
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
|
||||
super(deps, {
|
||||
...opts,
|
||||
objectConstructor: ClusterRole,
|
||||
});
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { ClusterApi } from "./cluster.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const clusterApiInjectable = getInjectable({
|
||||
id: "cluster-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "clusterApi is only available in certain environments");
|
||||
|
||||
return new ClusterApi();
|
||||
return new ClusterApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
|
||||
export class ClusterApi extends KubeApi<Cluster> {
|
||||
@ -18,9 +18,9 @@ export class ClusterApi extends KubeApi<Cluster> {
|
||||
*/
|
||||
static namespaced = true;
|
||||
|
||||
constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) {
|
||||
super({
|
||||
...opts,
|
||||
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
|
||||
super(deps, {
|
||||
...opts ?? {},
|
||||
objectConstructor: Cluster,
|
||||
});
|
||||
}
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { ComponentStatusApi } from "./component-status.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
|
||||
const componentStatusApiInjectable = getInjectable({
|
||||
id: "component-status-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "componentStatusApi is only available in certain environments");
|
||||
|
||||
return new ComponentStatusApi();
|
||||
return new ComponentStatusApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { DerivedKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
|
||||
export interface ComponentStatusCondition {
|
||||
@ -28,8 +28,8 @@ export class ComponentStatus extends KubeObject {
|
||||
}
|
||||
|
||||
export class ComponentStatusApi extends KubeApi<ComponentStatus> {
|
||||
constructor(opts: DerivedKubeApiOptions = {}) {
|
||||
super({
|
||||
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
|
||||
super(deps, {
|
||||
...opts,
|
||||
objectConstructor: ComponentStatus,
|
||||
});
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { ConfigMapApi } from "./config-map.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const configMapApiInjectable = getInjectable({
|
||||
id: "config-map-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "configMapApi is only available in certain environments");
|
||||
|
||||
return new ConfigMapApi();
|
||||
return new ConfigMapApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
import type { KubeObjectMetadata, KubeObjectScope, NamespaceScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import type { DerivedKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { autoBind } from "../../utils";
|
||||
|
||||
@ -44,8 +44,8 @@ export class ConfigMap extends KubeObject<
|
||||
}
|
||||
|
||||
export class ConfigMapApi extends KubeApi<ConfigMap, ConfigMapData> {
|
||||
constructor(opts?: DerivedKubeApiOptions) {
|
||||
super({
|
||||
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
|
||||
super(deps, {
|
||||
objectConstructor: ConfigMap,
|
||||
...opts ?? {},
|
||||
});
|
||||
|
||||
@ -7,6 +7,8 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { CronJobApi } from "./cron-job.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const cronJobApiInjectable = getInjectable({
|
||||
id: "cron-job-api",
|
||||
@ -14,6 +16,9 @@ const cronJobApiInjectable = getInjectable({
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "cronJobApi is only available in certain environments");
|
||||
|
||||
return new CronJobApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
}, {
|
||||
checkPreferredVersion: true,
|
||||
});
|
||||
},
|
||||
|
||||
@ -7,13 +7,13 @@ import moment from "moment";
|
||||
import type { NamespaceScopedMetadata, ObjectReference } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { formatDuration } from "../../utils/formatDuration";
|
||||
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { JobTemplateSpec } from "./types/job-template-spec";
|
||||
|
||||
export class CronJobApi extends KubeApi<CronJob> {
|
||||
constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) {
|
||||
super({
|
||||
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions) {
|
||||
super(deps, {
|
||||
...opts,
|
||||
objectConstructor: CronJob,
|
||||
});
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { CustomResourceDefinitionApi } from "./custom-resource-definition.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
|
||||
const customResourceDefinitionApiInjectable = getInjectable({
|
||||
id: "custom-resource-definition-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "customResourceDefinitionApi is only available in certain environments");
|
||||
|
||||
return new CustomResourceDefinitionApi();
|
||||
return new CustomResourceDefinitionApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -8,7 +8,7 @@ import customResourcesRouteInjectable from "../../front-end-routing/routes/clust
|
||||
import { buildURL } from "../../utils/buildUrl";
|
||||
import type { BaseKubeObjectCondition, ClusterScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { DerivedKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { JSONSchemaProps } from "./types/json-schema-props";
|
||||
|
||||
@ -234,8 +234,8 @@ export class CustomResourceDefinition extends KubeObject<
|
||||
}
|
||||
|
||||
export class CustomResourceDefinitionApi extends KubeApi<CustomResourceDefinition> {
|
||||
constructor(opts: DerivedKubeApiOptions = {}) {
|
||||
super({
|
||||
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
|
||||
super(deps, {
|
||||
objectConstructor: CustomResourceDefinition,
|
||||
checkPreferredVersion: true,
|
||||
...opts,
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { DaemonSetApi } from "./daemon-set.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const daemonSetApiInjectable = getInjectable({
|
||||
id: "daemon-set-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "daemonSetApi is only available in certain environements");
|
||||
|
||||
return new DaemonSetApi();
|
||||
return new DaemonSetApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
import moment from "moment";
|
||||
|
||||
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeObjectStatus, LabelSelector, NamespaceScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
@ -83,9 +83,9 @@ export class DaemonSet extends KubeObject<
|
||||
}
|
||||
|
||||
export class DaemonSetApi extends KubeApi<DaemonSet> {
|
||||
constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) {
|
||||
super({
|
||||
...opts,
|
||||
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
|
||||
super(deps, {
|
||||
...opts ?? {},
|
||||
objectConstructor: DaemonSet,
|
||||
});
|
||||
}
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { DeploymentApi } from "./deployment.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const deploymentApiInjectable = getInjectable({
|
||||
id: "deployment-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "deploymentApi is only available in certain environments");
|
||||
|
||||
return new DeploymentApi();
|
||||
return new DeploymentApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
import moment from "moment";
|
||||
|
||||
import type { DerivedKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { PodSpec } from "./pod.api";
|
||||
import type { KubeObjectStatus, LabelSelector, NamespaceScopedMetadata } from "../kube-object";
|
||||
@ -13,10 +13,10 @@ import { KubeObject } from "../kube-object";
|
||||
import { hasTypedProperty, isNumber, isObject } from "../../utils";
|
||||
|
||||
export class DeploymentApi extends KubeApi<Deployment> {
|
||||
constructor(opts?: DerivedKubeApiOptions) {
|
||||
super({
|
||||
objectConstructor: Deployment,
|
||||
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
|
||||
super(deps, {
|
||||
...opts ?? {},
|
||||
objectConstructor: Deployment,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { EndpointsApi } from "./endpoint.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const endpointsApiInjectable = getInjectable({
|
||||
id: "endpoints-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "endpointsApi is only available in certain environments");
|
||||
|
||||
return new EndpointsApi();
|
||||
return new EndpointsApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
import { autoBind } from "../../utils";
|
||||
import type { KubeObjectMetadata, KubeObjectScope, NamespaceScopedMetadata, ObjectReference } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { DerivedKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
|
||||
@ -112,8 +112,8 @@ export class Endpoints extends KubeObject<
|
||||
}
|
||||
|
||||
export class EndpointsApi extends KubeApi<Endpoints, EndpointsData> {
|
||||
constructor(opts: DerivedKubeApiOptions = {}) {
|
||||
super({
|
||||
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
|
||||
super(deps, {
|
||||
objectConstructor: Endpoints,
|
||||
...opts,
|
||||
});
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { KubeEventApi } from "./events.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const kubeEventApiInjectable = getInjectable({
|
||||
id: "kube-event-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "kubeEventApi is only available in certain environments");
|
||||
|
||||
return new KubeEventApi();
|
||||
return new KubeEventApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -7,7 +7,7 @@ import moment from "moment";
|
||||
import type { KubeObjectMetadata, KubeObjectScope, ObjectReference } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { formatDuration } from "../../utils/formatDuration";
|
||||
import type { DerivedKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
|
||||
@ -132,8 +132,8 @@ export class KubeEvent extends KubeObject<KubeObjectMetadata<KubeObjectScope.Nam
|
||||
}
|
||||
|
||||
export class KubeEventApi extends KubeApi<KubeEvent, KubeEventData> {
|
||||
constructor(opts: DerivedKubeApiOptions = {}) {
|
||||
super({
|
||||
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
|
||||
super(deps, {
|
||||
objectConstructor: KubeEvent,
|
||||
...opts,
|
||||
});
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { HorizontalPodAutoscalerApi } from "./horizontal-pod-autoscaler.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const horizontalPodAutoscalerApiInjectable = getInjectable({
|
||||
id: "horizontal-pod-autoscaler-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "horizontalPodAutoscalerApi is only available in certain environments");
|
||||
|
||||
return new HorizontalPodAutoscalerApi();
|
||||
return new HorizontalPodAutoscalerApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
import type { BaseKubeObjectCondition, LabelSelector, NamespaceScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { DerivedKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { OptionVarient } from "../../utils";
|
||||
|
||||
@ -202,8 +202,8 @@ export class HorizontalPodAutoscaler extends KubeObject<
|
||||
}
|
||||
|
||||
export class HorizontalPodAutoscalerApi extends KubeApi<HorizontalPodAutoscaler> {
|
||||
constructor(opts?: DerivedKubeApiOptions) {
|
||||
super({
|
||||
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
|
||||
super(deps, {
|
||||
objectConstructor: HorizontalPodAutoscaler,
|
||||
...opts ?? {},
|
||||
});
|
||||
|
||||
@ -43,5 +43,4 @@ export * from "./service.api";
|
||||
export * from "./service-account.api";
|
||||
export * from "./stateful-set.api";
|
||||
export * from "./storage-class.api";
|
||||
export * from "./legacy-globals";
|
||||
export * from "./types";
|
||||
|
||||
@ -5,12 +5,15 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { IngressClassApi } from "./ingress-class.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const ingressClassApiInjectable = getInjectable({
|
||||
id: "ingress-class-api",
|
||||
instantiate: () => {
|
||||
return new IngressClassApi();
|
||||
},
|
||||
instantiate: (di) => new IngressClassApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
}),
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
});
|
||||
|
||||
@ -5,12 +5,12 @@
|
||||
|
||||
import type { KubeObjectMetadata, KubeObjectScope } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { ResourceDescriptor } from "../kube-api";
|
||||
import type { KubeApiDependencies, ResourceDescriptor } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
|
||||
export class IngressClassApi extends KubeApi<IngressClass> {
|
||||
constructor() {
|
||||
super({
|
||||
constructor(dependencies: KubeApiDependencies) {
|
||||
super(dependencies, {
|
||||
objectConstructor: IngressClass,
|
||||
checkPreferredVersion: true,
|
||||
fallbackApiBases: ["/apis/extensions/v1beta1/ingressclasses"],
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { IngressApi } from "./ingress.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const ingressApiInjectable = getInjectable({
|
||||
id: "ingress-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "ingressApi is only available in certain environments");
|
||||
|
||||
return new IngressApi();
|
||||
return new IngressApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -6,14 +6,14 @@
|
||||
import type { NamespaceScopedMetadata, TypedLocalObjectReference } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { hasTypedProperty, isString, iter } from "../../utils";
|
||||
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { RequireExactlyOne } from "type-fest";
|
||||
|
||||
export class IngressApi extends KubeApi<Ingress> {
|
||||
constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) {
|
||||
super({
|
||||
...opts,
|
||||
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
|
||||
super(deps, {
|
||||
...opts ?? {},
|
||||
objectConstructor: Ingress,
|
||||
// Add fallback for Kubernetes <1.19
|
||||
checkPreferredVersion: true,
|
||||
|
||||
@ -7,6 +7,8 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { JobApi } from "./job.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const jobApiInjectable = getInjectable({
|
||||
id: "job-api",
|
||||
@ -14,6 +16,9 @@ const jobApiInjectable = getInjectable({
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "jobApi is only available in certain environments");
|
||||
|
||||
return new JobApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
}, {
|
||||
checkPreferredVersion: true,
|
||||
});
|
||||
},
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { PodSpec } from "./pod.api";
|
||||
import type { Container } from "./types/container";
|
||||
@ -95,9 +95,9 @@ export class Job extends KubeObject<
|
||||
}
|
||||
|
||||
export class JobApi extends KubeApi<Job> {
|
||||
constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) {
|
||||
super({
|
||||
...opts,
|
||||
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
|
||||
super(deps, {
|
||||
...opts ?? {},
|
||||
objectConstructor: Job,
|
||||
});
|
||||
}
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { LeaseApi } from "./lease.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const leaseApiInjectable = getInjectable({
|
||||
id: "lease-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "leaseApi is only available in certain environments");
|
||||
|
||||
return new LeaseApi();
|
||||
return new LeaseApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { NamespaceScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
@ -47,9 +47,9 @@ export class Lease extends KubeObject<
|
||||
}
|
||||
|
||||
export class LeaseApi extends KubeApi<Lease> {
|
||||
constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) {
|
||||
super({
|
||||
...opts,
|
||||
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
|
||||
super(deps, {
|
||||
...opts ?? {},
|
||||
objectConstructor: Lease,
|
||||
});
|
||||
}
|
||||
|
||||
@ -1,78 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { asLegacyGlobalForExtensionApi } from "../../../extensions/as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
|
||||
import configMapApiInjectable from "./config-map.api.injectable";
|
||||
import cronJobApiInjectable from "./cron-job.api.injectable";
|
||||
import jobApiInjectable from "./job.api.injectable";
|
||||
import networkPolicyApiInjectable from "./network-policy.api.injectable";
|
||||
import nodeApiInjectable from "./node.api.injectable";
|
||||
import persistentVolumeClaimApiInjectable from "./persistent-volume-claim.api.injectable";
|
||||
import podApiInjectable from "./pod.api.injectable";
|
||||
import resourceQuotaApiInjectable from "./resource-quota.api.injectable";
|
||||
import roleApiInjectable from "./role.api.injectable";
|
||||
import secretApiInjectable from "./secret.api.injectable";
|
||||
import serviceApiInjectable from "./service.api.injectable";
|
||||
import storageClassApiInjectable from "./storage-class.api.injectable";
|
||||
|
||||
/**
|
||||
* @deprecated use `di.inject(roleApiInjectable)` instead
|
||||
*/
|
||||
export const roleApi = asLegacyGlobalForExtensionApi(roleApiInjectable);
|
||||
|
||||
/**
|
||||
* @deprecated use `di.inject(podApiInjectable)` instead
|
||||
*/
|
||||
export const podApi = asLegacyGlobalForExtensionApi(podApiInjectable);
|
||||
|
||||
/**
|
||||
* @deprecated use `di.inject(cronJobApiInjectable)` instead
|
||||
*/
|
||||
export const cronJobApi = asLegacyGlobalForExtensionApi(cronJobApiInjectable);
|
||||
|
||||
/**
|
||||
* @deprecated use `di.inject(jobApiInjectable)` instead
|
||||
*/
|
||||
export const jobApi = asLegacyGlobalForExtensionApi(jobApiInjectable);
|
||||
|
||||
/**
|
||||
* @deprecated use `di.inject(configMapApiInjectable)` instead
|
||||
*/
|
||||
export const configMapApi = asLegacyGlobalForExtensionApi(configMapApiInjectable);
|
||||
|
||||
/**
|
||||
* @deprecated use `di.inject(networkPolicyApiInjectable)` instead
|
||||
*/
|
||||
export const networkPolicyApi = asLegacyGlobalForExtensionApi(networkPolicyApiInjectable);
|
||||
|
||||
/**
|
||||
* @deprecated use `di.inject(nodeApiInjectable)` instead
|
||||
*/
|
||||
export const nodeApi = asLegacyGlobalForExtensionApi(nodeApiInjectable);
|
||||
|
||||
/**
|
||||
* @deprecated use `di.inject(persistentVolumeClaimApiInjectable)` instead
|
||||
*/
|
||||
export const persistentVolumeClaimApi = asLegacyGlobalForExtensionApi(persistentVolumeClaimApiInjectable);
|
||||
|
||||
/**
|
||||
* @deprecated use `di.inject(resourceQuotaApiInjectable)` instead
|
||||
*/
|
||||
export const resourceQuotaApi = asLegacyGlobalForExtensionApi(resourceQuotaApiInjectable);
|
||||
|
||||
/**
|
||||
* @deprecated use `di.inject(secretApiInjectable)` instead
|
||||
*/
|
||||
export const secretApi = asLegacyGlobalForExtensionApi(secretApiInjectable);
|
||||
|
||||
/**
|
||||
* @deprecated use `di.inject(serviceApiInjectable)` instead
|
||||
*/
|
||||
export const serviceApi = asLegacyGlobalForExtensionApi(serviceApiInjectable);
|
||||
|
||||
/**
|
||||
* @deprecated use `di.inject(storageClassApiInjectable)` instead
|
||||
*/
|
||||
export const storageClassApi = asLegacyGlobalForExtensionApi(storageClassApiInjectable);
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { LimitRangeApi } from "./limit-range.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const limitRangeApiInjectable = getInjectable({
|
||||
id: "limit-range-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "limitRangeApi is only available in certain environments");
|
||||
|
||||
return new LimitRangeApi();
|
||||
return new LimitRangeApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
import type { NamespaceScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { DerivedKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
|
||||
export enum LimitType {
|
||||
@ -62,8 +62,8 @@ export class LimitRange extends KubeObject<
|
||||
}
|
||||
|
||||
export class LimitRangeApi extends KubeApi<LimitRange> {
|
||||
constructor(opts?: DerivedKubeApiOptions) {
|
||||
super({
|
||||
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
|
||||
super(deps, {
|
||||
objectConstructor: LimitRange,
|
||||
...opts ?? {},
|
||||
});
|
||||
|
||||
@ -7,6 +7,8 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { NamespaceApi } from "./namespace.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const namespaceApiInjectable = getInjectable({
|
||||
id: "namespace-api",
|
||||
@ -14,7 +16,10 @@ const namespaceApiInjectable = getInjectable({
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "namespaceApi is only available in certain environments");
|
||||
|
||||
return new NamespaceApi();
|
||||
return new NamespaceApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { ClusterScopedMetadata, KubeObjectStatus } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
@ -36,9 +36,9 @@ export class Namespace extends KubeObject<
|
||||
}
|
||||
|
||||
export class NamespaceApi extends KubeApi<Namespace> {
|
||||
constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) {
|
||||
super({
|
||||
...opts,
|
||||
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
|
||||
super(deps, {
|
||||
...opts ?? {},
|
||||
objectConstructor: Namespace,
|
||||
});
|
||||
}
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { NetworkPolicyApi } from "./network-policy.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const networkPolicyApiInjectable = getInjectable({
|
||||
id: "network-policy-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "networkPolicyApi is only available in certain environments");
|
||||
|
||||
return new NetworkPolicyApi();
|
||||
return new NetworkPolicyApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
import type { LabelSelector, NamespaceScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { DerivedKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
|
||||
export interface IPolicyIpBlock {
|
||||
@ -124,8 +124,8 @@ export class NetworkPolicy extends KubeObject<
|
||||
}
|
||||
|
||||
export class NetworkPolicyApi extends KubeApi<NetworkPolicy> {
|
||||
constructor(opts: DerivedKubeApiOptions = {}) {
|
||||
super({
|
||||
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
|
||||
super(deps, {
|
||||
objectConstructor: NetworkPolicy,
|
||||
...opts,
|
||||
});
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { NodeApi } from "./node.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const nodeApiInjectable = getInjectable({
|
||||
id: "node-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "nodeApi is only available in certain environments");
|
||||
|
||||
return new NodeApi();
|
||||
return new NodeApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -6,14 +6,14 @@
|
||||
import type { BaseKubeObjectCondition, ClusterScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { cpuUnitsToNumber, unitsToBytes, isObject } from "../../../renderer/utils";
|
||||
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { TypedRegEx } from "typed-regex";
|
||||
|
||||
export class NodeApi extends KubeApi<Node> {
|
||||
constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) {
|
||||
super({
|
||||
...opts,
|
||||
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
|
||||
super(deps, {
|
||||
...opts ?? {},
|
||||
objectConstructor: Node,
|
||||
});
|
||||
}
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { PersistentVolumeClaimApi } from "./persistent-volume-claim.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const persistentVolumeClaimApiInjectable = getInjectable({
|
||||
id: "persistent-volume-claim-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "persistentVolumeClaimApi is only available in certain environments");
|
||||
|
||||
return new PersistentVolumeClaimApi();
|
||||
return new PersistentVolumeClaimApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -6,15 +6,15 @@
|
||||
import type { LabelSelector, NamespaceScopedMetadata, TypedLocalObjectReference } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { Pod } from "./pod.api";
|
||||
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import { object } from "../../utils";
|
||||
import type { ResourceRequirements } from "./types/resource-requirements";
|
||||
|
||||
export class PersistentVolumeClaimApi extends KubeApi<PersistentVolumeClaim> {
|
||||
constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) {
|
||||
super({
|
||||
...opts,
|
||||
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
|
||||
super(deps, {
|
||||
...opts ?? {},
|
||||
objectConstructor: PersistentVolumeClaim,
|
||||
});
|
||||
}
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { PersistentVolumeApi } from "./persistent-volume.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const persistentVolumeApiInjectable = getInjectable({
|
||||
id: "persistent-volume-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "persistentVolumeApi is only available in certain environments");
|
||||
|
||||
return new PersistentVolumeApi();
|
||||
return new PersistentVolumeApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
import type { ClusterScopedMetadata, LabelSelector, ObjectReference, TypedLocalObjectReference } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import { unitsToBytes } from "../../utils";
|
||||
import type { DerivedKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { ResourceRequirements } from "./types/resource-requirements";
|
||||
|
||||
@ -103,8 +103,8 @@ export class PersistentVolume extends KubeObject<
|
||||
}
|
||||
|
||||
export class PersistentVolumeApi extends KubeApi<PersistentVolume> {
|
||||
constructor(opts: DerivedKubeApiOptions = {}) {
|
||||
super({
|
||||
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
|
||||
super(deps, {
|
||||
...opts,
|
||||
objectConstructor: PersistentVolume,
|
||||
});
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { PodDisruptionBudgetApi } from "./pod-disruption-budget.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const podDisruptionBudgetApiInjectable = getInjectable({
|
||||
id: "pod-disruption-budget-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "podDisruptionBudgetApi is only available in certain environments");
|
||||
|
||||
return new PodDisruptionBudgetApi();
|
||||
return new PodDisruptionBudgetApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
import type { LabelSelector, NamespaceScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { DerivedKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
|
||||
export interface PodDisruptionBudgetSpec {
|
||||
@ -52,8 +52,8 @@ export class PodDisruptionBudget extends KubeObject<
|
||||
}
|
||||
|
||||
export class PodDisruptionBudgetApi extends KubeApi<PodDisruptionBudget> {
|
||||
constructor(opts: DerivedKubeApiOptions = {}) {
|
||||
super({
|
||||
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
|
||||
super(deps, {
|
||||
objectConstructor: PodDisruptionBudget,
|
||||
...opts,
|
||||
});
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { PodMetricsApi } from "./pod-metrics.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const podMetricsApiInjectable = getInjectable({
|
||||
id: "pod-metrics-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "podMetricsApi is only available in certain environments");
|
||||
|
||||
return new PodMetricsApi();
|
||||
return new PodMetricsApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
import type { KubeObjectMetadata, KubeObjectScope, NamespaceScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { DerivedKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
|
||||
@ -52,8 +52,8 @@ export class PodMetrics extends KubeObject<
|
||||
}
|
||||
|
||||
export class PodMetricsApi extends KubeApi<PodMetrics, PodMetricsData> {
|
||||
constructor(opts: DerivedKubeApiOptions = {}) {
|
||||
super({
|
||||
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
|
||||
super(deps, {
|
||||
...opts,
|
||||
objectConstructor: PodMetrics,
|
||||
});
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { PodSecurityPolicyApi } from "./pod-security-policy.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const podSecurityPolicyApiInjectable = getInjectable({
|
||||
id: "pod-security-policy-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "podSecurityPolicyApi is only available in certain environments");
|
||||
|
||||
return new PodSecurityPolicyApi();
|
||||
return new PodSecurityPolicyApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
import type { ClusterScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { DerivedKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
|
||||
export interface PodSecurityPolicySpec {
|
||||
@ -111,8 +111,8 @@ export class PodSecurityPolicy extends KubeObject<
|
||||
}
|
||||
|
||||
export class PodSecurityPolicyApi extends KubeApi<PodSecurityPolicy> {
|
||||
constructor(opts: DerivedKubeApiOptions = {}) {
|
||||
super({
|
||||
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
|
||||
super(deps, {
|
||||
...opts,
|
||||
objectConstructor: PodSecurityPolicy,
|
||||
|
||||
|
||||
@ -7,6 +7,8 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { PodApi } from "./pod.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const podApiInjectable = getInjectable({
|
||||
id: "pod-api",
|
||||
@ -14,7 +16,10 @@ const podApiInjectable = getInjectable({
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "podApi is only available in certain environments");
|
||||
|
||||
return new PodApi();
|
||||
return new PodApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions, ResourceDescriptor } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies, ResourceDescriptor } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { RequireExactlyOne } from "type-fest";
|
||||
import type { KubeObjectMetadata, LocalObjectReference, Affinity, Toleration, NamespaceScopedMetadata } from "../kube-object";
|
||||
@ -17,9 +17,9 @@ import type { Container } from "./types/container";
|
||||
import type { ObjectFieldSelector, ResourceFieldSelector } from "./types";
|
||||
|
||||
export class PodApi extends KubeApi<Pod> {
|
||||
constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) {
|
||||
super({
|
||||
...opts,
|
||||
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
|
||||
super(deps, {
|
||||
...opts ?? {},
|
||||
objectConstructor: Pod,
|
||||
});
|
||||
}
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { PriorityClassApi } from "./priority-class.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const priorityClassApiInjectable = getInjectable({
|
||||
id: "priority-class-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "PriorityClassApi is only available in certain environments");
|
||||
|
||||
return new PriorityClassApi();
|
||||
return new PriorityClassApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { DerivedKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import type { ClusterScopedMetadata, KubeObjectMetadata, KubeObjectScope } from "../kube-object";
|
||||
@ -57,8 +57,8 @@ export class PriorityClass extends KubeObject<
|
||||
}
|
||||
|
||||
export class PriorityClassApi extends KubeApi<PriorityClass, PriorityClassData> {
|
||||
constructor(opts: DerivedKubeApiOptions = {}) {
|
||||
super({
|
||||
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
|
||||
super(deps, {
|
||||
objectConstructor: PriorityClass,
|
||||
...opts,
|
||||
});
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { ReplicaSetApi } from "./replica-set.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const replicaSetApiInjectable = getInjectable({
|
||||
id: "replica-set-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "replicaSetApi is only available in certain environments");
|
||||
|
||||
return new ReplicaSetApi();
|
||||
return new ReplicaSetApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -3,16 +3,16 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeObjectStatus, LabelSelector, NamespaceScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { PodTemplateSpec } from "./types/pod-template-spec";
|
||||
|
||||
export class ReplicaSetApi extends KubeApi<ReplicaSet> {
|
||||
constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) {
|
||||
super({
|
||||
...opts,
|
||||
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
|
||||
super(deps, {
|
||||
...opts ?? {},
|
||||
objectConstructor: ReplicaSet,
|
||||
});
|
||||
}
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { ResourceQuotaApi } from "./resource-quota.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const resourceQuotaApiInjectable = getInjectable({
|
||||
id: "resource-quota-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "resourceQuotaApi is only available in certain environments");
|
||||
|
||||
return new ResourceQuotaApi();
|
||||
return new ResourceQuotaApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
import type { NamespaceScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { DerivedKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
|
||||
export type IResourceQuotaValues = Partial<Record<string, string>> & {
|
||||
@ -65,8 +65,8 @@ export class ResourceQuota extends KubeObject<
|
||||
}
|
||||
|
||||
export class ResourceQuotaApi extends KubeApi<ResourceQuota> {
|
||||
constructor(opts: DerivedKubeApiOptions = {}) {
|
||||
super({
|
||||
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
|
||||
super(deps, {
|
||||
objectConstructor: ResourceQuota,
|
||||
...opts,
|
||||
});
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { RoleBindingApi } from "./role-binding.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const roleBindingApiInjectable = getInjectable({
|
||||
id: "role-binding-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "roleBindingApi is only available in certain environments");
|
||||
|
||||
return new RoleBindingApi();
|
||||
return new RoleBindingApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
import type { KubeObjectMetadata, KubeObjectScope, NamespaceScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { DerivedKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import type { RoleRef } from "./types/role-ref";
|
||||
@ -44,8 +44,8 @@ export class RoleBinding extends KubeObject<
|
||||
}
|
||||
|
||||
export class RoleBindingApi extends KubeApi<RoleBinding, RoleBindingData> {
|
||||
constructor(opts: DerivedKubeApiOptions = {}) {
|
||||
super({
|
||||
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
|
||||
super(deps, {
|
||||
...opts,
|
||||
objectConstructor: RoleBinding,
|
||||
});
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { RoleApi } from "./role.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const roleApiInjectable = getInjectable({
|
||||
id: "role-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "roleApi is only available in certain environments");
|
||||
|
||||
return new RoleApi();
|
||||
return new RoleApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
import type { KubeObjectMetadata, KubeObjectScope, NamespaceScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { DerivedKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import type { PolicyRule } from "./types/policy-rule";
|
||||
@ -35,8 +35,8 @@ export class Role extends KubeObject<
|
||||
}
|
||||
|
||||
export class RoleApi extends KubeApi<Role, RoleData> {
|
||||
constructor(opts: DerivedKubeApiOptions = {}) {
|
||||
super({
|
||||
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
|
||||
super(deps, {
|
||||
...opts,
|
||||
objectConstructor: Role,
|
||||
});
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { RuntimeClassApi } from "./runtime-class.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const runtimeClassApiInjectable = getInjectable({
|
||||
id: "runtime-class-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "RuntimeClassApi is only available in certain environments");
|
||||
|
||||
return new RuntimeClassApi();
|
||||
return new RuntimeClassApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { DerivedKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import type { ClusterScopedMetadata, KubeObjectMetadata, KubeObjectScope, Toleration } from "../kube-object";
|
||||
@ -63,8 +63,8 @@ export class RuntimeClass extends KubeObject<
|
||||
}
|
||||
|
||||
export class RuntimeClassApi extends KubeApi<RuntimeClass, RuntimeClassData> {
|
||||
constructor(opts: DerivedKubeApiOptions = {}) {
|
||||
super({
|
||||
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
|
||||
super(deps, {
|
||||
objectConstructor: RuntimeClass,
|
||||
...opts,
|
||||
});
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { SecretApi } from "./secret.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const secretApiInjectable = getInjectable({
|
||||
id: "secret-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "secretApi is only available in certain environments");
|
||||
|
||||
return new SecretApi();
|
||||
return new SecretApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -7,7 +7,7 @@ import type { KubeObjectMetadata, KubeObjectScope, NamespaceScopedMetadata } fro
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
import { autoBind } from "../../utils";
|
||||
import type { DerivedKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
|
||||
export enum SecretType {
|
||||
@ -72,8 +72,8 @@ export class Secret extends KubeObject<
|
||||
}
|
||||
|
||||
export class SecretApi extends KubeApi<Secret, SecretData> {
|
||||
constructor(options: DerivedKubeApiOptions = {}) {
|
||||
super({
|
||||
constructor(deps: KubeApiDependencies, options: DerivedKubeApiOptions = {}) {
|
||||
super(deps, {
|
||||
...options,
|
||||
objectConstructor: Secret,
|
||||
});
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { SelfSubjectRulesReviewApi } from "./self-subject-rules-reviews.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const selfSubjectRulesReviewApiInjectable = getInjectable({
|
||||
id: "self-subject-rules-review-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "selfSubjectRulesReviewApi is only available in certain environments");
|
||||
|
||||
return new SelfSubjectRulesReviewApi();
|
||||
return new SelfSubjectRulesReviewApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -4,13 +4,13 @@
|
||||
*/
|
||||
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
|
||||
export class SelfSubjectRulesReviewApi extends KubeApi<SelfSubjectRulesReview> {
|
||||
constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) {
|
||||
super({
|
||||
...opts,
|
||||
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
|
||||
super(deps, {
|
||||
...opts ?? {},
|
||||
objectConstructor: SelfSubjectRulesReview,
|
||||
});
|
||||
}
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { ServiceAccountApi } from "./service-account.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const serviceAccountApiInjectable = getInjectable({
|
||||
id: "service-account-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "serviceAccountApi is only available in certain environments");
|
||||
|
||||
return new ServiceAccountApi();
|
||||
return new ServiceAccountApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
import type { KubeObjectMetadata, KubeObjectScope, LocalObjectReference, NamespaceScopedMetadata, ObjectReference } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { DerivedKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
|
||||
@ -50,8 +50,8 @@ export class ServiceAccount extends KubeObject<
|
||||
}
|
||||
|
||||
export class ServiceAccountApi extends KubeApi<ServiceAccount, ServiceAccountData> {
|
||||
constructor(opts: DerivedKubeApiOptions = {}) {
|
||||
super({
|
||||
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
|
||||
super(deps, {
|
||||
...opts,
|
||||
objectConstructor: ServiceAccount,
|
||||
});
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { ServiceApi } from "./service.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const serviceApiInjectable = getInjectable({
|
||||
id: "service-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "serviceApi is only available in certain environments");
|
||||
|
||||
return new ServiceApi();
|
||||
return new ServiceApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
import type { NamespaceScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { DerivedKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
|
||||
export interface ServicePort {
|
||||
@ -129,8 +129,8 @@ export class Service extends KubeObject<
|
||||
}
|
||||
|
||||
export class ServiceApi extends KubeApi<Service> {
|
||||
constructor(opts: DerivedKubeApiOptions = {}) {
|
||||
super({
|
||||
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
|
||||
super(deps, {
|
||||
...opts,
|
||||
objectConstructor: Service,
|
||||
});
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { StatefulSetApi } from "./stateful-set.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const statefulSetApiInjectable = getInjectable({
|
||||
id: "stateful-set-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "statefulSetApi is only available in certain environments");
|
||||
|
||||
return new StatefulSetApi();
|
||||
return new StatefulSetApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
import moment from "moment";
|
||||
|
||||
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { LabelSelector, NamespaceScopedMetadata } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
@ -13,9 +13,9 @@ import type { PodTemplateSpec } from "./types/pod-template-spec";
|
||||
import type { PersistentVolumeClaimTemplateSpec } from "./types/persistent-volume-claim-template-spec";
|
||||
|
||||
export class StatefulSetApi extends KubeApi<StatefulSet> {
|
||||
constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) {
|
||||
super({
|
||||
...opts,
|
||||
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
|
||||
super(deps, {
|
||||
...opts ?? {},
|
||||
objectConstructor: StatefulSet,
|
||||
});
|
||||
}
|
||||
|
||||
@ -7,13 +7,18 @@ import assert from "assert";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../stores-apis-can-be-created.token";
|
||||
import { StorageClassApi } from "./storage-class.api";
|
||||
import { kubeApiInjectionToken } from "../kube-api/kube-api-injection-token";
|
||||
import loggerInjectable from "../../logger.injectable";
|
||||
import maybeKubeApiInjectable from "../maybe-kube-api.injectable";
|
||||
|
||||
const storageClassApiInjectable = getInjectable({
|
||||
id: "storage-class-api",
|
||||
instantiate: (di) => {
|
||||
assert(di.inject(storesAndApisCanBeCreatedInjectionToken), "storageClassApi is only available in certain environments");
|
||||
|
||||
return new StorageClassApi();
|
||||
return new StorageClassApi({
|
||||
logger: di.inject(loggerInjectable),
|
||||
maybeKubeApi: di.inject(maybeKubeApiInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
injectionToken: kubeApiInjectionToken,
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
import { autoBind } from "../../utils";
|
||||
import type { ClusterScopedMetadata, KubeObjectMetadata, KubeObjectScope } from "../kube-object";
|
||||
import { KubeObject } from "../kube-object";
|
||||
import type { DerivedKubeApiOptions } from "../kube-api";
|
||||
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
|
||||
import { KubeApi } from "../kube-api";
|
||||
import type { KubeJsonApiData } from "../kube-json-api";
|
||||
|
||||
@ -86,8 +86,8 @@ export class StorageClass extends KubeObject<
|
||||
}
|
||||
|
||||
export class StorageClassApi extends KubeApi<StorageClass, StorageClassData> {
|
||||
constructor(opts: DerivedKubeApiOptions = {}) {
|
||||
super({
|
||||
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
|
||||
super(deps, {
|
||||
...opts,
|
||||
objectConstructor: StorageClass,
|
||||
});
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user