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

Allow extensions to opt-out of KubeApi auto registering #7217

Merged
merged 1 commit into from
Feb 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 15 additions & 3 deletions packages/core/src/extensions/common-api/k8s-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,29 @@ const getKubeApiDeps = (): KubeApiDependencies => {
};
};

export interface ExternalKubeApiOptions {
/**
* If `true` then on creation of the `KubeApi`instance a call to `apiManager.registerApi` will be
* made. This is `true` by default to maintain backwards compatability.
*
* Setting this to `false` might make `KubeObject`'s details drawer stop working.
*
* @default true
*/
autoRegister?: boolean;
}

// NOTE: this is done to preserve `instanceOf` behaviour
function KubeApiCstr<
Object extends KubeObject = KubeObject,
Data extends KubeJsonApiDataFor<Object> = KubeJsonApiDataFor<Object>,
>(opts: KubeApiOptions<Object, Data>) {
>({ autoRegister = true, ...opts }: KubeApiOptions<Object, Data> & ExternalKubeApiOptions) {
const api = new InternalKubeApi(getKubeApiDeps(), opts);

const di = getLegacyGlobalDiForExtensionApi();
const storesAndApisCanBeCreated = di.inject(storesAndApisCanBeCreatedInjectionToken);

if (storesAndApisCanBeCreated) {
if (storesAndApisCanBeCreated && autoRegister) {
apiManager.registerApi(api);
}

Expand All @@ -72,7 +84,7 @@ export type KubeApi<
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>;
>(opts: KubeApiOptions<Object, Data> & ExternalKubeApiOptions) => InternalKubeApi<Object, Data>;

/**
* @deprecated Switch to using `Common.createResourceStack` instead
Expand Down