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

fix: allow to select kube-api objects with label & field selectors (#1327)

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2020-11-11 13:42:36 +02:00 committed by GitHub
parent bcbbe140b9
commit c67dad54e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -51,6 +51,6 @@ export class VersionedKubeApi<T extends KubeObject = any> extends KubeApi<T> {
namespace: isNamespaced ? namespace : undefined,
name: name,
});
return resourcePath + (query ? `?` + stringify(query) : "");
return resourcePath + (query ? `?` + stringify(this.normalizeQuery(query)) : "");
}
}

View File

@ -24,6 +24,8 @@ export interface IKubeApiQueryParams {
timeoutSeconds?: number;
limit?: number; // doesn't work with ?watch
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 IKubeApiCluster {
@ -114,7 +116,17 @@ export class KubeApi<T extends KubeObject = any> {
namespace: this.isNamespaced ? namespace : undefined,
name: name,
});
return resourcePath + (query ? `?` + stringify(query) : "");
return resourcePath + (query ? `?` + stringify(this.normalizeQuery(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 {