From dc39dc9c62e85f99695b0aeeb93760f8ff073a1d Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Fri, 24 Feb 2023 07:44:35 -0800 Subject: [PATCH] Allow extensions to opt-out of KubeApi auto registering (#7217) Signed-off-by: Sebastian Malton --- .../core/src/extensions/common-api/k8s-api.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/core/src/extensions/common-api/k8s-api.ts b/packages/core/src/extensions/common-api/k8s-api.ts index 0b9a05353f..20e687ff6d 100644 --- a/packages/core/src/extensions/common-api/k8s-api.ts +++ b/packages/core/src/extensions/common-api/k8s-api.ts @@ -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 = KubeJsonApiDataFor, ->(opts: KubeApiOptions) { +>({ autoRegister = true, ...opts }: KubeApiOptions & ExternalKubeApiOptions) { const api = new InternalKubeApi(getKubeApiDeps(), opts); const di = getLegacyGlobalDiForExtensionApi(); const storesAndApisCanBeCreated = di.inject(storesAndApisCanBeCreatedInjectionToken); - if (storesAndApisCanBeCreated) { + if (storesAndApisCanBeCreated && autoRegister) { apiManager.registerApi(api); } @@ -72,7 +84,7 @@ export type KubeApi< export const KubeApi = KubeApiCstr as unknown as new< Object extends KubeObject = KubeObject, Data extends KubeJsonApiDataFor = KubeJsonApiDataFor, ->(opts: KubeApiOptions) => InternalKubeApi; +>(opts: KubeApiOptions & ExternalKubeApiOptions) => InternalKubeApi; /** * @deprecated Switch to using `Common.createResourceStack` instead