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

refactoring, removed versioned kube api

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2020-11-11 13:35:52 +02:00
commit 2843cccdb2

View File

@ -25,11 +25,9 @@ export interface IKubeApiQueryParams {
timeoutSeconds?: number; timeoutSeconds?: number;
limit?: number; // doesn't work with ?watch limit?: number; // doesn't work with ?watch
continue?: string; // might be used with ?limit from second request continue?: string; // might be used with ?limit from second request
labelSelector?: string | string[]; // restrict list of objects by their labels, e.g. labelSelector: ["label=value"]
fieldSelector?: string | string[]; // restrict list of objects by their fields, e.g. fieldSelector: "field=name"
} }
export interface IKubeApiPreferredVersion { export interface IKubePreferredVersion {
preferredVersion?: { preferredVersion?: {
version: string; version: string;
} }
@ -112,7 +110,7 @@ export class KubeApi<T extends KubeObject = any> {
if (!this.options.checkPreferredVersion || this.apiVersionPreferred === undefined) { if (!this.options.checkPreferredVersion || this.apiVersionPreferred === undefined) {
return; return;
} }
const res = await this.request.get<IKubeApiPreferredVersion>(`${this.apiPrefix}/${this.apiGroup}`); const res = await this.request.get<IKubePreferredVersion>(`${this.apiPrefix}/${this.apiGroup}`);
Object.defineProperty(this, "apiVersionPreferred", { Object.defineProperty(this, "apiVersionPreferred", {
value: res?.preferredVersion?.version ?? null, value: res?.preferredVersion?.version ?? null,
}); });
@ -143,17 +141,7 @@ export class KubeApi<T extends KubeObject = any> {
namespace: this.isNamespaced ? namespace : undefined, namespace: this.isNamespaced ? namespace : undefined,
name: name, name: name,
}); });
return resourcePath + (query ? `?` + stringify(this.normalizeQuery(query)) : ""); return resourcePath + (query ? `?` + stringify(query) : "");
}
protected normalizeQuery(query: Partial<IKubeApiQueryParams> = {}) {
if (query.labelSelector) {
query.labelSelector = [query.labelSelector].flat().join(",")
}
if (query.fieldSelector) {
query.fieldSelector = [query.fieldSelector].flat().join(",")
}
return query;
} }
protected parseResponse(data: KubeJsonApiData | KubeJsonApiData[] | KubeJsonApiDataList, namespace?: string): any { protected parseResponse(data: KubeJsonApiData | KubeJsonApiData[] | KubeJsonApiDataList, namespace?: string): any {