diff --git a/src/common/k8s-api/kube-api.ts b/src/common/k8s-api/kube-api.ts index 54b0e5726f..ebaf2091fd 100644 --- a/src/common/k8s-api/kube-api.ts +++ b/src/common/k8s-api/kube-api.ts @@ -56,6 +56,9 @@ export interface IKubeApiOptions { isNamespaced?: boolean; kind?: string; checkPreferredVersion?: boolean; + + // If true, the KubeApi won't be registered to apiManager + apiManagerDisabled?: boolean; } export interface IKubeApiQueryParams { @@ -94,6 +97,9 @@ export interface ILocalKubeApiConfig { metadata: { uid: string; } + + // If true, the KubeApi won't be registered to apiManager + apiManagerDisabled?: boolean; } /** @@ -106,12 +112,15 @@ export interface IRemoteKubeApiConfig { server: string; caData?: string; skipTLSVerify?: boolean; - } + }; user: { token?: string; clientCertificateData?: string; clientKeyData?: string; - } + }; + + // If true, the KubeApi won't be registered to apiManager + apiManagerDisabled?: boolean; } export function forCluster(cluster: ILocalKubeApiConfig, kubeClass: KubeObjectConstructor): KubeApi { @@ -128,7 +137,8 @@ export function forCluster(cluster: ILocalKubeApiConfig, k return new KubeApi({ objectConstructor: kubeClass, - request + request, + apiManagerDisabled: cluster.apiManagerDisabled }); } @@ -166,12 +176,13 @@ export function forRemoteCluster(config: IRemoteKubeApiCon const request = new KubeJsonApi({ serverAddress: config.cluster.server, apiBase: "", - debug: isDevelopment, + debug: isDevelopment }, reqInit); return new KubeApi({ objectConstructor: kubeClass, - request + request, + apiManagerDisabled: config.apiManagerDisabled }); } @@ -213,6 +224,11 @@ export class KubeApi { protected watchDisposer: () => void; private watchId = 1; + /** + * By default registers the api to apiManager. This can be disabled with options. + * If registered, the api should be unregistered from the apiManager afterwards. + * @param options + */ constructor(protected options: IKubeApiOptions) { const { objectConstructor, @@ -237,7 +253,10 @@ export class KubeApi { this.objectConstructor = objectConstructor; this.parseResponse = this.parseResponse.bind(this); - apiManager.registerApi(apiBase, this); + + if (!options.apiManagerDisabled) { + apiManager.registerApi(apiBase, this); + } } get apiVersionWithGroup() {