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

Add option to disable automatic apiManager registration for KubeApi

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
Panu Horsmalahti 2021-10-20 16:03:37 +03:00
parent 46653386b9
commit a0c6475472

View File

@ -56,6 +56,9 @@ export interface IKubeApiOptions<T extends KubeObject> {
isNamespaced?: boolean; isNamespaced?: boolean;
kind?: string; kind?: string;
checkPreferredVersion?: boolean; checkPreferredVersion?: boolean;
// If true, the KubeApi won't be registered to apiManager
apiManagerDisabled?: boolean;
} }
export interface IKubeApiQueryParams { export interface IKubeApiQueryParams {
@ -94,6 +97,9 @@ export interface ILocalKubeApiConfig {
metadata: { metadata: {
uid: string; uid: string;
} }
// If true, the KubeApi won't be registered to apiManager
apiManagerDisabled?: boolean;
} }
/** /**
@ -106,12 +112,15 @@ export interface IRemoteKubeApiConfig {
server: string; server: string;
caData?: string; caData?: string;
skipTLSVerify?: boolean; skipTLSVerify?: boolean;
} };
user: { user: {
token?: string; token?: string;
clientCertificateData?: string; clientCertificateData?: string;
clientKeyData?: string; clientKeyData?: string;
} };
// If true, the KubeApi won't be registered to apiManager
apiManagerDisabled?: boolean;
} }
export function forCluster<T extends KubeObject>(cluster: ILocalKubeApiConfig, kubeClass: KubeObjectConstructor<T>): KubeApi<T> { export function forCluster<T extends KubeObject>(cluster: ILocalKubeApiConfig, kubeClass: KubeObjectConstructor<T>): KubeApi<T> {
@ -128,7 +137,8 @@ export function forCluster<T extends KubeObject>(cluster: ILocalKubeApiConfig, k
return new KubeApi({ return new KubeApi({
objectConstructor: kubeClass, objectConstructor: kubeClass,
request request,
apiManagerDisabled: cluster.apiManagerDisabled
}); });
} }
@ -166,12 +176,13 @@ export function forRemoteCluster<T extends KubeObject>(config: IRemoteKubeApiCon
const request = new KubeJsonApi({ const request = new KubeJsonApi({
serverAddress: config.cluster.server, serverAddress: config.cluster.server,
apiBase: "", apiBase: "",
debug: isDevelopment, debug: isDevelopment
}, reqInit); }, reqInit);
return new KubeApi({ return new KubeApi({
objectConstructor: kubeClass, objectConstructor: kubeClass,
request request,
apiManagerDisabled: config.apiManagerDisabled
}); });
} }
@ -213,6 +224,11 @@ export class KubeApi<T extends KubeObject> {
protected watchDisposer: () => void; protected watchDisposer: () => void;
private watchId = 1; 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<T>) { constructor(protected options: IKubeApiOptions<T>) {
const { const {
objectConstructor, objectConstructor,
@ -237,7 +253,10 @@ export class KubeApi<T extends KubeObject> {
this.objectConstructor = objectConstructor; this.objectConstructor = objectConstructor;
this.parseResponse = this.parseResponse.bind(this); this.parseResponse = this.parseResponse.bind(this);
apiManager.registerApi(apiBase, this);
if (!options.apiManagerDisabled) {
apiManager.registerApi(apiBase, this);
}
} }
get apiVersionWithGroup() { get apiVersionWithGroup() {