1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Make KubeApi consume its dependencies while not breaking the extension API

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2023-01-04 11:20:14 -05:00
parent 1ef5677d61
commit 1be1b4418f
106 changed files with 972 additions and 316 deletions

View File

@ -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<KubeObject> {
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",

View File

@ -2,9 +2,9 @@
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { KubeJsonApi } from "../kube-json-api";
import type { ApiManager } from "../api-manager";
import { Ingress, IngressApi } from "../endpoints";
import type { IngressApi } from "../endpoints";
import { Ingress } from "../endpoints";
import { getDiForUnitTesting } from "../../../renderer/getDiForUnitTesting";
import apiManagerInjectable from "../api-manager/manager.injectable";
import type { Fetch } from "../../fetch/fetch.injectable";
@ -20,14 +20,17 @@ import directoryForUserDataInjectable from "../../app-paths/directory-for-user-d
import createClusterInjectable from "../../../main/create-cluster/create-cluster.injectable";
import hostedClusterInjectable from "../../../renderer/cluster-frame-context/hosted-cluster.injectable";
import directoryForKubeConfigsInjectable from "../../app-paths/directory-for-kube-configs/directory-for-kube-configs.injectable";
import apiKubeInjectable from "../../../renderer/k8s/api-kube.injectable";
import type { DiContainer } from "@ogre-tools/injectable";
import ingressApiInjectable from "../endpoints/ingress.api.injectable";
describe("KubeApi", () => {
let request: KubeJsonApi;
let di: DiContainer;
let registerApiSpy: jest.SpiedFunction<ApiManager["registerApi"]>;
let fetchMock: AsyncFnMock<Fetch>;
beforeEach(async () => {
const di = getDiForUnitTesting({ doGeneralOverrides: true });
di = getDiForUnitTesting({ doGeneralOverrides: true });
fetchMock = asyncFn();
di.override(fetchInjectable, () => fetchMock);
@ -37,6 +40,7 @@ describe("KubeApi", () => {
di.override(storesAndApisCanBeCreatedInjectable, () => true);
const createCluster = di.inject(createClusterInjectable);
const createKubeJsonApi = di.inject(createKubeJsonApiInjectable);
di.override(hostedClusterInjectable, () => createCluster({
contextName: "some-context-name",
@ -46,12 +50,11 @@ describe("KubeApi", () => {
clusterServerUrl: "https://localhost:8080",
}));
const createKubeJsonApi = di.inject(createKubeJsonApiInjectable);
request = createKubeJsonApi({
di.override(apiKubeInjectable, () => createKubeJsonApi({
serverAddress: `http://127.0.0.1:9999`,
apiBase: "/api-kube",
});
}));
registerApiSpy = jest.spyOn(di.inject(apiManagerInjectable), "registerApi");
const setupAutoRegistration = di.inject(setupAutoRegistrationInjectable);
@ -64,13 +67,7 @@ describe("KubeApi", () => {
let getCall: Promise<Ingress | null>;
beforeEach(async () => {
ingressApi = new IngressApi({
request,
objectConstructor: Ingress,
apiBase: "/apis/networking.k8s.io/v1/ingresses",
fallbackApiBases: ["/apis/extensions/v1beta1/ingresses"],
checkPreferredVersion: true,
});
ingressApi = di.inject(ingressApiInjectable);
getCall = ingressApi.get({
name: "foo",
namespace: "default",

View File

@ -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<Fetch>;
let di: DiContainer;
beforeEach(async () => {
const di = getDiForUnitTesting({ doGeneralOverrides: true });
di = getDiForUnitTesting({ doGeneralOverrides: true });
di.override(directoryForUserDataInjectable, () => "/some-user-store-path");
di.override(directoryForKubeConfigsInjectable, () => "/some-kube-configs");
di.override(storesAndApisCanBeCreatedInjectable, () => true);
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", () => {

View File

@ -3,11 +3,12 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import loggerInjectable from "../logger.injectable";
import { apiKubePrefix } from "../vars";
import isDevelopmentInjectable from "../vars/is-development.injectable";
import apiBaseInjectable from "./api-base.injectable";
import type { KubeApiConstructor } from "./create-kube-api-for-remote-cluster.injectable";
import createKubeJsonApiInjectable from "./create-kube-json-api.injectable";
import type { KubeApiOptions } from "./kube-api";
import { KubeApi } from "./kube-api";
import type { KubeJsonApiDataFor, KubeObject, KubeObjectConstructor } from "./kube-object";
@ -21,12 +22,12 @@ export interface CreateKubeApiForCluster {
<Object extends KubeObject, Api extends KubeApi<Object>, Data extends KubeJsonApiDataFor<Object>>(
cluster: CreateKubeApiForLocalClusterConfig,
kubeClass: KubeObjectConstructor<Object, Data>,
apiClass: new (apiOpts: KubeApiOptions<Object>) => Api
apiClass: KubeApiConstructor<Object, Api>,
): Api;
<Object extends KubeObject, Data extends KubeJsonApiDataFor<Object>>(
cluster: CreateKubeApiForLocalClusterConfig,
kubeClass: KubeObjectConstructor<Object, Data>,
apiClass?: new (apiOpts: KubeApiOptions<Object>) => KubeApi<Object>
apiClass?: KubeApiConstructor<Object, KubeApi<Object>>,
): KubeApi<Object>;
}
@ -36,27 +37,42 @@ const createKubeApiForClusterInjectable = getInjectable({
const apiBase = di.inject(apiBaseInjectable);
const isDevelopment = di.inject(isDevelopmentInjectable);
const createKubeJsonApi = di.inject(createKubeJsonApiInjectable);
const logger = di.inject(loggerInjectable);
return (
cluster: CreateKubeApiForLocalClusterConfig,
kubeClass: KubeObjectConstructor<KubeObject, KubeJsonApiDataFor<KubeObject>>,
apiClass = KubeApi,
) => (
new apiClass({
objectConstructor: kubeClass,
request: createKubeJsonApi(
{
serverAddress: apiBase.config.serverAddress,
apiBase: apiKubePrefix,
debug: isDevelopment,
}, {
headers: {
"Host": `${cluster.metadata.uid}.lens.app:${new URL(apiBase.config.serverAddress).port}`,
},
apiClass?: KubeApiConstructor<KubeObject, KubeApi<KubeObject>>,
) => {
const request = createKubeJsonApi(
{
serverAddress: apiBase.config.serverAddress,
apiBase: apiKubePrefix,
debug: isDevelopment,
}, {
headers: {
"Host": `${cluster.metadata.uid}.lens.app:${new URL(apiBase.config.serverAddress).port}`,
},
),
})
);
});
if (apiClass) {
return new apiClass({
objectConstructor: kubeClass,
request,
});
}
return new KubeApi(
{
logger,
maybeKubeApi: undefined,
},
{
objectConstructor: kubeClass,
request,
},
);
};
},
});

View File

@ -6,6 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable";
import type { AgentOptions } from "https";
import { Agent } from "https";
import type { RequestInit } from "node-fetch";
import loggerInjectable from "../logger.injectable";
import isDevelopmentInjectable from "../vars/is-development.injectable";
import createKubeJsonApiInjectable from "./create-kube-json-api.injectable";
import type { KubeApiOptions } from "./kube-api";
@ -32,16 +33,18 @@ export interface CreateKubeApiForRemoteClusterConfig {
agent?: Agent;
}
export type KubeApiConstructor<Object extends KubeObject, Api extends KubeApi<Object>> = new (apiOpts: KubeApiOptions<Object>) => Api;
export interface CreateKubeApiForRemoteCluster {
<Object extends KubeObject, Api extends KubeApi<Object>, Data extends KubeJsonApiDataFor<Object>>(
config: CreateKubeApiForRemoteClusterConfig,
kubeClass: KubeObjectConstructor<Object, Data>,
apiClass: new (apiOpts: KubeApiOptions<Object>) => Api,
apiClass: KubeApiConstructor<Object, Api>,
): Api;
<Object extends KubeObject, Data extends KubeJsonApiDataFor<Object>>(
config: CreateKubeApiForRemoteClusterConfig,
kubeClass: KubeObjectConstructor<Object, Data>,
apiClass?: new (apiOpts: KubeApiOptions<Object>) => KubeApi<Object>,
apiClass?: KubeApiConstructor<Object, KubeApi<Object>>,
): KubeApi<Object>;
}
@ -50,8 +53,13 @@ const createKubeApiForRemoteClusterInjectable = getInjectable({
instantiate: (di): CreateKubeApiForRemoteCluster => {
const isDevelopment = di.inject(isDevelopmentInjectable);
const createKubeJsonApi = di.inject(createKubeJsonApiInjectable);
const logger = di.inject(loggerInjectable);
return (config: CreateKubeApiForRemoteClusterConfig, kubeClass: KubeObjectConstructor<KubeObject, KubeJsonApiDataFor<KubeObject>>, apiClass = KubeApi) => {
return (
config: CreateKubeApiForRemoteClusterConfig,
kubeClass: KubeObjectConstructor<KubeObject, KubeJsonApiDataFor<KubeObject>>,
apiClass?: KubeApiConstructor<KubeObject, KubeApi<KubeObject>>,
) => {
const reqInit: RequestInit = {};
const agentOptions: AgentOptions = {};
@ -93,10 +101,23 @@ const createKubeApiForRemoteClusterInjectable = getInjectable({
} : {}),
}, reqInit);
return new apiClass({
objectConstructor: kubeClass,
request,
});
if (apiClass) {
return new apiClass({
objectConstructor: kubeClass,
request,
});
}
return new KubeApi(
{
logger,
maybeKubeApi: undefined,
},
{
objectConstructor: kubeClass,
request,
},
);
};
},
});

View File

@ -0,0 +1,26 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import loggerInjectable from "../logger.injectable";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "./kube-api";
import maybeKubeApiInjectable from "./maybe-kube-api.injectable";
export interface CreateKubeApi {
<Api>(ctor: new (deps: KubeApiDependencies, opts: DerivedKubeApiOptions) => Api, opts?: DerivedKubeApiOptions): Api;
}
const createKubeApiInjectable = getInjectable({
id: "create-kube-api",
instantiate: (di): CreateKubeApi => {
const deps: KubeApiDependencies = {
logger: di.inject(loggerInjectable),
maybeKubeApi: di.inject(maybeKubeApiInjectable),
};
return (ctor, opts) => new ctor(deps, opts ?? {});
},
});
export default createKubeApiInjectable;

View File

@ -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,

View File

@ -2,7 +2,7 @@
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { DerivedKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { KubeJsonApiData } from "../kube-json-api";
import type { ClusterScopedMetadata, KubeObjectMetadata, KubeObjectScope } from "../kube-object";
@ -47,8 +47,8 @@ export class ClusterRoleBinding extends KubeObject<
}
export class ClusterRoleBindingApi extends KubeApi<ClusterRoleBinding, ClusterRoleBindingData> {
constructor(opts: DerivedKubeApiOptions = {}) {
super({
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
super(deps, {
...opts,
objectConstructor: ClusterRoleBinding,
});

View File

@ -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,

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { DerivedKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { KubeJsonApiData } from "../kube-json-api";
import type { ClusterScopedMetadata, KubeObjectMetadata, KubeObjectScope } from "../kube-object";
@ -40,8 +40,8 @@ export class ClusterRole extends KubeObject<
}
export class ClusterRoleApi extends KubeApi<ClusterRole, ClusterRoleData> {
constructor(opts: DerivedKubeApiOptions = {}) {
super({
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
super(deps, {
...opts,
objectConstructor: ClusterRole,
});

View File

@ -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,

View File

@ -4,7 +4,7 @@
*/
import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
export class ClusterApi extends KubeApi<Cluster> {
@ -18,9 +18,9 @@ export class ClusterApi extends KubeApi<Cluster> {
*/
static namespaced = true;
constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) {
super({
...opts,
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
super(deps, {
...opts ?? {},
objectConstructor: Cluster,
});
}

View File

@ -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,

View File

@ -4,7 +4,7 @@
*/
import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
export interface ComponentStatusCondition {
@ -28,8 +28,8 @@ export class ComponentStatus extends KubeObject {
}
export class ComponentStatusApi extends KubeApi<ComponentStatus> {
constructor(opts: DerivedKubeApiOptions = {}) {
super({
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
super(deps, {
...opts,
objectConstructor: ComponentStatus,
});

View File

@ -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,

View File

@ -6,7 +6,7 @@
import type { KubeObjectMetadata, KubeObjectScope, NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object";
import type { KubeJsonApiData } from "../kube-json-api";
import type { DerivedKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import { autoBind } from "../../utils";
@ -44,8 +44,8 @@ export class ConfigMap extends KubeObject<
}
export class ConfigMapApi extends KubeApi<ConfigMap, ConfigMapData> {
constructor(opts?: DerivedKubeApiOptions) {
super({
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
super(deps, {
objectConstructor: ConfigMap,
...opts ?? {},
});

View File

@ -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,
});
},

View File

@ -7,13 +7,13 @@ import moment from "moment";
import type { NamespaceScopedMetadata, ObjectReference } from "../kube-object";
import { KubeObject } from "../kube-object";
import { formatDuration } from "../../utils/formatDuration";
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { JobTemplateSpec } from "./types/job-template-spec";
export class CronJobApi extends KubeApi<CronJob> {
constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) {
super({
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions) {
super(deps, {
...opts,
objectConstructor: CronJob,
});

View File

@ -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,

View File

@ -8,7 +8,7 @@ import customResourcesRouteInjectable from "../../front-end-routing/routes/clust
import { buildURL } from "../../utils/buildUrl";
import type { BaseKubeObjectCondition, ClusterScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { JSONSchemaProps } from "./types/json-schema-props";
@ -234,8 +234,8 @@ export class CustomResourceDefinition extends KubeObject<
}
export class CustomResourceDefinitionApi extends KubeApi<CustomResourceDefinition> {
constructor(opts: DerivedKubeApiOptions = {}) {
super({
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
super(deps, {
objectConstructor: CustomResourceDefinition,
checkPreferredVersion: true,
...opts,

View File

@ -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,

View File

@ -5,7 +5,7 @@
import moment from "moment";
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { KubeObjectStatus, LabelSelector, NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object";
@ -83,9 +83,9 @@ export class DaemonSet extends KubeObject<
}
export class DaemonSetApi extends KubeApi<DaemonSet> {
constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) {
super({
...opts,
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
super(deps, {
...opts ?? {},
objectConstructor: DaemonSet,
});
}

View File

@ -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,

View File

@ -5,7 +5,7 @@
import moment from "moment";
import type { DerivedKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { PodSpec } from "./pod.api";
import type { KubeObjectStatus, LabelSelector, NamespaceScopedMetadata } from "../kube-object";
@ -13,10 +13,10 @@ import { KubeObject } from "../kube-object";
import { hasTypedProperty, isNumber, isObject } from "../../utils";
export class DeploymentApi extends KubeApi<Deployment> {
constructor(opts?: DerivedKubeApiOptions) {
super({
objectConstructor: Deployment,
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
super(deps, {
...opts ?? {},
objectConstructor: Deployment,
});
}

View File

@ -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,

View File

@ -6,7 +6,7 @@
import { autoBind } from "../../utils";
import type { KubeObjectMetadata, KubeObjectScope, NamespaceScopedMetadata, ObjectReference } from "../kube-object";
import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { KubeJsonApiData } from "../kube-json-api";
@ -112,8 +112,8 @@ export class Endpoints extends KubeObject<
}
export class EndpointsApi extends KubeApi<Endpoints, EndpointsData> {
constructor(opts: DerivedKubeApiOptions = {}) {
super({
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
super(deps, {
objectConstructor: Endpoints,
...opts,
});

View File

@ -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,

View File

@ -7,7 +7,7 @@ import moment from "moment";
import type { KubeObjectMetadata, KubeObjectScope, ObjectReference } from "../kube-object";
import { KubeObject } from "../kube-object";
import { formatDuration } from "../../utils/formatDuration";
import type { DerivedKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { KubeJsonApiData } from "../kube-json-api";
@ -132,8 +132,8 @@ export class KubeEvent extends KubeObject<KubeObjectMetadata<KubeObjectScope.Nam
}
export class KubeEventApi extends KubeApi<KubeEvent, KubeEventData> {
constructor(opts: DerivedKubeApiOptions = {}) {
super({
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
super(deps, {
objectConstructor: KubeEvent,
...opts,
});

View File

@ -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,

View File

@ -5,7 +5,7 @@
import type { BaseKubeObjectCondition, LabelSelector, NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { OptionVarient } from "../../utils";
@ -202,8 +202,8 @@ export class HorizontalPodAutoscaler extends KubeObject<
}
export class HorizontalPodAutoscalerApi extends KubeApi<HorizontalPodAutoscaler> {
constructor(opts?: DerivedKubeApiOptions) {
super({
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
super(deps, {
objectConstructor: HorizontalPodAutoscaler,
...opts ?? {},
});

View File

@ -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,

View File

@ -6,14 +6,14 @@
import type { NamespaceScopedMetadata, TypedLocalObjectReference } from "../kube-object";
import { KubeObject } from "../kube-object";
import { hasTypedProperty, isString, iter } from "../../utils";
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { RequireExactlyOne } from "type-fest";
export class IngressApi extends KubeApi<Ingress> {
constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) {
super({
...opts,
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
super(deps, {
...opts ?? {},
objectConstructor: Ingress,
// Add fallback for Kubernetes <1.19
checkPreferredVersion: true,

View File

@ -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,
});
},

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { PodSpec } from "./pod.api";
import type { Container } from "./types/container";
@ -95,9 +95,9 @@ export class Job extends KubeObject<
}
export class JobApi extends KubeApi<Job> {
constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) {
super({
...opts,
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
super(deps, {
...opts ?? {},
objectConstructor: Job,
});
}

View File

@ -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,

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object";
@ -47,9 +47,9 @@ export class Lease extends KubeObject<
}
export class LeaseApi extends KubeApi<Lease> {
constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) {
super({
...opts,
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
super(deps, {
...opts ?? {},
objectConstructor: Lease,
});
}

View File

@ -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,

View File

@ -5,7 +5,7 @@
import type { NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
export enum LimitType {
@ -62,8 +62,8 @@ export class LimitRange extends KubeObject<
}
export class LimitRangeApi extends KubeApi<LimitRange> {
constructor(opts?: DerivedKubeApiOptions) {
super({
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
super(deps, {
objectConstructor: LimitRange,
...opts ?? {},
});

View File

@ -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,

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { ClusterScopedMetadata, KubeObjectStatus } from "../kube-object";
import { KubeObject } from "../kube-object";
@ -36,9 +36,9 @@ export class Namespace extends KubeObject<
}
export class NamespaceApi extends KubeApi<Namespace> {
constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) {
super({
...opts,
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
super(deps, {
...opts ?? {},
objectConstructor: Namespace,
});
}

View File

@ -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,

View File

@ -5,7 +5,7 @@
import type { LabelSelector, NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
export interface IPolicyIpBlock {
@ -124,8 +124,8 @@ export class NetworkPolicy extends KubeObject<
}
export class NetworkPolicyApi extends KubeApi<NetworkPolicy> {
constructor(opts: DerivedKubeApiOptions = {}) {
super({
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
super(deps, {
objectConstructor: NetworkPolicy,
...opts,
});

View File

@ -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,

View File

@ -6,14 +6,14 @@
import type { BaseKubeObjectCondition, ClusterScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object";
import { cpuUnitsToNumber, unitsToBytes, isObject } from "../../../renderer/utils";
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import { TypedRegEx } from "typed-regex";
export class NodeApi extends KubeApi<Node> {
constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) {
super({
...opts,
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
super(deps, {
...opts ?? {},
objectConstructor: Node,
});
}

View File

@ -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,

View File

@ -6,15 +6,15 @@
import type { LabelSelector, NamespaceScopedMetadata, TypedLocalObjectReference } from "../kube-object";
import { KubeObject } from "../kube-object";
import type { Pod } from "./pod.api";
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import { object } from "../../utils";
import type { ResourceRequirements } from "./types/resource-requirements";
export class PersistentVolumeClaimApi extends KubeApi<PersistentVolumeClaim> {
constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) {
super({
...opts,
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
super(deps, {
...opts ?? {},
objectConstructor: PersistentVolumeClaim,
});
}

View File

@ -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,

View File

@ -6,7 +6,7 @@
import type { ClusterScopedMetadata, LabelSelector, ObjectReference, TypedLocalObjectReference } from "../kube-object";
import { KubeObject } from "../kube-object";
import { unitsToBytes } from "../../utils";
import type { DerivedKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { ResourceRequirements } from "./types/resource-requirements";
@ -103,8 +103,8 @@ export class PersistentVolume extends KubeObject<
}
export class PersistentVolumeApi extends KubeApi<PersistentVolume> {
constructor(opts: DerivedKubeApiOptions = {}) {
super({
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
super(deps, {
...opts,
objectConstructor: PersistentVolume,
});

View File

@ -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,

View File

@ -5,7 +5,7 @@
import type { LabelSelector, NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
export interface PodDisruptionBudgetSpec {
@ -52,8 +52,8 @@ export class PodDisruptionBudget extends KubeObject<
}
export class PodDisruptionBudgetApi extends KubeApi<PodDisruptionBudget> {
constructor(opts: DerivedKubeApiOptions = {}) {
super({
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
super(deps, {
objectConstructor: PodDisruptionBudget,
...opts,
});

View File

@ -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,

View File

@ -5,7 +5,7 @@
import type { KubeObjectMetadata, KubeObjectScope, NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { KubeJsonApiData } from "../kube-json-api";
@ -52,8 +52,8 @@ export class PodMetrics extends KubeObject<
}
export class PodMetricsApi extends KubeApi<PodMetrics, PodMetricsData> {
constructor(opts: DerivedKubeApiOptions = {}) {
super({
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
super(deps, {
...opts,
objectConstructor: PodMetrics,
});

View File

@ -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,

View File

@ -5,7 +5,7 @@
import type { ClusterScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
export interface PodSecurityPolicySpec {
@ -111,8 +111,8 @@ export class PodSecurityPolicy extends KubeObject<
}
export class PodSecurityPolicyApi extends KubeApi<PodSecurityPolicy> {
constructor(opts: DerivedKubeApiOptions = {}) {
super({
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
super(deps, {
...opts,
objectConstructor: PodSecurityPolicy,

View File

@ -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,

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions, ResourceDescriptor } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies, ResourceDescriptor } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { RequireExactlyOne } from "type-fest";
import type { KubeObjectMetadata, LocalObjectReference, Affinity, Toleration, NamespaceScopedMetadata } from "../kube-object";
@ -17,9 +17,9 @@ import type { Container } from "./types/container";
import type { ObjectFieldSelector, ResourceFieldSelector } from "./types";
export class PodApi extends KubeApi<Pod> {
constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) {
super({
...opts,
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
super(deps, {
...opts ?? {},
objectConstructor: Pod,
});
}

View File

@ -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,

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { DerivedKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { KubeJsonApiData } from "../kube-json-api";
import type { ClusterScopedMetadata, KubeObjectMetadata, KubeObjectScope } from "../kube-object";
@ -57,8 +57,8 @@ export class PriorityClass extends KubeObject<
}
export class PriorityClassApi extends KubeApi<PriorityClass, PriorityClassData> {
constructor(opts: DerivedKubeApiOptions = {}) {
super({
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
super(deps, {
objectConstructor: PriorityClass,
...opts,
});

View File

@ -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,

View File

@ -3,16 +3,16 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { KubeObjectStatus, LabelSelector, NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object";
import type { PodTemplateSpec } from "./types/pod-template-spec";
export class ReplicaSetApi extends KubeApi<ReplicaSet> {
constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) {
super({
...opts,
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
super(deps, {
...opts ?? {},
objectConstructor: ReplicaSet,
});
}

View File

@ -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,

View File

@ -5,7 +5,7 @@
import type { NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
export type IResourceQuotaValues = Partial<Record<string, string>> & {
@ -65,8 +65,8 @@ export class ResourceQuota extends KubeObject<
}
export class ResourceQuotaApi extends KubeApi<ResourceQuota> {
constructor(opts: DerivedKubeApiOptions = {}) {
super({
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
super(deps, {
objectConstructor: ResourceQuota,
...opts,
});

View File

@ -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,

View File

@ -5,7 +5,7 @@
import type { KubeObjectMetadata, KubeObjectScope, NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { KubeJsonApiData } from "../kube-json-api";
import type { RoleRef } from "./types/role-ref";
@ -44,8 +44,8 @@ export class RoleBinding extends KubeObject<
}
export class RoleBindingApi extends KubeApi<RoleBinding, RoleBindingData> {
constructor(opts: DerivedKubeApiOptions = {}) {
super({
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
super(deps, {
...opts,
objectConstructor: RoleBinding,
});

View File

@ -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,

View File

@ -5,7 +5,7 @@
import type { KubeObjectMetadata, KubeObjectScope, NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { KubeJsonApiData } from "../kube-json-api";
import type { PolicyRule } from "./types/policy-rule";
@ -35,8 +35,8 @@ export class Role extends KubeObject<
}
export class RoleApi extends KubeApi<Role, RoleData> {
constructor(opts: DerivedKubeApiOptions = {}) {
super({
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
super(deps, {
...opts,
objectConstructor: Role,
});

View File

@ -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,

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { DerivedKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { KubeJsonApiData } from "../kube-json-api";
import type { ClusterScopedMetadata, KubeObjectMetadata, KubeObjectScope, Toleration } from "../kube-object";
@ -63,8 +63,8 @@ export class RuntimeClass extends KubeObject<
}
export class RuntimeClassApi extends KubeApi<RuntimeClass, RuntimeClassData> {
constructor(opts: DerivedKubeApiOptions = {}) {
super({
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
super(deps, {
objectConstructor: RuntimeClass,
...opts,
});

View File

@ -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,

View File

@ -7,7 +7,7 @@ import type { KubeObjectMetadata, KubeObjectScope, NamespaceScopedMetadata } fro
import { KubeObject } from "../kube-object";
import type { KubeJsonApiData } from "../kube-json-api";
import { autoBind } from "../../utils";
import type { DerivedKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
export enum SecretType {
@ -72,8 +72,8 @@ export class Secret extends KubeObject<
}
export class SecretApi extends KubeApi<Secret, SecretData> {
constructor(options: DerivedKubeApiOptions = {}) {
super({
constructor(deps: KubeApiDependencies, options: DerivedKubeApiOptions = {}) {
super(deps, {
...options,
objectConstructor: Secret,
});

View File

@ -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,

View File

@ -4,13 +4,13 @@
*/
import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
export class SelfSubjectRulesReviewApi extends KubeApi<SelfSubjectRulesReview> {
constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) {
super({
...opts,
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
super(deps, {
...opts ?? {},
objectConstructor: SelfSubjectRulesReview,
});
}

View File

@ -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,

View File

@ -5,7 +5,7 @@
import type { KubeObjectMetadata, KubeObjectScope, LocalObjectReference, NamespaceScopedMetadata, ObjectReference } from "../kube-object";
import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { KubeJsonApiData } from "../kube-json-api";
@ -50,8 +50,8 @@ export class ServiceAccount extends KubeObject<
}
export class ServiceAccountApi extends KubeApi<ServiceAccount, ServiceAccountData> {
constructor(opts: DerivedKubeApiOptions = {}) {
super({
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
super(deps, {
...opts,
objectConstructor: ServiceAccount,
});

View File

@ -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,

View File

@ -5,7 +5,7 @@
import type { NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
export interface ServicePort {
@ -129,8 +129,8 @@ export class Service extends KubeObject<
}
export class ServiceApi extends KubeApi<Service> {
constructor(opts: DerivedKubeApiOptions = {}) {
super({
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
super(deps, {
...opts,
objectConstructor: Service,
});

View File

@ -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,

View File

@ -5,7 +5,7 @@
import moment from "moment";
import type { DerivedKubeApiOptions, IgnoredKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { LabelSelector, NamespaceScopedMetadata } from "../kube-object";
import { KubeObject } from "../kube-object";
@ -13,9 +13,9 @@ import type { PodTemplateSpec } from "./types/pod-template-spec";
import type { PersistentVolumeClaimTemplateSpec } from "./types/persistent-volume-claim-template-spec";
export class StatefulSetApi extends KubeApi<StatefulSet> {
constructor(opts: DerivedKubeApiOptions & IgnoredKubeApiOptions = {}) {
super({
...opts,
constructor(deps: KubeApiDependencies, opts?: DerivedKubeApiOptions) {
super(deps, {
...opts ?? {},
objectConstructor: StatefulSet,
});
}

View File

@ -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,

View File

@ -6,7 +6,7 @@
import { autoBind } from "../../utils";
import type { ClusterScopedMetadata, KubeObjectMetadata, KubeObjectScope } from "../kube-object";
import { KubeObject } from "../kube-object";
import type { DerivedKubeApiOptions } from "../kube-api";
import type { DerivedKubeApiOptions, KubeApiDependencies } from "../kube-api";
import { KubeApi } from "../kube-api";
import type { KubeJsonApiData } from "../kube-json-api";
@ -86,8 +86,8 @@ export class StorageClass extends KubeObject<
}
export class StorageClassApi extends KubeApi<StorageClass, StorageClassData> {
constructor(opts: DerivedKubeApiOptions = {}) {
super({
constructor(deps: KubeApiDependencies, opts: DerivedKubeApiOptions = {}) {
super(deps, {
...opts,
objectConstructor: StorageClass,
});

View File

@ -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<any, any>): 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<Object, Data>) {
constructor(protected readonly dependencies: KubeApiDependencies, opts: KubeApiOptions<Object, Data>) {
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() {

View File

@ -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;

View File

@ -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();

View File

@ -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<boolean>;
beforeEach(() => {
useFakeTime("2015-10-21T07:28:00Z");
testUsingFakeTime("2015-10-21T07:28:00Z");
someComputed = computed(() => {
const currentTimestamp = reactiveNow();

View File

@ -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<Object> = KubeJsonApiDataFor<Object>,
>(opts: KubeApiOptions<Object, Data>) {
return new InternalKubeApi(getKubeApiDeps(), opts);
}
export const KubeApi = KubeApiCstr as unknown as new<
Object extends KubeObject = KubeObject,
Data extends KubeJsonApiDataFor<Object> = KubeJsonApiDataFor<Object>,
>(opts: KubeApiOptions<Object, Data>) => InternalKubeApi<Object, Data>;
export const createResourceStack = asLegacyGlobalFunctionForExtensionApi(createResourceStackInjectable);
@ -82,7 +105,7 @@ export {
export abstract class KubeObjectStore<
K extends KubeObject = KubeObject,
A extends KubeApi<K, D> = KubeApi<K, KubeJsonApiDataFor<K>>,
A extends InternalKubeApi<K, D> = InternalKubeApi<K, KubeJsonApiDataFor<K>>,
D extends KubeJsonApiDataFor<K> = KubeApiDataFrom<K, A>,
> extends InternalKubeObjectStore<K, A, D> {
/**
@ -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,

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -3,6 +3,44 @@
exports[`opening dock tab for installing helm chart given application is started, when navigating to helm charts renders 1`] = `
<body>
<div>
<div
class="Animate slide-right Drawer KubeObjectDetails flex column right enter leave"
style="--size: 725px; --enter-duration: 100ms; --leave-duration: 100ms;"
>
<div
class="drawer-wrapper flex column"
>
<div
class="drawer-title flex align-center"
>
<div
class="drawer-title-text flex gaps align-center"
>
</div>
<i
class="Icon material interactive focusable"
tabindex="0"
>
<span
class="icon"
data-icon-name="close"
>
close
</span>
</i>
<div>
Close
</div>
</div>
<div
class="drawer-content flex column box grow"
/>
</div>
<div
class="ResizingAnchor horizontal leading"
/>
</div>
<div
class="Notifications flex column align-flex-end"
/>
@ -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`] = `
<body>
<div>
<div
class="Animate slide-right Drawer KubeObjectDetails flex column right enter leave"
style="--size: 725px; --enter-duration: 100ms; --leave-duration: 100ms;"
>
<div
class="drawer-wrapper flex column"
>
<div
class="drawer-title flex align-center"
>
<div
class="drawer-title-text flex gaps align-center"
>
</div>
<i
class="Icon material interactive focusable"
tabindex="0"
>
<span
class="icon"
data-icon-name="close"
>
close
</span>
</i>
<div>
Close
</div>
</div>
<div
class="drawer-content flex column box grow"
/>
</div>
<div
class="ResizingAnchor horizontal leading"
/>
</div>
<div
class="Notifications flex column align-flex-end"
/>
@ -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`] = `
<body>
<div>
<div
class="Animate slide-right Drawer KubeObjectDetails flex column right enter leave"
style="--size: 725px; --enter-duration: 100ms; --leave-duration: 100ms;"
>
<div
class="drawer-wrapper flex column"
>
<div
class="drawer-title flex align-center"
>
<div
class="drawer-title-text flex gaps align-center"
>
</div>
<i
class="Icon material interactive focusable"
tabindex="0"
>
<span
class="icon"
data-icon-name="close"
>
close
</span>
</i>
<div>
Close
</div>
</div>
<div
class="drawer-content flex column box grow"
/>
</div>
<div
class="ResizingAnchor horizontal leading"
/>
</div>
<div
class="Notifications flex column align-flex-end"
/>
@ -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`] = `
<body>
<div>
<div
class="Animate slide-right Drawer KubeObjectDetails flex column right enter leave"
style="--size: 725px; --enter-duration: 100ms; --leave-duration: 100ms;"
>
<div
class="drawer-wrapper flex column"
>
<div
class="drawer-title flex align-center"
>
<div
class="drawer-title-text flex gaps align-center"
>
</div>
<i
class="Icon material interactive focusable"
tabindex="0"
>
<span
class="icon"
data-icon-name="close"
>
close
</span>
</i>
<div>
Close
</div>
</div>
<div
class="drawer-content flex column box grow"
/>
</div>
<div
class="ResizingAnchor horizontal leading"
/>
</div>
<div
class="Notifications flex column align-flex-end"
/>
@ -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`] = `
<body>
<div>
<div
class="Animate slide-right Drawer KubeObjectDetails flex column right enter leave"
style="--size: 725px; --enter-duration: 100ms; --leave-duration: 100ms;"
>
<div
class="drawer-wrapper flex column"
>
<div
class="drawer-title flex align-center"
>
<div
class="drawer-title-text flex gaps align-center"
>
</div>
<i
class="Icon material interactive focusable"
tabindex="0"
>
<span
class="icon"
data-icon-name="close"
>
close
</span>
</i>
<div>
Close
</div>
</div>
<div
class="drawer-content flex column box grow"
/>
</div>
<div
class="ResizingAnchor horizontal leading"
/>
</div>
<div
class="Notifications flex column align-flex-end"
/>
@ -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`] = `
<body>
<div>
<div
class="Animate slide-right Drawer KubeObjectDetails flex column right enter leave"
style="--size: 725px; --enter-duration: 100ms; --leave-duration: 100ms;"
>
<div
class="drawer-wrapper flex column"
>
<div
class="drawer-title flex align-center"
>
<div
class="drawer-title-text flex gaps align-center"
>
</div>
<i
class="Icon material interactive focusable"
tabindex="0"
>
<span
class="icon"
data-icon-name="close"
>
close
</span>
</i>
<div>
Close
</div>
</div>
<div
class="drawer-content flex column box grow"
/>
</div>
<div
class="ResizingAnchor horizontal leading"
/>
</div>
<div
class="Notifications flex column align-flex-end"
/>
@ -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`] = `
<body>
<div>
<div
class="Animate slide-right Drawer KubeObjectDetails flex column right enter leave"
style="--size: 725px; --enter-duration: 100ms; --leave-duration: 100ms;"
>
<div
class="drawer-wrapper flex column"
>
<div
class="drawer-title flex align-center"
>
<div
class="drawer-title-text flex gaps align-center"
>
</div>
<i
class="Icon material interactive focusable"
tabindex="0"
>
<span
class="icon"
data-icon-name="close"
>
close
</span>
</i>
<div>
Close
</div>
</div>
<div
class="drawer-content flex column box grow"
/>
</div>
<div
class="ResizingAnchor horizontal leading"
/>
</div>
<div
class="Notifications flex column align-flex-end"
/>
@ -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`] = `
<body>
<div>
<div
class="Animate slide-right Drawer KubeObjectDetails flex column right enter leave"
style="--size: 725px; --enter-duration: 100ms; --leave-duration: 100ms;"
>
<div
class="drawer-wrapper flex column"
>
<div
class="drawer-title flex align-center"
>
<div
class="drawer-title-text flex gaps align-center"
>
</div>
<i
class="Icon material interactive focusable"
tabindex="0"
>
<span
class="icon"
data-icon-name="close"
>
close
</span>
</i>
<div>
Close
</div>
</div>
<div
class="drawer-content flex column box grow"
/>
</div>
<div
class="ResizingAnchor horizontal leading"
/>
</div>
<div
class="Notifications flex column align-flex-end"
/>
@ -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`] = `
<body>
<div>
<div
class="Animate slide-right Drawer KubeObjectDetails flex column right enter leave"
style="--size: 725px; --enter-duration: 100ms; --leave-duration: 100ms;"
>
<div
class="drawer-wrapper flex column"
>
<div
class="drawer-title flex align-center"
>
<div
class="drawer-title-text flex gaps align-center"
>
</div>
<i
class="Icon material interactive focusable"
tabindex="0"
>
<span
class="icon"
data-icon-name="close"
>
close
</span>
</i>
<div>
Close
</div>
</div>
<div
class="drawer-content flex column box grow"
/>
</div>
<div
class="ResizingAnchor horizontal leading"
/>
</div>
<div
class="Notifications flex column align-flex-end"
/>

View File

@ -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");

View File

@ -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();

View File

@ -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();

Some files were not shown because too many files have changed in this diff Show More