Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix KubeJsonApi.forCluster missing from extension API and remove class constructors that require dependencies #6947

Merged
merged 1 commit into from
Jan 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/extensions/common-api/k8s-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import { getLegacyGlobalDiForExtensionApi } from "../as-legacy-globals-for-exten
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";
import { storesAndApisCanBeCreatedInjectionToken } from "../../common/k8s-api/stores-apis-can-be-created.token";
import type { JsonApiConfig } from "../../common/k8s-api/json-api";
import type { KubeJsonApi as InternalKubeJsonApi } from "../../common/k8s-api/kube-json-api";
import createKubeJsonApiInjectable from "../../common/k8s-api/create-kube-json-api.injectable";
import type { RequestInit } from "node-fetch";

export const apiManager = asLegacyGlobalForExtensionApi(apiManagerInjectable);
export const forCluster = asLegacyGlobalFunctionForExtensionApi(createKubeApiForClusterInjectable);
Expand Down Expand Up @@ -107,11 +111,24 @@ export {
type KubeStatusData,
} from "../../common/k8s-api/kube-object";

export {
KubeJsonApi,
type KubeJsonApiData,
export type {
KubeJsonApiData,
} from "../../common/k8s-api/kube-json-api";

function KubeJsonApiCstr(config: JsonApiConfig, reqInit?: RequestInit) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Cstr stand for Constructor? Maybe avoid abbreviation for clarity?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that function isn't exposed to the extension API at all. Just an an internal implementation to this file.

const di = getLegacyGlobalDiForExtensionApi();
const createKubeJsonApi = di.inject(createKubeJsonApiInjectable);

return createKubeJsonApi(config, reqInit);
}

export const KubeJsonApi = Object.assign(
KubeJsonApiCstr as unknown as new (config: JsonApiConfig, reqInit?: RequestInit) => InternalKubeJsonApi,
{
forCluster,
},
);

export abstract class KubeObjectStore<
K extends KubeObject = KubeObject,
A extends InternalKubeApi<K, D> = InternalKubeApi<K, KubeJsonApiDataFor<K>>,
Expand Down