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

Broadcast failure to list namespaces less frequently (#2501)

- Only of three successive (non-overlapping) list failures

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-04-12 08:29:36 -04:00
parent a4986ee016
commit 05f5176419

View File

@ -675,6 +675,8 @@ export class Cluster implements ClusterModel, ClusterState {
}; };
} }
protected getAllowedNamespacesErrorCount = 0;
protected async getAllowedNamespaces() { protected async getAllowedNamespaces() {
if (this.accessibleNamespaces.length) { if (this.accessibleNamespaces.length) {
return this.accessibleNamespaces; return this.accessibleNamespaces;
@ -683,16 +685,27 @@ export class Cluster implements ClusterModel, ClusterState {
const api = (await this.getProxyKubeconfig()).makeApiClient(CoreV1Api); const api = (await this.getProxyKubeconfig()).makeApiClient(CoreV1Api);
try { try {
const namespaceList = await api.listNamespace(); const { body: { items }} = await api.listNamespace();
const namespaces = items.map(ns => ns.metadata.name);
return namespaceList.body.items.map(ns => ns.metadata.name); this.getAllowedNamespacesErrorCount = 0; // reset on success
return namespaces;
} catch (error) { } catch (error) {
const ctx = (await this.getProxyKubeconfig()).getContextObject(this.contextName); const ctx = (await this.getProxyKubeconfig()).getContextObject(this.contextName);
const namespaceList = [ctx.namespace].filter(Boolean); const namespaceList = [ctx.namespace].filter(Boolean);
if (namespaceList.length === 0 && error instanceof HttpError && error.statusCode === 403) { if (namespaceList.length === 0 && error instanceof HttpError && error.statusCode === 403) {
logger.info("[CLUSTER]: listing namespaces is forbidden, broadcasting", { clusterId: this.id }); this.getAllowedNamespacesErrorCount += 1;
broadcastMessage(ClusterListNamespaceForbiddenChannel, this.id);
if (this.getAllowedNamespacesErrorCount > 3) {
// reset on send
this.getAllowedNamespacesErrorCount = 0;
// then broadcast, make sure it is 3 successive attempts
logger.info("[CLUSTER]: listing namespaces is forbidden, broadcasting", { clusterId: this.id, error });
broadcastMessage(ClusterListNamespaceForbiddenChannel, this.id);
}
} }
return namespaceList; return namespaceList;