From 1be1b4418f6d3e3170123562d2004a2c9cd14e36 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Wed, 4 Jan 2023 11:20:14 -0500 Subject: [PATCH] Make KubeApi consume its dependencies while not breaking the extension API Signed-off-by: Sebastian Malton --- .../k8s-api/__tests__/api-manager.test.ts | 4 + .../kube-api-version-detection.test.ts | 27 +- src/common/k8s-api/__tests__/kube-api.test.ts | 55 ++- .../create-kube-api-for-cluster.injectable.ts | 54 ++- ...-kube-api-for-remote-cluster.injectable.ts | 35 +- .../k8s-api/create-kube-api.injectable.ts | 26 ++ .../cluster-role-binding.api.injectable.ts | 7 +- .../endpoints/cluster-role-binding.api.ts | 6 +- .../endpoints/cluster-role.api.injectable.ts | 7 +- .../k8s-api/endpoints/cluster-role.api.ts | 6 +- .../endpoints/cluster.api.injectable.ts | 7 +- src/common/k8s-api/endpoints/cluster.api.ts | 8 +- .../component-status.api.injectable.ts | 7 +- .../k8s-api/endpoints/component-status.api.ts | 6 +- .../endpoints/config-map.api.injectable.ts | 7 +- .../k8s-api/endpoints/config-map.api.ts | 6 +- .../endpoints/cron-job.api.injectable.ts | 5 + src/common/k8s-api/endpoints/cron-job.api.ts | 6 +- ...stom-resource-definition.api.injectable.ts | 7 +- .../custom-resource-definition.api.ts | 6 +- .../endpoints/daemon-set.api.injectable.ts | 7 +- .../k8s-api/endpoints/daemon-set.api.ts | 8 +- .../endpoints/deployment.api.injectable.ts | 7 +- .../k8s-api/endpoints/deployment.api.ts | 8 +- .../endpoints/endpoint.api.injectable.ts | 7 +- src/common/k8s-api/endpoints/endpoint.api.ts | 6 +- .../endpoints/events.api.injectable.ts | 7 +- src/common/k8s-api/endpoints/events.api.ts | 6 +- ...orizontal-pod-autoscaler.api.injectable.ts | 7 +- .../horizontal-pod-autoscaler.api.ts | 6 +- .../endpoints/ingress.api.injectable.ts | 7 +- src/common/k8s-api/endpoints/ingress.api.ts | 8 +- .../k8s-api/endpoints/job.api.injectable.ts | 5 + src/common/k8s-api/endpoints/job.api.ts | 8 +- .../k8s-api/endpoints/lease.api.injectable.ts | 7 +- src/common/k8s-api/endpoints/lease.api.ts | 8 +- .../endpoints/limit-range.api.injectable.ts | 7 +- .../k8s-api/endpoints/limit-range.api.ts | 6 +- .../endpoints/namespace.api.injectable.ts | 7 +- src/common/k8s-api/endpoints/namespace.api.ts | 8 +- .../network-policy.api.injectable.ts | 7 +- .../k8s-api/endpoints/network-policy.api.ts | 6 +- .../k8s-api/endpoints/node.api.injectable.ts | 7 +- src/common/k8s-api/endpoints/node.api.ts | 8 +- .../persistent-volume-claim.api.injectable.ts | 7 +- .../endpoints/persistent-volume-claim.api.ts | 8 +- .../persistent-volume.api.injectable.ts | 7 +- .../endpoints/persistent-volume.api.ts | 6 +- .../pod-disruption-budget.api.injectable.ts | 7 +- .../endpoints/pod-disruption-budget.api.ts | 6 +- .../endpoints/pod-metrics.api.injectable.ts | 7 +- .../k8s-api/endpoints/pod-metrics.api.ts | 6 +- .../pod-security-policy.api.injectable.ts | 7 +- .../endpoints/pod-security-policy.api.ts | 6 +- .../k8s-api/endpoints/pod.api.injectable.ts | 7 +- src/common/k8s-api/endpoints/pod.api.ts | 8 +- .../priority-class.api.injectable.ts | 7 +- .../k8s-api/endpoints/priority-class.api.ts | 6 +- .../endpoints/replica-set.api.injectable.ts | 7 +- .../k8s-api/endpoints/replica-set.api.ts | 8 +- .../resource-quota.api.injectable.ts | 7 +- .../k8s-api/endpoints/resource-quota.api.ts | 6 +- .../endpoints/role-binding.api.injectable.ts | 7 +- .../k8s-api/endpoints/role-binding.api.ts | 6 +- .../k8s-api/endpoints/role.api.injectable.ts | 7 +- src/common/k8s-api/endpoints/role.api.ts | 6 +- .../endpoints/runtime-class.api.injectable.ts | 7 +- .../k8s-api/endpoints/runtime-class.api.ts | 6 +- .../endpoints/secret.api.injectable.ts | 7 +- src/common/k8s-api/endpoints/secret.api.ts | 6 +- ...lf-subject-rules-reviews.api.injectable.ts | 7 +- .../self-subject-rules-reviews.api.ts | 8 +- .../service-account.api.injectable.ts | 7 +- .../k8s-api/endpoints/service-account.api.ts | 6 +- .../endpoints/service.api.injectable.ts | 7 +- src/common/k8s-api/endpoints/service.api.ts | 6 +- .../endpoints/stateful-set.api.injectable.ts | 7 +- .../k8s-api/endpoints/stateful-set.api.ts | 8 +- .../endpoints/storage-class.api.injectable.ts | 7 +- .../k8s-api/endpoints/storage-class.api.ts | 6 +- src/common/k8s-api/kube-api.ts | 39 +- .../k8s-api/maybe-kube-api.injectable.ts | 19 + src/common/test-utils/use-fake-time.ts | 2 +- .../utils/reactive-now/reactive-now.test.tsx | 4 +- src/extensions/common-api/k8s-api.ts | 88 ++++- .../application-menu/application-menu.test.ts | 4 +- ...g-of-orphan-application-menu-items.test.ts | 4 +- .../analytics-for-installing-update.test.ts | 4 +- ...alling-update-using-topbar-button.test.tsx | 4 +- ...g-time-since-update-was-downloaded.test.ts | 4 +- .../periodical-checking-of-updates.test.ts | 4 +- .../installing-update.test.ts | 4 +- .../show-status-for-a-kube-object.test.tsx | 4 +- ...debar-and-tab-navigation-for-core.test.tsx | 4 +- ...and-tab-navigation-for-extensions.test.tsx | 4 +- ...tom-helm-repository-in-preferences.test.ts | 4 +- ...tab-for-installing-helm-chart.test.ts.snap | 342 ++++++++++++++++++ .../upgrade-chart-new-tab.test.ts | 4 +- .../showing-details-for-helm-release.test.ts | 4 +- ...ing-the-app-using-application-menu.test.ts | 4 +- .../node-shell-session/node-shell-session.ts | 7 +- .../setup-auto-registration.injectable.ts | 12 +- .../components/countdown/countdown.test.tsx | 4 +- .../__tests__/render-delay.test.tsx | 4 +- .../test-utils/get-application-builder.tsx | 3 + .../cluster-frame/cluster-frame.test.tsx | 4 +- 106 files changed, 972 insertions(+), 316 deletions(-) create mode 100644 src/common/k8s-api/create-kube-api.injectable.ts create mode 100644 src/common/k8s-api/maybe-kube-api.injectable.ts diff --git a/src/common/k8s-api/__tests__/api-manager.test.ts b/src/common/k8s-api/__tests__/api-manager.test.ts index 92f9334363..b83f52c3f0 100644 --- a/src/common/k8s-api/__tests__/api-manager.test.ts +++ b/src/common/k8s-api/__tests__/api-manager.test.ts @@ -17,6 +17,7 @@ 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 { protected async checkPreferredVersion() { @@ -57,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", diff --git a/src/common/k8s-api/__tests__/kube-api-version-detection.test.ts b/src/common/k8s-api/__tests__/kube-api-version-detection.test.ts index e2caef39fa..94c6e0cd9c 100644 --- a/src/common/k8s-api/__tests__/kube-api-version-detection.test.ts +++ b/src/common/k8s-api/__tests__/kube-api-version-detection.test.ts @@ -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; let fetchMock: AsyncFnMock; 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; 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", diff --git a/src/common/k8s-api/__tests__/kube-api.test.ts b/src/common/k8s-api/__tests__/kube-api.test.ts index a4f9fd5b21..99129ebf6c 100644 --- a/src/common/k8s-api/__tests__/kube-api.test.ts +++ b/src/common/k8s-api/__tests__/kube-api.test.ts @@ -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,18 @@ describe("createKubeApiForRemoteCluster", () => { }); describe("KubeApi", () => { - let request: KubeJsonApi; let fetchMock: AsyncFnMock; + 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); const createCluster = di.inject(createClusterInjectable); + const createKubeJsonApi = di.inject(createKubeJsonApiInjectable); di.override(hostedClusterInjectable, () => createCluster({ contextName: "some-context-name", @@ -154,12 +165,10 @@ describe("KubeApi", () => { 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", () => { diff --git a/src/common/k8s-api/create-kube-api-for-cluster.injectable.ts b/src/common/k8s-api/create-kube-api-for-cluster.injectable.ts index a90a52456d..dc3a3fef69 100644 --- a/src/common/k8s-api/create-kube-api-for-cluster.injectable.ts +++ b/src/common/k8s-api/create-kube-api-for-cluster.injectable.ts @@ -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 { , Data extends KubeJsonApiDataFor>( cluster: CreateKubeApiForLocalClusterConfig, kubeClass: KubeObjectConstructor, - apiClass: new (apiOpts: KubeApiOptions) => Api + apiClass: KubeApiConstructor, ): Api; >( cluster: CreateKubeApiForLocalClusterConfig, kubeClass: KubeObjectConstructor, - apiClass?: new (apiOpts: KubeApiOptions) => KubeApi + apiClass?: KubeApiConstructor>, ): KubeApi; } @@ -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>, - 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>, + ) => { + 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, + }, + ); + }; }, }); diff --git a/src/common/k8s-api/create-kube-api-for-remote-cluster.injectable.ts b/src/common/k8s-api/create-kube-api-for-remote-cluster.injectable.ts index d11b7ae34b..8b39387d1d 100644 --- a/src/common/k8s-api/create-kube-api-for-remote-cluster.injectable.ts +++ b/src/common/k8s-api/create-kube-api-for-remote-cluster.injectable.ts @@ -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> = new (apiOpts: KubeApiOptions) => Api; + export interface CreateKubeApiForRemoteCluster { , Data extends KubeJsonApiDataFor>( config: CreateKubeApiForRemoteClusterConfig, kubeClass: KubeObjectConstructor, - apiClass: new (apiOpts: KubeApiOptions) => Api, + apiClass: KubeApiConstructor, ): Api; >( config: CreateKubeApiForRemoteClusterConfig, kubeClass: KubeObjectConstructor, - apiClass?: new (apiOpts: KubeApiOptions) => KubeApi, + apiClass?: KubeApiConstructor>, ): KubeApi; } @@ -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>, apiClass = KubeApi) => { + return ( + config: CreateKubeApiForRemoteClusterConfig, + kubeClass: KubeObjectConstructor>, + apiClass?: KubeApiConstructor>, + ) => { 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, + }, + ); }; }, }); diff --git a/src/common/k8s-api/create-kube-api.injectable.ts b/src/common/k8s-api/create-kube-api.injectable.ts new file mode 100644 index 0000000000..cce470b132 --- /dev/null +++ b/src/common/k8s-api/create-kube-api.injectable.ts @@ -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 { + (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; diff --git a/src/common/k8s-api/endpoints/cluster-role-binding.api.injectable.ts b/src/common/k8s-api/endpoints/cluster-role-binding.api.injectable.ts index 38ba76d661..4965a86edc 100644 --- a/src/common/k8s-api/endpoints/cluster-role-binding.api.injectable.ts +++ b/src/common/k8s-api/endpoints/cluster-role-binding.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/cluster-role-binding.api.ts b/src/common/k8s-api/endpoints/cluster-role-binding.api.ts index d9bc61af49..827a3ce95d 100644 --- a/src/common/k8s-api/endpoints/cluster-role-binding.api.ts +++ b/src/common/k8s-api/endpoints/cluster-role-binding.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions = {}) { - super({ + constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) { + super(deps, { ...opts, objectConstructor: ClusterRoleBinding, }); diff --git a/src/common/k8s-api/endpoints/cluster-role.api.injectable.ts b/src/common/k8s-api/endpoints/cluster-role.api.injectable.ts index 9b56bc2559..b22e198d1e 100644 --- a/src/common/k8s-api/endpoints/cluster-role.api.injectable.ts +++ b/src/common/k8s-api/endpoints/cluster-role.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/cluster-role.api.ts b/src/common/k8s-api/endpoints/cluster-role.api.ts index f99168b395..e55f934df9 100644 --- a/src/common/k8s-api/endpoints/cluster-role.api.ts +++ b/src/common/k8s-api/endpoints/cluster-role.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions = {}) { - super({ + constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) { + super(deps, { ...opts, objectConstructor: ClusterRole, }); diff --git a/src/common/k8s-api/endpoints/cluster.api.injectable.ts b/src/common/k8s-api/endpoints/cluster.api.injectable.ts index 8d51e630ee..494ef9d94b 100644 --- a/src/common/k8s-api/endpoints/cluster.api.injectable.ts +++ b/src/common/k8s-api/endpoints/cluster.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/cluster.api.ts b/src/common/k8s-api/endpoints/cluster.api.ts index aae4c239ad..92f42f1e4e 100644 --- a/src/common/k8s-api/endpoints/cluster.api.ts +++ b/src/common/k8s-api/endpoints/cluster.api.ts @@ -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 { @@ -18,9 +18,9 @@ export class ClusterApi extends KubeApi { */ static namespaced = true; - constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) { - super({ - ...opts, + constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) { + super(deps, { + ...opts ?? {}, objectConstructor: Cluster, }); } diff --git a/src/common/k8s-api/endpoints/component-status.api.injectable.ts b/src/common/k8s-api/endpoints/component-status.api.injectable.ts index 395c825401..01bb16e6b4 100644 --- a/src/common/k8s-api/endpoints/component-status.api.injectable.ts +++ b/src/common/k8s-api/endpoints/component-status.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/component-status.api.ts b/src/common/k8s-api/endpoints/component-status.api.ts index 5335207b71..a35fc92c44 100644 --- a/src/common/k8s-api/endpoints/component-status.api.ts +++ b/src/common/k8s-api/endpoints/component-status.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions = {}) { - super({ + constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) { + super(deps, { ...opts, objectConstructor: ComponentStatus, }); diff --git a/src/common/k8s-api/endpoints/config-map.api.injectable.ts b/src/common/k8s-api/endpoints/config-map.api.injectable.ts index d643849f70..e41cc23111 100644 --- a/src/common/k8s-api/endpoints/config-map.api.injectable.ts +++ b/src/common/k8s-api/endpoints/config-map.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/config-map.api.ts b/src/common/k8s-api/endpoints/config-map.api.ts index 922274d32a..a2860246b1 100644 --- a/src/common/k8s-api/endpoints/config-map.api.ts +++ b/src/common/k8s-api/endpoints/config-map.api.ts @@ -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 { - constructor(opts?: DerivedKubeApiOptions) { - super({ + constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) { + super(deps, { objectConstructor: ConfigMap, ...opts ?? {}, }); diff --git a/src/common/k8s-api/endpoints/cron-job.api.injectable.ts b/src/common/k8s-api/endpoints/cron-job.api.injectable.ts index e2230ee2db..2831a726aa 100644 --- a/src/common/k8s-api/endpoints/cron-job.api.injectable.ts +++ b/src/common/k8s-api/endpoints/cron-job.api.injectable.ts @@ -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, }); }, diff --git a/src/common/k8s-api/endpoints/cron-job.api.ts b/src/common/k8s-api/endpoints/cron-job.api.ts index 7dad6a857d..2ccb8c910c 100644 --- a/src/common/k8s-api/endpoints/cron-job.api.ts +++ b/src/common/k8s-api/endpoints/cron-job.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) { - super({ + constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions) { + super(deps, { ...opts, objectConstructor: CronJob, }); diff --git a/src/common/k8s-api/endpoints/custom-resource-definition.api.injectable.ts b/src/common/k8s-api/endpoints/custom-resource-definition.api.injectable.ts index c441b07c3e..cf8a6560a0 100644 --- a/src/common/k8s-api/endpoints/custom-resource-definition.api.injectable.ts +++ b/src/common/k8s-api/endpoints/custom-resource-definition.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/custom-resource-definition.api.ts b/src/common/k8s-api/endpoints/custom-resource-definition.api.ts index 9235e2c992..b438f06b3a 100644 --- a/src/common/k8s-api/endpoints/custom-resource-definition.api.ts +++ b/src/common/k8s-api/endpoints/custom-resource-definition.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions = {}) { - super({ + constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) { + super(deps, { objectConstructor: CustomResourceDefinition, checkPreferredVersion: true, ...opts, diff --git a/src/common/k8s-api/endpoints/daemon-set.api.injectable.ts b/src/common/k8s-api/endpoints/daemon-set.api.injectable.ts index a1e1d65084..8a904519b6 100644 --- a/src/common/k8s-api/endpoints/daemon-set.api.injectable.ts +++ b/src/common/k8s-api/endpoints/daemon-set.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/daemon-set.api.ts b/src/common/k8s-api/endpoints/daemon-set.api.ts index 00f9cfb2d9..6661e2ff43 100644 --- a/src/common/k8s-api/endpoints/daemon-set.api.ts +++ b/src/common/k8s-api/endpoints/daemon-set.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) { - super({ - ...opts, + constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) { + super(deps, { + ...opts ?? {}, objectConstructor: DaemonSet, }); } diff --git a/src/common/k8s-api/endpoints/deployment.api.injectable.ts b/src/common/k8s-api/endpoints/deployment.api.injectable.ts index 26c98c39e6..47236b1a6f 100644 --- a/src/common/k8s-api/endpoints/deployment.api.injectable.ts +++ b/src/common/k8s-api/endpoints/deployment.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/deployment.api.ts b/src/common/k8s-api/endpoints/deployment.api.ts index 318ea8563f..31bc55ae76 100644 --- a/src/common/k8s-api/endpoints/deployment.api.ts +++ b/src/common/k8s-api/endpoints/deployment.api.ts @@ -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 { - constructor(opts?: DerivedKubeApiOptions) { - super({ - objectConstructor: Deployment, + constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) { + super(deps, { ...opts ?? {}, + objectConstructor: Deployment, }); } diff --git a/src/common/k8s-api/endpoints/endpoint.api.injectable.ts b/src/common/k8s-api/endpoints/endpoint.api.injectable.ts index 79a57cd3e7..6288dc2448 100644 --- a/src/common/k8s-api/endpoints/endpoint.api.injectable.ts +++ b/src/common/k8s-api/endpoints/endpoint.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/endpoint.api.ts b/src/common/k8s-api/endpoints/endpoint.api.ts index dd61bc2211..c60377a887 100644 --- a/src/common/k8s-api/endpoints/endpoint.api.ts +++ b/src/common/k8s-api/endpoints/endpoint.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions = {}) { - super({ + constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) { + super(deps, { objectConstructor: Endpoints, ...opts, }); diff --git a/src/common/k8s-api/endpoints/events.api.injectable.ts b/src/common/k8s-api/endpoints/events.api.injectable.ts index 83f0697d31..a64afb877e 100644 --- a/src/common/k8s-api/endpoints/events.api.injectable.ts +++ b/src/common/k8s-api/endpoints/events.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/events.api.ts b/src/common/k8s-api/endpoints/events.api.ts index 3a03c0ffbf..aca77712c8 100644 --- a/src/common/k8s-api/endpoints/events.api.ts +++ b/src/common/k8s-api/endpoints/events.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions = {}) { - super({ + constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) { + super(deps, { objectConstructor: KubeEvent, ...opts, }); diff --git a/src/common/k8s-api/endpoints/horizontal-pod-autoscaler.api.injectable.ts b/src/common/k8s-api/endpoints/horizontal-pod-autoscaler.api.injectable.ts index 7449053661..d891e45e0f 100644 --- a/src/common/k8s-api/endpoints/horizontal-pod-autoscaler.api.injectable.ts +++ b/src/common/k8s-api/endpoints/horizontal-pod-autoscaler.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/horizontal-pod-autoscaler.api.ts b/src/common/k8s-api/endpoints/horizontal-pod-autoscaler.api.ts index 70857fd881..71863d65ad 100644 --- a/src/common/k8s-api/endpoints/horizontal-pod-autoscaler.api.ts +++ b/src/common/k8s-api/endpoints/horizontal-pod-autoscaler.api.ts @@ -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 { - constructor(opts?: DerivedKubeApiOptions) { - super({ + constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) { + super(deps, { objectConstructor: HorizontalPodAutoscaler, ...opts ?? {}, }); diff --git a/src/common/k8s-api/endpoints/ingress.api.injectable.ts b/src/common/k8s-api/endpoints/ingress.api.injectable.ts index 350f8824e4..ec25b199b0 100644 --- a/src/common/k8s-api/endpoints/ingress.api.injectable.ts +++ b/src/common/k8s-api/endpoints/ingress.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/ingress.api.ts b/src/common/k8s-api/endpoints/ingress.api.ts index d223530013..d35cd77c0b 100644 --- a/src/common/k8s-api/endpoints/ingress.api.ts +++ b/src/common/k8s-api/endpoints/ingress.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) { - super({ - ...opts, + constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) { + super(deps, { + ...opts ?? {}, objectConstructor: Ingress, // Add fallback for Kubernetes <1.19 checkPreferredVersion: true, diff --git a/src/common/k8s-api/endpoints/job.api.injectable.ts b/src/common/k8s-api/endpoints/job.api.injectable.ts index fc25c8c61f..923b96a2eb 100644 --- a/src/common/k8s-api/endpoints/job.api.injectable.ts +++ b/src/common/k8s-api/endpoints/job.api.injectable.ts @@ -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, }); }, diff --git a/src/common/k8s-api/endpoints/job.api.ts b/src/common/k8s-api/endpoints/job.api.ts index 66f4ef3768..ef47419e80 100644 --- a/src/common/k8s-api/endpoints/job.api.ts +++ b/src/common/k8s-api/endpoints/job.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) { - super({ - ...opts, + constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) { + super(deps, { + ...opts ?? {}, objectConstructor: Job, }); } diff --git a/src/common/k8s-api/endpoints/lease.api.injectable.ts b/src/common/k8s-api/endpoints/lease.api.injectable.ts index 41bd5e3935..f5d8e73b55 100644 --- a/src/common/k8s-api/endpoints/lease.api.injectable.ts +++ b/src/common/k8s-api/endpoints/lease.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/lease.api.ts b/src/common/k8s-api/endpoints/lease.api.ts index 22cfb778e4..25f636dcfb 100644 --- a/src/common/k8s-api/endpoints/lease.api.ts +++ b/src/common/k8s-api/endpoints/lease.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) { - super({ - ...opts, + constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) { + super(deps, { + ...opts ?? {}, objectConstructor: Lease, }); } diff --git a/src/common/k8s-api/endpoints/limit-range.api.injectable.ts b/src/common/k8s-api/endpoints/limit-range.api.injectable.ts index c2898c998a..7f50e2df92 100644 --- a/src/common/k8s-api/endpoints/limit-range.api.injectable.ts +++ b/src/common/k8s-api/endpoints/limit-range.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/limit-range.api.ts b/src/common/k8s-api/endpoints/limit-range.api.ts index 5ed0974edc..eec533993c 100644 --- a/src/common/k8s-api/endpoints/limit-range.api.ts +++ b/src/common/k8s-api/endpoints/limit-range.api.ts @@ -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 { - constructor(opts?: DerivedKubeApiOptions) { - super({ + constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) { + super(deps, { objectConstructor: LimitRange, ...opts ?? {}, }); diff --git a/src/common/k8s-api/endpoints/namespace.api.injectable.ts b/src/common/k8s-api/endpoints/namespace.api.injectable.ts index c55c6b9521..fe722433c1 100644 --- a/src/common/k8s-api/endpoints/namespace.api.injectable.ts +++ b/src/common/k8s-api/endpoints/namespace.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/namespace.api.ts b/src/common/k8s-api/endpoints/namespace.api.ts index 774d91cf61..3de24d3df9 100644 --- a/src/common/k8s-api/endpoints/namespace.api.ts +++ b/src/common/k8s-api/endpoints/namespace.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) { - super({ - ...opts, + constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) { + super(deps, { + ...opts ?? {}, objectConstructor: Namespace, }); } diff --git a/src/common/k8s-api/endpoints/network-policy.api.injectable.ts b/src/common/k8s-api/endpoints/network-policy.api.injectable.ts index 58a316605a..66c6a95732 100644 --- a/src/common/k8s-api/endpoints/network-policy.api.injectable.ts +++ b/src/common/k8s-api/endpoints/network-policy.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/network-policy.api.ts b/src/common/k8s-api/endpoints/network-policy.api.ts index 518874f7aa..78520d5539 100644 --- a/src/common/k8s-api/endpoints/network-policy.api.ts +++ b/src/common/k8s-api/endpoints/network-policy.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions = {}) { - super({ + constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) { + super(deps, { objectConstructor: NetworkPolicy, ...opts, }); diff --git a/src/common/k8s-api/endpoints/node.api.injectable.ts b/src/common/k8s-api/endpoints/node.api.injectable.ts index 4a0faf3270..b780d69ee7 100644 --- a/src/common/k8s-api/endpoints/node.api.injectable.ts +++ b/src/common/k8s-api/endpoints/node.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/node.api.ts b/src/common/k8s-api/endpoints/node.api.ts index e1d726bed1..158f359a57 100644 --- a/src/common/k8s-api/endpoints/node.api.ts +++ b/src/common/k8s-api/endpoints/node.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) { - super({ - ...opts, + constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) { + super(deps, { + ...opts ?? {}, objectConstructor: Node, }); } diff --git a/src/common/k8s-api/endpoints/persistent-volume-claim.api.injectable.ts b/src/common/k8s-api/endpoints/persistent-volume-claim.api.injectable.ts index e765cf0c38..5d21ba9587 100644 --- a/src/common/k8s-api/endpoints/persistent-volume-claim.api.injectable.ts +++ b/src/common/k8s-api/endpoints/persistent-volume-claim.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/persistent-volume-claim.api.ts b/src/common/k8s-api/endpoints/persistent-volume-claim.api.ts index 4c3c575699..947d9139a3 100644 --- a/src/common/k8s-api/endpoints/persistent-volume-claim.api.ts +++ b/src/common/k8s-api/endpoints/persistent-volume-claim.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) { - super({ - ...opts, + constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) { + super(deps, { + ...opts ?? {}, objectConstructor: PersistentVolumeClaim, }); } diff --git a/src/common/k8s-api/endpoints/persistent-volume.api.injectable.ts b/src/common/k8s-api/endpoints/persistent-volume.api.injectable.ts index 38ad80845c..cde587942c 100644 --- a/src/common/k8s-api/endpoints/persistent-volume.api.injectable.ts +++ b/src/common/k8s-api/endpoints/persistent-volume.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/persistent-volume.api.ts b/src/common/k8s-api/endpoints/persistent-volume.api.ts index db230e9da3..f4d80a82eb 100644 --- a/src/common/k8s-api/endpoints/persistent-volume.api.ts +++ b/src/common/k8s-api/endpoints/persistent-volume.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions = {}) { - super({ + constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) { + super(deps, { ...opts, objectConstructor: PersistentVolume, }); diff --git a/src/common/k8s-api/endpoints/pod-disruption-budget.api.injectable.ts b/src/common/k8s-api/endpoints/pod-disruption-budget.api.injectable.ts index c2e793433b..28ecff01b1 100644 --- a/src/common/k8s-api/endpoints/pod-disruption-budget.api.injectable.ts +++ b/src/common/k8s-api/endpoints/pod-disruption-budget.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/pod-disruption-budget.api.ts b/src/common/k8s-api/endpoints/pod-disruption-budget.api.ts index 169efc9b70..0010bbb642 100644 --- a/src/common/k8s-api/endpoints/pod-disruption-budget.api.ts +++ b/src/common/k8s-api/endpoints/pod-disruption-budget.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions = {}) { - super({ + constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) { + super(deps, { objectConstructor: PodDisruptionBudget, ...opts, }); diff --git a/src/common/k8s-api/endpoints/pod-metrics.api.injectable.ts b/src/common/k8s-api/endpoints/pod-metrics.api.injectable.ts index ecdbfa920d..ddd2b109ef 100644 --- a/src/common/k8s-api/endpoints/pod-metrics.api.injectable.ts +++ b/src/common/k8s-api/endpoints/pod-metrics.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/pod-metrics.api.ts b/src/common/k8s-api/endpoints/pod-metrics.api.ts index 6db15dd6b7..84a58026d5 100644 --- a/src/common/k8s-api/endpoints/pod-metrics.api.ts +++ b/src/common/k8s-api/endpoints/pod-metrics.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions = {}) { - super({ + constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) { + super(deps, { ...opts, objectConstructor: PodMetrics, }); diff --git a/src/common/k8s-api/endpoints/pod-security-policy.api.injectable.ts b/src/common/k8s-api/endpoints/pod-security-policy.api.injectable.ts index 44e25a54b1..c62b568e87 100644 --- a/src/common/k8s-api/endpoints/pod-security-policy.api.injectable.ts +++ b/src/common/k8s-api/endpoints/pod-security-policy.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/pod-security-policy.api.ts b/src/common/k8s-api/endpoints/pod-security-policy.api.ts index 9655fb70a1..f0e9e1110c 100644 --- a/src/common/k8s-api/endpoints/pod-security-policy.api.ts +++ b/src/common/k8s-api/endpoints/pod-security-policy.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions = {}) { - super({ + constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) { + super(deps, { ...opts, objectConstructor: PodSecurityPolicy, diff --git a/src/common/k8s-api/endpoints/pod.api.injectable.ts b/src/common/k8s-api/endpoints/pod.api.injectable.ts index f88a396bab..f2c1635b14 100644 --- a/src/common/k8s-api/endpoints/pod.api.injectable.ts +++ b/src/common/k8s-api/endpoints/pod.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/pod.api.ts b/src/common/k8s-api/endpoints/pod.api.ts index 862a28da94..3a0bed57cd 100644 --- a/src/common/k8s-api/endpoints/pod.api.ts +++ b/src/common/k8s-api/endpoints/pod.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) { - super({ - ...opts, + constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) { + super(deps, { + ...opts ?? {}, objectConstructor: Pod, }); } diff --git a/src/common/k8s-api/endpoints/priority-class.api.injectable.ts b/src/common/k8s-api/endpoints/priority-class.api.injectable.ts index 8aae454967..e21a85a290 100644 --- a/src/common/k8s-api/endpoints/priority-class.api.injectable.ts +++ b/src/common/k8s-api/endpoints/priority-class.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/priority-class.api.ts b/src/common/k8s-api/endpoints/priority-class.api.ts index 516ae07ef4..1d181b6038 100644 --- a/src/common/k8s-api/endpoints/priority-class.api.ts +++ b/src/common/k8s-api/endpoints/priority-class.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions = {}) { - super({ + constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) { + super(deps, { objectConstructor: PriorityClass, ...opts, }); diff --git a/src/common/k8s-api/endpoints/replica-set.api.injectable.ts b/src/common/k8s-api/endpoints/replica-set.api.injectable.ts index 2bda99b703..c6c75d8192 100644 --- a/src/common/k8s-api/endpoints/replica-set.api.injectable.ts +++ b/src/common/k8s-api/endpoints/replica-set.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/replica-set.api.ts b/src/common/k8s-api/endpoints/replica-set.api.ts index 401ba6cf05..1fee553b8d 100644 --- a/src/common/k8s-api/endpoints/replica-set.api.ts +++ b/src/common/k8s-api/endpoints/replica-set.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) { - super({ - ...opts, + constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) { + super(deps, { + ...opts ?? {}, objectConstructor: ReplicaSet, }); } diff --git a/src/common/k8s-api/endpoints/resource-quota.api.injectable.ts b/src/common/k8s-api/endpoints/resource-quota.api.injectable.ts index b10865fe47..a82fa3abd9 100644 --- a/src/common/k8s-api/endpoints/resource-quota.api.injectable.ts +++ b/src/common/k8s-api/endpoints/resource-quota.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/resource-quota.api.ts b/src/common/k8s-api/endpoints/resource-quota.api.ts index b0ad18fed9..9316f9d932 100644 --- a/src/common/k8s-api/endpoints/resource-quota.api.ts +++ b/src/common/k8s-api/endpoints/resource-quota.api.ts @@ -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> & { @@ -65,8 +65,8 @@ export class ResourceQuota extends KubeObject< } export class ResourceQuotaApi extends KubeApi { - constructor(opts: DerivedKubeApiOptions = {}) { - super({ + constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) { + super(deps, { objectConstructor: ResourceQuota, ...opts, }); diff --git a/src/common/k8s-api/endpoints/role-binding.api.injectable.ts b/src/common/k8s-api/endpoints/role-binding.api.injectable.ts index 7b802f78ce..489b20401a 100644 --- a/src/common/k8s-api/endpoints/role-binding.api.injectable.ts +++ b/src/common/k8s-api/endpoints/role-binding.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/role-binding.api.ts b/src/common/k8s-api/endpoints/role-binding.api.ts index 20620fcf39..3923efee89 100644 --- a/src/common/k8s-api/endpoints/role-binding.api.ts +++ b/src/common/k8s-api/endpoints/role-binding.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions = {}) { - super({ + constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) { + super(deps, { ...opts, objectConstructor: RoleBinding, }); diff --git a/src/common/k8s-api/endpoints/role.api.injectable.ts b/src/common/k8s-api/endpoints/role.api.injectable.ts index d2b09f8bf7..d91d6a1fb8 100644 --- a/src/common/k8s-api/endpoints/role.api.injectable.ts +++ b/src/common/k8s-api/endpoints/role.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/role.api.ts b/src/common/k8s-api/endpoints/role.api.ts index 23bee908ba..d6bd0e79d3 100644 --- a/src/common/k8s-api/endpoints/role.api.ts +++ b/src/common/k8s-api/endpoints/role.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions = {}) { - super({ + constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) { + super(deps, { ...opts, objectConstructor: Role, }); diff --git a/src/common/k8s-api/endpoints/runtime-class.api.injectable.ts b/src/common/k8s-api/endpoints/runtime-class.api.injectable.ts index 1b13d13270..3fbeab9a09 100644 --- a/src/common/k8s-api/endpoints/runtime-class.api.injectable.ts +++ b/src/common/k8s-api/endpoints/runtime-class.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/runtime-class.api.ts b/src/common/k8s-api/endpoints/runtime-class.api.ts index fa1867ea07..16e3cefab5 100644 --- a/src/common/k8s-api/endpoints/runtime-class.api.ts +++ b/src/common/k8s-api/endpoints/runtime-class.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions = {}) { - super({ + constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) { + super(deps, { objectConstructor: RuntimeClass, ...opts, }); diff --git a/src/common/k8s-api/endpoints/secret.api.injectable.ts b/src/common/k8s-api/endpoints/secret.api.injectable.ts index 916fbe1e93..c4173987da 100644 --- a/src/common/k8s-api/endpoints/secret.api.injectable.ts +++ b/src/common/k8s-api/endpoints/secret.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/secret.api.ts b/src/common/k8s-api/endpoints/secret.api.ts index ff6b0ff845..a5a3b5eb1c 100644 --- a/src/common/k8s-api/endpoints/secret.api.ts +++ b/src/common/k8s-api/endpoints/secret.api.ts @@ -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 { - constructor(options: DerivedKubeApiOptions = {}) { - super({ + constructor(deps: KubeApiDependencies, options: DerivedKubeApiOptions = {}) { + super(deps, { ...options, objectConstructor: Secret, }); diff --git a/src/common/k8s-api/endpoints/self-subject-rules-reviews.api.injectable.ts b/src/common/k8s-api/endpoints/self-subject-rules-reviews.api.injectable.ts index b66a2b4fc9..8034b9d47f 100644 --- a/src/common/k8s-api/endpoints/self-subject-rules-reviews.api.injectable.ts +++ b/src/common/k8s-api/endpoints/self-subject-rules-reviews.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/self-subject-rules-reviews.api.ts b/src/common/k8s-api/endpoints/self-subject-rules-reviews.api.ts index 61714d9ca3..2c73d89e77 100644 --- a/src/common/k8s-api/endpoints/self-subject-rules-reviews.api.ts +++ b/src/common/k8s-api/endpoints/self-subject-rules-reviews.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) { - super({ - ...opts, + constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) { + super(deps, { + ...opts ?? {}, objectConstructor: SelfSubjectRulesReview, }); } diff --git a/src/common/k8s-api/endpoints/service-account.api.injectable.ts b/src/common/k8s-api/endpoints/service-account.api.injectable.ts index da202d6ccd..70a477ac54 100644 --- a/src/common/k8s-api/endpoints/service-account.api.injectable.ts +++ b/src/common/k8s-api/endpoints/service-account.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/service-account.api.ts b/src/common/k8s-api/endpoints/service-account.api.ts index 01bc31dc64..e92ea667d9 100644 --- a/src/common/k8s-api/endpoints/service-account.api.ts +++ b/src/common/k8s-api/endpoints/service-account.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions = {}) { - super({ + constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) { + super(deps, { ...opts, objectConstructor: ServiceAccount, }); diff --git a/src/common/k8s-api/endpoints/service.api.injectable.ts b/src/common/k8s-api/endpoints/service.api.injectable.ts index 31885238de..78a0f744de 100644 --- a/src/common/k8s-api/endpoints/service.api.injectable.ts +++ b/src/common/k8s-api/endpoints/service.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/service.api.ts b/src/common/k8s-api/endpoints/service.api.ts index 302ad3556d..f574bea53d 100644 --- a/src/common/k8s-api/endpoints/service.api.ts +++ b/src/common/k8s-api/endpoints/service.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions = {}) { - super({ + constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) { + super(deps, { ...opts, objectConstructor: Service, }); diff --git a/src/common/k8s-api/endpoints/stateful-set.api.injectable.ts b/src/common/k8s-api/endpoints/stateful-set.api.injectable.ts index fa206cf957..1dd58fde3c 100644 --- a/src/common/k8s-api/endpoints/stateful-set.api.injectable.ts +++ b/src/common/k8s-api/endpoints/stateful-set.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/stateful-set.api.ts b/src/common/k8s-api/endpoints/stateful-set.api.ts index 8d8e9553b3..e91a856262 100644 --- a/src/common/k8s-api/endpoints/stateful-set.api.ts +++ b/src/common/k8s-api/endpoints/stateful-set.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) { - super({ - ...opts, + constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) { + super(deps, { + ...opts ?? {}, objectConstructor: StatefulSet, }); } diff --git a/src/common/k8s-api/endpoints/storage-class.api.injectable.ts b/src/common/k8s-api/endpoints/storage-class.api.injectable.ts index 7f1abab299..e65247aa8d 100644 --- a/src/common/k8s-api/endpoints/storage-class.api.injectable.ts +++ b/src/common/k8s-api/endpoints/storage-class.api.injectable.ts @@ -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, diff --git a/src/common/k8s-api/endpoints/storage-class.api.ts b/src/common/k8s-api/endpoints/storage-class.api.ts index ff3b233ce5..bf121e47db 100644 --- a/src/common/k8s-api/endpoints/storage-class.api.ts +++ b/src/common/k8s-api/endpoints/storage-class.api.ts @@ -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 { - constructor(opts: DerivedKubeApiOptions = {}) { - super({ + constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) { + super(deps, { ...opts, objectConstructor: StorageClass, }); diff --git a/src/common/k8s-api/kube-api.ts b/src/common/k8s-api/kube-api.ts index 9be55b6622..c2a8906400 100644 --- a/src/common/k8s-api/kube-api.ts +++ b/src/common/k8s-api/kube-api.ts @@ -20,11 +20,9 @@ import type { Patch } from "rfc6902"; import assert from "assert"; import type { PartialDeep } from "type-fest"; import type { Logger } from "../logger"; -import { Environments, getEnvironmentSpecificLegacyGlobalDiForExtensionApi, getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api"; +import { Environments, getEnvironmentSpecificLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api"; import autoRegistrationEmitterInjectable from "./api-manager/auto-registration-emitter.injectable"; -import { apiKubeInjectionToken } from "./api-kube"; import type AbortController from "abort-controller"; -import loggerInjectable from "../logger.injectable"; import { matches } from "lodash/fp"; /** @@ -80,28 +78,6 @@ export interface DerivedKubeApiOptions { request?: KubeJsonApi; } -/** - * @deprecated This type is only present for backwards compatable typescript support - */ -export interface IgnoredKubeApiOptions { - /** - * @deprecated this option is overridden and should not be used - */ - objectConstructor?: any; - /** - * @deprecated this option is overridden and should not be used - */ - kind?: any; - /** - * @deprecated this option is overridden and should not be used - */ - isNamespaces?: any; - /** - * @deprecated this option is overridden and should not be used - */ - apiBase?: any; -} - export interface KubeApiQueryParams { watch?: boolean | number; resourceVersion?: string; @@ -256,6 +232,7 @@ function legacyRegisterApi(api: KubeApi): void { export interface KubeApiDependencies { readonly logger: Logger; + readonly maybeKubeApi: KubeJsonApi | undefined; } export class KubeApi< @@ -280,12 +257,10 @@ export class KubeApi< protected readonly fullApiPathname: string; protected readonly fallbackApiBases: string[] | undefined; - protected readonly dependencies: KubeApiDependencies; - - constructor(opts: KubeApiOptions) { + constructor(protected readonly dependencies: KubeApiDependencies, opts: KubeApiOptions) { const { objectConstructor, - request = getLegacyGlobalDiForExtensionApi().inject(apiKubeInjectionToken), + request = this.dependencies.maybeKubeApi, kind = objectConstructor.kind, isNamespaced, apiBase: fullApiPathname = objectConstructor.apiBase, @@ -314,12 +289,6 @@ export class KubeApi< this.request = request; this.objectConstructor = objectConstructor; legacyRegisterApi(this); - - const di = getLegacyGlobalDiForExtensionApi(); - - this.dependencies = { - logger: di.inject(loggerInjectable), - }; } get apiVersionWithGroup() { diff --git a/src/common/k8s-api/maybe-kube-api.injectable.ts b/src/common/k8s-api/maybe-kube-api.injectable.ts new file mode 100644 index 0000000000..6717c00881 --- /dev/null +++ b/src/common/k8s-api/maybe-kube-api.injectable.ts @@ -0,0 +1,19 @@ +/** + * 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 { apiKubeInjectionToken } from "./api-kube"; + +const maybeKubeApiInjectable = getInjectable({ + id: "maybe-kube-api", + instantiate: (di) => { + try { + return di.inject(apiKubeInjectionToken); + } catch { + return undefined; + } + }, +}); + +export default maybeKubeApiInjectable; diff --git a/src/common/test-utils/use-fake-time.ts b/src/common/test-utils/use-fake-time.ts index 2a0956cebb..e455984861 100644 --- a/src/common/test-utils/use-fake-time.ts +++ b/src/common/test-utils/use-fake-time.ts @@ -16,7 +16,7 @@ export const advanceFakeTime = (milliseconds: number) => { }); }; -export const useFakeTime = (dateTime = "2015-10-21T07:28:00Z") => { +export const testUsingFakeTime = (dateTime = "2015-10-21T07:28:00Z") => { usingFakeTime = true; jest.useFakeTimers(); diff --git a/src/common/utils/reactive-now/reactive-now.test.tsx b/src/common/utils/reactive-now/reactive-now.test.tsx index d2deb951b7..ab9b185438 100644 --- a/src/common/utils/reactive-now/reactive-now.test.tsx +++ b/src/common/utils/reactive-now/reactive-now.test.tsx @@ -8,14 +8,14 @@ import type { IComputedValue } from "mobx"; import { computed, observe } from "mobx"; import React from "react"; import { observer } from "mobx-react"; -import { advanceFakeTime, useFakeTime } from "../../test-utils/use-fake-time"; +import { advanceFakeTime, testUsingFakeTime } from "../../test-utils/use-fake-time"; import { reactiveNow } from "./reactive-now"; describe("reactiveNow", () => { let someComputed: IComputedValue; beforeEach(() => { - useFakeTime("2015-10-21T07:28:00Z"); + testUsingFakeTime("2015-10-21T07:28:00Z"); someComputed = computed(() => { const currentTimestamp = reactiveNow(); diff --git a/src/extensions/common-api/k8s-api.ts b/src/extensions/common-api/k8s-api.ts index 5ff09b3d7f..3856429717 100644 --- a/src/extensions/common-api/k8s-api.ts +++ b/src/extensions/common-api/k8s-api.ts @@ -18,17 +18,40 @@ import type { KubernetesCluster } from "./catalog"; import type { KubeApiDataFrom, KubeObjectStoreOptions } from "../../common/k8s-api/kube-object.store"; import { KubeObjectStore as InternalKubeObjectStore } from "../../common/k8s-api/kube-object.store"; import type { KubeJsonApiDataFor, KubeObject } from "../../common/k8s-api/kube-object"; -import type { KubeApi } from "../../common/k8s-api/kube-api"; +import type { DerivedKubeApiOptions, KubeApiDependencies, KubeApiOptions } from "../../common/k8s-api/kube-api"; +import { KubeApi as InternalKubeApi } from "../../common/k8s-api/kube-api"; import clusterFrameContextForNamespacedResourcesInjectable from "../../renderer/cluster-frame-context/for-namespaced-resources.injectable"; import type { ClusterContext } from "../../renderer/cluster-frame-context/cluster-frame-context"; import loggerInjectable from "../../common/logger.injectable"; import { getLegacyGlobalDiForExtensionApi } from "../as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api"; +import maybeKubeApiInjectable from "../../common/k8s-api/maybe-kube-api.injectable"; +import { DeploymentApi as InternalDeploymentApi, IngressApi as InternalIngressApi, NodeApi, PersistentVolumeClaimApi, PodApi } from "../../common/k8s-api/endpoints"; export const apiManager = asLegacyGlobalForExtensionApi(apiManagerInjectable); export const forCluster = asLegacyGlobalFunctionForExtensionApi(createKubeApiForClusterInjectable); export const forRemoteCluster = asLegacyGlobalFunctionForExtensionApi(createKubeApiForRemoteClusterInjectable); -export { KubeApi } from "../../common/k8s-api/kube-api"; +const getKubeApiDeps = (): KubeApiDependencies => { + const di = getLegacyGlobalDiForExtensionApi(); + + return { + logger: di.inject(loggerInjectable), + maybeKubeApi: di.inject(maybeKubeApiInjectable), + }; +}; + +// NOTE: this is done to preserve `instanceOf` behaviour +function KubeApiCstr< + Object extends KubeObject = KubeObject, + Data extends KubeJsonApiDataFor = KubeJsonApiDataFor, +>(opts: KubeApiOptions) { + return new InternalKubeApi(getKubeApiDeps(), opts); +} + +export const KubeApi = KubeApiCstr as unknown as new< + Object extends KubeObject = KubeObject, + Data extends KubeJsonApiDataFor = KubeJsonApiDataFor, +>(opts: KubeApiOptions) => InternalKubeApi; export const createResourceStack = asLegacyGlobalFunctionForExtensionApi(createResourceStackInjectable); @@ -82,7 +105,7 @@ export { export abstract class KubeObjectStore< K extends KubeObject = KubeObject, - A extends KubeApi = KubeApi>, + A extends InternalKubeApi = InternalKubeApi>, D extends KubeJsonApiDataFor = KubeApiDataFrom, > extends InternalKubeObjectStore { /** @@ -127,15 +150,65 @@ export { type KubeObjectStoreSubscribeParams, } from "../../common/k8s-api/kube-object.store"; +/** + * @deprecated This type is only present for backwards compatable typescript support + */ +export interface IgnoredKubeApiOptions { + /** + * @deprecated this option is overridden and should not be used + */ + objectConstructor?: any; + /** + * @deprecated this option is overridden and should not be used + */ + kind?: any; + /** + * @deprecated this option is overridden and should not be used + */ + isNamespaces?: any; + /** + * @deprecated this option is overridden and should not be used + */ + apiBase?: any; +} + +// NOTE: these *Constructor functions MUST be `function` to work with `new X()` +function PodsApiConstructor(opts?: DerivedKubeApiOptions & IgnoredKubeApiOptions) { + return new PodApi(getKubeApiDeps(), opts ?? {}); +} + +export const PodsApi = PodsApiConstructor as unknown as new (opts?: DerivedKubeApiOptions & IgnoredKubeApiOptions) => PodApi; + +function NodesApiConstructor(opts?: DerivedKubeApiOptions & IgnoredKubeApiOptions) { + return new NodeApi(getKubeApiDeps(), opts ?? {}); +} + +export const NodesApi = NodesApiConstructor as unknown as new (opts?: DerivedKubeApiOptions & IgnoredKubeApiOptions) => NodeApi; + +function DeploymentApiConstructor(opts?: DerivedKubeApiOptions) { + return new InternalDeploymentApi(getKubeApiDeps(), opts ?? {}); +} + +export const DeploymentApi = DeploymentApiConstructor as unknown as new (opts?: DerivedKubeApiOptions) => InternalDeploymentApi; + +function IngressApiConstructor(opts?: DerivedKubeApiOptions & IgnoredKubeApiOptions) { + return new InternalIngressApi(getKubeApiDeps(), opts ?? {}); +} + +export const IngressApi = IngressApiConstructor as unknown as new (opts?: DerivedKubeApiOptions & IgnoredKubeApiOptions) => InternalIngressApi; + +function PersistentVolumeClaimsApiConstructor(opts?: DerivedKubeApiOptions & IgnoredKubeApiOptions) { + return new PersistentVolumeClaimApi(getKubeApiDeps(), opts ?? {}); +} + +export const PersistentVolumeClaimsApi = PersistentVolumeClaimsApiConstructor as unknown as new (opts?: DerivedKubeApiOptions & IgnoredKubeApiOptions) => PersistentVolumeClaimApi; + export { type Container as IPodContainer, type PodContainerStatus as IPodContainerStatus, Pod, - PodApi as PodsApi, Node, - NodeApi as NodesApi, Deployment, - DeploymentApi, DaemonSet, StatefulSet, Job, @@ -151,11 +224,10 @@ export { PriorityClass, Service, Endpoints as Endpoint, - Ingress, IngressApi, + Ingress, NetworkPolicy, PersistentVolume, PersistentVolumeClaim, - PersistentVolumeClaimApi as PersistentVolumeClaimsApi, StorageClass, Namespace, KubeEvent, diff --git a/src/features/application-menu/application-menu.test.ts b/src/features/application-menu/application-menu.test.ts index e0128b83fb..0db35db744 100644 --- a/src/features/application-menu/application-menu.test.ts +++ b/src/features/application-menu/application-menu.test.ts @@ -5,7 +5,7 @@ import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import populateApplicationMenuInjectable from "./main/populate-application-menu.injectable"; -import { advanceFakeTime, useFakeTime } from "../../common/test-utils/use-fake-time"; +import { advanceFakeTime, testUsingFakeTime } from "../../common/test-utils/use-fake-time"; import { getCompositePaths } from "../../common/utils/composite/get-composite-paths/get-composite-paths"; import platformInjectable, { allPlatforms } from "../../common/vars/platform.injectable"; @@ -14,7 +14,7 @@ describe.each(allPlatforms)("application-menu, given platform is '%s'", (platfor let populateApplicationMenuMock: jest.Mock; beforeEach(async () => { - useFakeTime(); + testUsingFakeTime(); populateApplicationMenuMock = jest.fn(); diff --git a/src/features/application-menu/handling-of-orphan-application-menu-items.test.ts b/src/features/application-menu/handling-of-orphan-application-menu-items.test.ts index 7cae6d0079..7f35861a45 100644 --- a/src/features/application-menu/handling-of-orphan-application-menu-items.test.ts +++ b/src/features/application-menu/handling-of-orphan-application-menu-items.test.ts @@ -5,7 +5,7 @@ import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder"; import populateApplicationMenuInjectable from "./main/populate-application-menu.injectable"; -import { advanceFakeTime, useFakeTime } from "../../common/test-utils/use-fake-time"; +import { advanceFakeTime, testUsingFakeTime } from "../../common/test-utils/use-fake-time"; import { getCompositePaths } from "../../common/utils/composite/get-composite-paths/get-composite-paths"; import { getInjectable } from "@ogre-tools/injectable"; import applicationMenuItemInjectionToken from "./main/menu-items/application-menu-item-injection-token"; @@ -18,7 +18,7 @@ describe("handling-of-orphan-application-menu-items, given orphan menu item", () let logErrorMock: jest.Mock; beforeEach(async () => { - useFakeTime(); + testUsingFakeTime(); populateApplicationMenuMock = jest.fn(); logErrorMock = jest.fn(); diff --git a/src/features/application-update/analytics-for-installing-update.test.ts b/src/features/application-update/analytics-for-installing-update.test.ts index 2a7b8d19fd..ce77d37229 100644 --- a/src/features/application-update/analytics-for-installing-update.test.ts +++ b/src/features/application-update/analytics-for-installing-update.test.ts @@ -17,7 +17,7 @@ import type { DownloadPlatformUpdate } from "./main/download-update/download-pla import downloadPlatformUpdateInjectable from "./main/download-update/download-platform-update/download-platform-update.injectable"; import quitAndInstallUpdateInjectable from "./main/quit-and-install-update.injectable"; import periodicalCheckForUpdatesInjectable from "./child-features/periodical-checking-of-updates/main/periodical-check-for-updates.injectable"; -import { advanceFakeTime, useFakeTime } from "../../common/test-utils/use-fake-time"; +import { advanceFakeTime, testUsingFakeTime } from "../../common/test-utils/use-fake-time"; import emitEventInjectable from "../../common/app-event-bus/emit-event.injectable"; import getBuildVersionInjectable from "../../main/vars/build-version/get-build-version.injectable"; @@ -29,7 +29,7 @@ describe("analytics for installing update", () => { let mainDi: DiContainer; beforeEach(async () => { - useFakeTime("2015-10-21T07:28:00Z"); + testUsingFakeTime("2015-10-21T07:28:00Z"); builder = getApplicationBuilder(); diff --git a/src/features/application-update/child-features/application-update-using-top-bar/installing-update-using-topbar-button.test.tsx b/src/features/application-update/child-features/application-update-using-top-bar/installing-update-using-topbar-button.test.tsx index 88f59a720c..adede427d2 100644 --- a/src/features/application-update/child-features/application-update-using-top-bar/installing-update-using-topbar-button.test.tsx +++ b/src/features/application-update/child-features/application-update-using-top-bar/installing-update-using-topbar-button.test.tsx @@ -16,7 +16,7 @@ import type { ApplicationBuilder } from "../../../../renderer/components/test-ut import { getApplicationBuilder } from "../../../../renderer/components/test-utils/get-application-builder"; import processCheckingForUpdatesInjectable from "../../main/process-checking-for-updates.injectable"; import quitAndInstallUpdateInjectable from "../../main/quit-and-install-update.injectable"; -import { advanceFakeTime, useFakeTime } from "../../../../common/test-utils/use-fake-time"; +import { advanceFakeTime, testUsingFakeTime } from "../../../../common/test-utils/use-fake-time"; function daysToMilliseconds(days: number) { return Math.round(days * 24 * 60 * 60 * 1000); @@ -29,7 +29,7 @@ describe("encourage user to update when sufficient time passed since update was let quitAndInstallUpdateMock: jest.MockedFunction<() => void>; beforeEach(() => { - useFakeTime("2015-10-21T07:28:00Z"); + testUsingFakeTime("2015-10-21T07:28:00Z"); applicationBuilder = getApplicationBuilder(); diff --git a/src/features/application-update/child-features/force-user-to-update-when-too-long-time-since-update-was-downloaded/force-user-to-update-when-too-long-time-since-update-was-downloaded.test.ts b/src/features/application-update/child-features/force-user-to-update-when-too-long-time-since-update-was-downloaded/force-user-to-update-when-too-long-time-since-update-was-downloaded.test.ts index b5a333d24e..39ac24570a 100644 --- a/src/features/application-update/child-features/force-user-to-update-when-too-long-time-since-update-was-downloaded/force-user-to-update-when-too-long-time-since-update-was-downloaded.test.ts +++ b/src/features/application-update/child-features/force-user-to-update-when-too-long-time-since-update-was-downloaded/force-user-to-update-when-too-long-time-since-update-was-downloaded.test.ts @@ -14,7 +14,7 @@ import type { DiContainer } from "@ogre-tools/injectable"; import processCheckingForUpdatesInjectable from "../../main/process-checking-for-updates.injectable"; import type { RenderResult } from "@testing-library/react"; import { fireEvent } from "@testing-library/react"; -import { advanceFakeTime, useFakeTime } from "../../../../common/test-utils/use-fake-time"; +import { advanceFakeTime, testUsingFakeTime } from "../../../../common/test-utils/use-fake-time"; import quitAndInstallUpdateInjectable from "../../main/quit-and-install-update.injectable"; import timeAfterUpdateMustBeInstalledInjectable from "./renderer/force-update-modal/time-after-update-must-be-installed.injectable"; import secondsAfterInstallStartsInjectable from "./renderer/force-update-modal/seconds-after-install-starts.injectable"; @@ -31,7 +31,7 @@ describe("force user to update when too long since update was downloaded", () => let quitAndInstallUpdateMock: jest.Mock; beforeEach(() => { - useFakeTime("2015-10-21T07:28:00Z"); + testUsingFakeTime("2015-10-21T07:28:00Z"); applicationBuilder = getApplicationBuilder(); diff --git a/src/features/application-update/child-features/periodical-checking-of-updates/periodical-checking-of-updates.test.ts b/src/features/application-update/child-features/periodical-checking-of-updates/periodical-checking-of-updates.test.ts index e38ebdcbfc..22765b85de 100644 --- a/src/features/application-update/child-features/periodical-checking-of-updates/periodical-checking-of-updates.test.ts +++ b/src/features/application-update/child-features/periodical-checking-of-updates/periodical-checking-of-updates.test.ts @@ -9,7 +9,7 @@ import electronUpdaterIsActiveInjectable from "../../../../main/electron-app/fea import publishIsConfiguredInjectable from "../../main/updating-is-enabled/publish-is-configured/publish-is-configured.injectable"; import processCheckingForUpdatesInjectable from "../../main/process-checking-for-updates.injectable"; import periodicalCheckForUpdatesInjectable from "./main/periodical-check-for-updates.injectable"; -import { advanceFakeTime, useFakeTime } from "../../../../common/test-utils/use-fake-time"; +import { advanceFakeTime, testUsingFakeTime } from "../../../../common/test-utils/use-fake-time"; const ENOUGH_TIME = 1000 * 60 * 60 * 2; @@ -18,7 +18,7 @@ describe("periodical checking of updates", () => { let processCheckingForUpdatesMock: jest.Mock; beforeEach(() => { - useFakeTime("2015-10-21T07:28:00Z"); + testUsingFakeTime("2015-10-21T07:28:00Z"); builder = getApplicationBuilder(); diff --git a/src/features/application-update/installing-update.test.ts b/src/features/application-update/installing-update.test.ts index d065f407e3..81529a851f 100644 --- a/src/features/application-update/installing-update.test.ts +++ b/src/features/application-update/installing-update.test.ts @@ -16,7 +16,7 @@ import type { DownloadPlatformUpdate } from "./main/download-update/download-pla import downloadPlatformUpdateInjectable from "./main/download-update/download-platform-update/download-platform-update.injectable"; import setUpdateOnQuitInjectable from "../../main/electron-app/features/set-update-on-quit.injectable"; import processCheckingForUpdatesInjectable from "./main/process-checking-for-updates.injectable"; -import { useFakeTime } from "../../common/test-utils/use-fake-time"; +import { testUsingFakeTime } from "../../common/test-utils/use-fake-time"; import staticFilesDirectoryInjectable from "../../common/vars/static-files-directory.injectable"; describe("installing update", () => { @@ -27,7 +27,7 @@ describe("installing update", () => { let setUpdateOnQuitMock: jest.Mock; beforeEach(() => { - useFakeTime("2015-10-21T07:28:00Z"); + testUsingFakeTime("2015-10-21T07:28:00Z"); builder = getApplicationBuilder(); diff --git a/src/features/cluster/kube-object-status-icon/show-status-for-a-kube-object.test.tsx b/src/features/cluster/kube-object-status-icon/show-status-for-a-kube-object.test.tsx index 95d508351d..49fe7f9efd 100644 --- a/src/features/cluster/kube-object-status-icon/show-status-for-a-kube-object.test.tsx +++ b/src/features/cluster/kube-object-status-icon/show-status-for-a-kube-object.test.tsx @@ -5,7 +5,7 @@ import { KubeObjectStatusLevel } from "../../../common/k8s-api/kube-object-status"; import { KubeObject } from "../../../common/k8s-api/kube-object"; import React from "react"; -import { useFakeTime } from "../../../common/test-utils/use-fake-time"; +import { testUsingFakeTime } from "../../../common/test-utils/use-fake-time"; import type { DiContainer } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable"; import type { IAtom } from "mobx"; @@ -28,7 +28,7 @@ describe("show status for a kube object", () => { let criticalStatusIsShown: boolean; beforeEach(() => { - useFakeTime("2015-10-21T07:28:00Z"); + testUsingFakeTime("2015-10-21T07:28:00Z"); builder = getApplicationBuilder(); diff --git a/src/features/cluster/sidebar-and-tab-navigation-for-core.test.tsx b/src/features/cluster/sidebar-and-tab-navigation-for-core.test.tsx index fd4d95d760..90dfc500b2 100644 --- a/src/features/cluster/sidebar-and-tab-navigation-for-core.test.tsx +++ b/src/features/cluster/sidebar-and-tab-navigation-for-core.test.tsx @@ -22,7 +22,7 @@ import pathExistsInjectable from "../../common/fs/path-exists.injectable"; import readJsonFileInjectable from "../../common/fs/read-json-file.injectable"; import { navigateToRouteInjectionToken } from "../../common/front-end-routing/navigate-to-route-injection-token"; import sidebarStorageInjectable from "../../renderer/components/layout/sidebar-storage/sidebar-storage.injectable"; -import { advanceFakeTime, useFakeTime } from "../../common/test-utils/use-fake-time"; +import { advanceFakeTime, testUsingFakeTime } from "../../common/test-utils/use-fake-time"; import storageSaveDelayInjectable from "../../renderer/utils/create-storage/storage-save-delay.injectable"; import { flushPromises } from "../../common/test-utils/flush-promises"; @@ -31,7 +31,7 @@ describe("cluster - sidebar and tab navigation for core", () => { let rendered: RenderResult; beforeEach(() => { - useFakeTime("2015-10-21T07:28:00Z"); + testUsingFakeTime("2015-10-21T07:28:00Z"); builder = getApplicationBuilder(); diff --git a/src/features/cluster/sidebar-and-tab-navigation-for-extensions.test.tsx b/src/features/cluster/sidebar-and-tab-navigation-for-extensions.test.tsx index 2441afa000..27a211a0cb 100644 --- a/src/features/cluster/sidebar-and-tab-navigation-for-extensions.test.tsx +++ b/src/features/cluster/sidebar-and-tab-navigation-for-extensions.test.tsx @@ -15,7 +15,7 @@ import pathExistsInjectable from "../../common/fs/path-exists.injectable"; import readJsonFileInjectable from "../../common/fs/read-json-file.injectable"; import { navigateToRouteInjectionToken } from "../../common/front-end-routing/navigate-to-route-injection-token"; import assert from "assert"; -import { advanceFakeTime, useFakeTime } from "../../common/test-utils/use-fake-time"; +import { advanceFakeTime, testUsingFakeTime } from "../../common/test-utils/use-fake-time"; import type { IObservableValue } from "mobx"; import { runInAction, computed, observable } from "mobx"; import storageSaveDelayInjectable from "../../renderer/utils/create-storage/storage-save-delay.injectable"; @@ -27,7 +27,7 @@ describe("cluster - sidebar and tab navigation for extensions", () => { let rendered: RenderResult; beforeEach(() => { - useFakeTime("2015-10-21T07:28:00Z"); + testUsingFakeTime("2015-10-21T07:28:00Z"); applicationBuilder = getApplicationBuilder(); diff --git a/src/features/helm-charts/add-custom-helm-repository-in-preferences.test.ts b/src/features/helm-charts/add-custom-helm-repository-in-preferences.test.ts index 684cde0038..495d2e9fb3 100644 --- a/src/features/helm-charts/add-custom-helm-repository-in-preferences.test.ts +++ b/src/features/helm-charts/add-custom-helm-repository-in-preferences.test.ts @@ -18,7 +18,7 @@ import isPathInjectable from "../../renderer/components/input/validators/is-path import showSuccessNotificationInjectable from "../../renderer/components/notifications/show-success-notification.injectable"; import showErrorNotificationInjectable from "../../renderer/components/notifications/show-error-notification.injectable"; import type { AsyncResult } from "../../common/utils/async-result"; -import { useFakeTime } from "../../common/test-utils/use-fake-time"; +import { testUsingFakeTime } from "../../common/test-utils/use-fake-time"; describe("add custom helm repository in preferences", () => { let builder: ApplicationBuilder; @@ -33,7 +33,7 @@ describe("add custom helm repository in preferences", () => { builder = getApplicationBuilder(); - useFakeTime("2021-01-01 12:00:00"); + testUsingFakeTime("2021-01-01 12:00:00"); execFileMock = asyncFn(); getActiveHelmRepositoriesMock = asyncFn(); diff --git a/src/features/helm-charts/installing-chart/__snapshots__/opening-dock-tab-for-installing-helm-chart.test.ts.snap b/src/features/helm-charts/installing-chart/__snapshots__/opening-dock-tab-for-installing-helm-chart.test.ts.snap index e949e6c3c6..de1103cdc7 100644 --- a/src/features/helm-charts/installing-chart/__snapshots__/opening-dock-tab-for-installing-helm-chart.test.ts.snap +++ b/src/features/helm-charts/installing-chart/__snapshots__/opening-dock-tab-for-installing-helm-chart.test.ts.snap @@ -3,6 +3,44 @@ exports[`opening dock tab for installing helm chart given application is started, when navigating to helm charts renders 1`] = `
+
+
+
+
+ +
+ + + close + + +
+ Close +
+
+
+
+
+
@@ -502,6 +540,44 @@ exports[`opening dock tab for installing helm chart given application is started exports[`opening dock tab for installing helm chart given application is started, when navigating to helm charts when charts resolve renders 1`] = `
+
+
+
+
+ +
+ + + close + + +
+ Close +
+
+
+
+
+
@@ -1171,6 +1247,44 @@ exports[`opening dock tab for installing helm chart given application is started exports[`opening dock tab for installing helm chart given application is started, when navigating to helm charts when charts resolve when opening details of a chart renders 1`] = `
+
+
+
+
+ +
+ + + close + + +
+ Close +
+
+
+
+
+
@@ -1897,6 +2011,44 @@ exports[`opening dock tab for installing helm chart given application is started exports[`opening dock tab for installing helm chart given application is started, when navigating to helm charts when charts resolve when opening details of a chart when chart versions resolve renders 1`] = `
+
+
+
+
+ +
+ + + close + + +
+ Close +
+
+
+
+
+
@@ -2806,6 +2958,44 @@ exports[`opening dock tab for installing helm chart given application is started exports[`opening dock tab for installing helm chart given application is started, when navigating to helm charts when charts resolve when opening details of a chart when chart versions resolve when readme resolves renders 1`] = `
+
+
+
+
+ +
+ + + close + + +
+ Close +
+
+
+
+
+
@@ -3725,6 +3915,44 @@ exports[`opening dock tab for installing helm chart given application is started exports[`opening dock tab for installing helm chart given application is started, when navigating to helm charts when charts resolve when opening details of a chart when chart versions resolve when readme resolves when selecting different version renders 1`] = `
+
+
+
+
+ +
+ + + close + + +
+ Close +
+
+
+
+
+
@@ -4634,6 +4862,44 @@ exports[`opening dock tab for installing helm chart given application is started exports[`opening dock tab for installing helm chart given application is started, when navigating to helm charts when charts resolve when opening details of a chart when chart versions resolve when readme resolves when selecting different version when readme rejects renders 1`] = `
+
+
+
+
+ +
+ + + close + + +
+ Close +
+
+
+
+
+
@@ -5547,6 +5813,44 @@ exports[`opening dock tab for installing helm chart given application is started exports[`opening dock tab for installing helm chart given application is started, when navigating to helm charts when charts resolve when opening details of a chart when chart versions resolve when readme resolves when selecting different version when readme resolves renders 1`] = `
+
+
+
+
+ +
+ + + close + + +
+ Close +
+
+
+
+
+
@@ -6466,6 +6770,44 @@ exports[`opening dock tab for installing helm chart given application is started exports[`opening dock tab for installing helm chart given application is started, when navigating to helm charts when charts resolve when opening details of a chart when chart versions resolve when readme resolves when selecting to install the chart renders 1`] = `
+
+
+
+
+ +
+ + + close + + +
+ Close +
+
+
+
+
+
diff --git a/src/features/helm-charts/upgrade-chart/upgrade-chart-new-tab.test.ts b/src/features/helm-charts/upgrade-chart/upgrade-chart-new-tab.test.ts index c58cf24ba2..7d46856fec 100644 --- a/src/features/helm-charts/upgrade-chart/upgrade-chart-new-tab.test.ts +++ b/src/features/helm-charts/upgrade-chart/upgrade-chart-new-tab.test.ts @@ -17,7 +17,7 @@ import type { RequestHelmReleaseConfiguration } from "../../../common/k8s-api/en import requestHelmReleaseConfigurationInjectable from "../../../common/k8s-api/endpoints/helm-releases.api/request-configuration.injectable"; import type { RequestHelmReleases } from "../../../common/k8s-api/endpoints/helm-releases.api/request-releases.injectable"; import requestHelmReleasesInjectable from "../../../common/k8s-api/endpoints/helm-releases.api/request-releases.injectable"; -import { advanceFakeTime, useFakeTime } from "../../../common/test-utils/use-fake-time"; +import { advanceFakeTime, testUsingFakeTime } from "../../../common/test-utils/use-fake-time"; import dockStoreInjectable from "../../../renderer/components/dock/dock/store.injectable"; import type { ApplicationBuilder } from "../../../renderer/components/test-utils/get-application-builder"; import { getApplicationBuilder } from "../../../renderer/components/test-utils/get-application-builder"; @@ -51,7 +51,7 @@ describe("New Upgrade Helm Chart Dock Tab", () => { navigateToHelmReleases = windowDi.inject(navigateToHelmReleasesInjectable); }); - useFakeTime("2020-01-12 12:00:00"); + testUsingFakeTime("2020-01-12 12:00:00"); builder.namespaces.add("my-first-namespace"); builder.namespaces.add("my-second-namespace"); diff --git a/src/features/helm-releases/showing-details-for-helm-release.test.ts b/src/features/helm-releases/showing-details-for-helm-release.test.ts index b743ce013a..9294b3057e 100644 --- a/src/features/helm-releases/showing-details-for-helm-release.test.ts +++ b/src/features/helm-releases/showing-details-for-helm-release.test.ts @@ -15,7 +15,7 @@ import type { RequestHelmReleaseConfiguration } from "../../common/k8s-api/endpo import requestHelmReleaseConfigurationInjectable from "../../common/k8s-api/endpoints/helm-releases.api/request-configuration.injectable"; import type { RequestHelmReleaseUpdate } from "../../common/k8s-api/endpoints/helm-releases.api/request-update.injectable"; import requestHelmReleaseUpdateInjectable from "../../common/k8s-api/endpoints/helm-releases.api/request-update.injectable"; -import { useFakeTime } from "../../common/test-utils/use-fake-time"; +import { testUsingFakeTime } from "../../common/test-utils/use-fake-time"; import type { RequestDetailedHelmRelease } from "../../renderer/components/+helm-releases/release-details/release-details-model/request-detailed-helm-release.injectable"; import requestDetailedHelmReleaseInjectable from "../../renderer/components/+helm-releases/release-details/release-details-model/request-detailed-helm-release.injectable"; import showSuccessNotificationInjectable from "../../renderer/components/notifications/show-success-notification.injectable"; @@ -45,7 +45,7 @@ describe("showing details for helm release", () => { let showCheckedErrorNotificationMock: jest.Mock; beforeEach(() => { - useFakeTime("2015-10-21T07:28:00Z"); + testUsingFakeTime("2015-10-21T07:28:00Z"); builder = getApplicationBuilder(); diff --git a/src/features/quitting-and-restarting-the-app/quitting-the-app-using-application-menu.test.ts b/src/features/quitting-and-restarting-the-app/quitting-the-app-using-application-menu.test.ts index 654b361eb5..a7a6e4ae60 100644 --- a/src/features/quitting-and-restarting-the-app/quitting-the-app-using-application-menu.test.ts +++ b/src/features/quitting-and-restarting-the-app/quitting-the-app-using-application-menu.test.ts @@ -9,7 +9,7 @@ import type { ClusterManager } from "../../main/cluster/manager"; import exitAppInjectable from "../../main/electron-app/features/exit-app.injectable"; import clusterManagerInjectable from "../../main/cluster/manager.injectable"; import stopServicesAndExitAppInjectable from "../../main/stop-services-and-exit-app.injectable"; -import { advanceFakeTime, useFakeTime } from "../../common/test-utils/use-fake-time"; +import { advanceFakeTime, testUsingFakeTime } from "../../common/test-utils/use-fake-time"; describe("quitting the app using application menu", () => { describe("given application has started", () => { @@ -18,7 +18,7 @@ describe("quitting the app using application menu", () => { let exitAppMock: jest.Mock; beforeEach(async () => { - useFakeTime("2015-10-21T07:28:00Z"); + testUsingFakeTime("2015-10-21T07:28:00Z"); builder = getApplicationBuilder(); diff --git a/src/main/shell-session/node-shell-session/node-shell-session.ts b/src/main/shell-session/node-shell-session/node-shell-session.ts index 6a8af4c09e..492c70d73d 100644 --- a/src/main/shell-session/node-shell-session/node-shell-session.ts +++ b/src/main/shell-session/node-shell-session/node-shell-session.ts @@ -9,9 +9,10 @@ import type { KubeConfig } from "@kubernetes/client-node"; import type { ShellSessionArgs, ShellSessionDependencies } from "../shell-session"; import { ShellOpenError, ShellSession } from "../shell-session"; import { get, once } from "lodash"; -import { Node, NodeApi } from "../../../common/k8s-api/endpoints"; +import { NodeApi } from "../../../common/k8s-api/endpoints"; import { TerminalChannels } from "../../../common/terminal/channels"; import type { CreateKubeJsonApiForCluster } from "../../../common/k8s-api/create-kube-json-api-for-cluster.injectable"; +import type { CreateKubeApi } from "../../../common/k8s-api/create-kube-api.injectable"; export interface NodeShellSessionArgs extends ShellSessionArgs { nodeName: string; @@ -19,6 +20,7 @@ export interface NodeShellSessionArgs extends ShellSessionArgs { export interface NodeShellSessionDependencies extends ShellSessionDependencies { createKubeJsonApiForCluster: CreateKubeJsonApiForCluster; + createKubeApi: CreateKubeApi; } export class NodeShellSession extends ShellSession { @@ -67,8 +69,7 @@ export class NodeShellSession extends ShellSession { const env = await this.getCachedShellEnv(); const args = ["exec", "-i", "-t", "-n", "kube-system", this.podName, "--"]; - const nodeApi = new NodeApi({ - objectConstructor: Node, + const nodeApi = this.dependencies.createKubeApi(NodeApi, { request: this.dependencies.createKubeJsonApiForCluster(this.cluster.id), }); const node = await nodeApi.get({ name: this.nodeName }); diff --git a/src/renderer/before-frame-starts/runnables/setup-auto-registration.injectable.ts b/src/renderer/before-frame-starts/runnables/setup-auto-registration.injectable.ts index 78ba68c173..64bc9dee58 100644 --- a/src/renderer/before-frame-starts/runnables/setup-auto-registration.injectable.ts +++ b/src/renderer/before-frame-starts/runnables/setup-auto-registration.injectable.ts @@ -7,12 +7,14 @@ import autoRegistrationEmitterInjectable from "../../../common/k8s-api/api-manag import apiManagerInjectable from "../../../common/k8s-api/api-manager/manager.injectable"; import { CustomResourceStore } from "../../../common/k8s-api/api-manager/resource.store"; import type { CustomResourceDefinition } from "../../../common/k8s-api/endpoints"; +import type { KubeApiDependencies } from "../../../common/k8s-api/kube-api"; import { KubeApi } from "../../../common/k8s-api/kube-api"; import { KubeObject } from "../../../common/k8s-api/kube-object"; import { beforeClusterFrameStartsSecondInjectionToken } from "../tokens"; import type { KubeObjectStoreDependencies } from "../../../common/k8s-api/kube-object.store"; import clusterFrameContextForNamespacedResourcesInjectable from "../../cluster-frame-context/for-namespaced-resources.injectable"; import loggerInjectable from "../../../common/logger.injectable"; +import maybeKubeApiInjectable from "../../../common/k8s-api/maybe-kube-api.injectable"; const setupAutoRegistrationInjectable = getInjectable({ id: "setup-auto-registration", @@ -22,7 +24,11 @@ const setupAutoRegistrationInjectable = getInjectable({ const autoRegistrationEmitter = di.inject(autoRegistrationEmitterInjectable); const beforeApiManagerInitializationCrds: CustomResourceDefinition[] = []; const beforeApiManagerInitializationApis: KubeApi[] = []; - const deps: KubeObjectStoreDependencies = { + const kubeApiDependencies: KubeApiDependencies = { + logger: di.inject(loggerInjectable), + maybeKubeApi: di.inject(maybeKubeApiInjectable), + }; + const kubeObjectStoreDependencies: KubeObjectStoreDependencies = { context: di.inject(clusterFrameContextForNamespacedResourcesInjectable), logger: di.inject(loggerInjectable), }; @@ -42,7 +48,7 @@ const setupAutoRegistrationInjectable = getInjectable({ return rawApi; } - const api = new KubeApi({ objectConstructor }); + const api = new KubeApi(kubeApiDependencies, { objectConstructor }); apiManager.registerApi(api); @@ -50,7 +56,7 @@ const setupAutoRegistrationInjectable = getInjectable({ })(); if (!apiManager.getStore(api)) { - apiManager.registerStore(new CustomResourceStore(deps, api)); + apiManager.registerStore(new CustomResourceStore(kubeObjectStoreDependencies, api)); } }; const autoInitKubeApi = (api: KubeApi) => { diff --git a/src/renderer/components/countdown/countdown.test.tsx b/src/renderer/components/countdown/countdown.test.tsx index 9bb08f486b..6a84e6970e 100644 --- a/src/renderer/components/countdown/countdown.test.tsx +++ b/src/renderer/components/countdown/countdown.test.tsx @@ -10,7 +10,7 @@ import { renderFor } from "../test-utils/renderFor"; import { Countdown } from "./countdown"; import React from "react"; import type { RenderResult } from "@testing-library/react"; -import { advanceFakeTime, useFakeTime } from "../../../common/test-utils/use-fake-time"; +import { advanceFakeTime, testUsingFakeTime } from "../../../common/test-utils/use-fake-time"; import type { IComputedValue } from "mobx"; import { observe } from "mobx"; import { noop } from "../../../common/utils"; @@ -20,7 +20,7 @@ describe("countdown", () => { let render: DiRender; beforeEach(() => { - useFakeTime("2015-10-21T07:28:00Z"); + testUsingFakeTime("2015-10-21T07:28:00Z"); di = createContainer("irrelevant"); diff --git a/src/renderer/components/render-delay/__tests__/render-delay.test.tsx b/src/renderer/components/render-delay/__tests__/render-delay.test.tsx index c189e3f38e..e83bee28c0 100644 --- a/src/renderer/components/render-delay/__tests__/render-delay.test.tsx +++ b/src/renderer/components/render-delay/__tests__/render-delay.test.tsx @@ -7,7 +7,7 @@ import { RenderDelay } from "../render-delay"; import type { DiRender } from "../../test-utils/renderFor"; import { renderFor } from "../../test-utils/renderFor"; import { getDiForUnitTesting } from "../../../getDiForUnitTesting"; -import { advanceFakeTime, useFakeTime } from "../../../../common/test-utils/use-fake-time"; +import { advanceFakeTime, testUsingFakeTime } from "../../../../common/test-utils/use-fake-time"; import cancelIdleCallbackInjectable from "../cancel-idle-callback.injectable"; import requestIdleCallbackInjectable from "../request-idle-callback.injectable"; import type { RenderResult } from "@testing-library/react"; @@ -21,7 +21,7 @@ describe("", () => { render = renderFor(di); - useFakeTime("2020-01-17 12:18:19"); + testUsingFakeTime("2020-01-17 12:18:19"); di.override(cancelIdleCallbackInjectable, () => clearTimeout); di.override(requestIdleCallbackInjectable, () => (callback, opts) => setTimeout(callback, opts.timeout) as any); diff --git a/src/renderer/components/test-utils/get-application-builder.tsx b/src/renderer/components/test-utils/get-application-builder.tsx index 405a4e3179..c27d677425 100644 --- a/src/renderer/components/test-utils/get-application-builder.tsx +++ b/src/renderer/components/test-utils/get-application-builder.tsx @@ -68,6 +68,7 @@ import shouldStartHiddenInjectable from "../../../main/electron-app/features/sho import fsInjectable from "../../../common/fs/fs.injectable"; import joinPathsInjectable from "../../../common/path/join-paths.injectable"; import homeDirectoryPathInjectable from "../../../common/os/home-directory-path.injectable"; +import { testUsingFakeTime } from "../../../common/test-utils/use-fake-time"; type Callback = (di: DiContainer) => void | Promise; @@ -167,6 +168,8 @@ export const getApplicationBuilder = () => { mainDi.register(mainExtensionsStateInjectable); }); + testUsingFakeTime(); + const { overrideForWindow, sendToWindow } = overrideChannels(mainDi); const beforeApplicationStartCallbacks: Callback[] = []; diff --git a/src/renderer/frames/cluster-frame/cluster-frame.test.tsx b/src/renderer/frames/cluster-frame/cluster-frame.test.tsx index b969291fd2..1a4cc82248 100644 --- a/src/renderer/frames/cluster-frame/cluster-frame.test.tsx +++ b/src/renderer/frames/cluster-frame/cluster-frame.test.tsx @@ -23,7 +23,7 @@ import legacyOnChannelListenInjectable from "../../ipc/legacy-channel-listen.inj import currentRouteComponentInjectable from "../../routes/current-route-component.injectable"; import hostedClusterIdInjectable from "../../cluster-frame-context/hosted-cluster-id.injectable"; import hostedClusterInjectable from "../../cluster-frame-context/hosted-cluster.injectable"; -import { useFakeTime } from "../../../common/test-utils/use-fake-time"; +import { testUsingFakeTime } from "../../../common/test-utils/use-fake-time"; import currentlyInClusterFrameInjectable from "../../routes/currently-in-cluster-frame.injectable"; describe("", () => { @@ -47,7 +47,7 @@ describe("", () => { di.override(storesAndApisCanBeCreatedInjectable, () => true); di.override(currentlyInClusterFrameInjectable, () => true); - useFakeTime("2000-01-01 12:00:00am"); + testUsingFakeTime("2000-01-01 12:00:00am"); const createCluster = di.inject(createClusterInjectable);