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:
parent
a4986ee016
commit
05f5176419
@ -675,6 +675,8 @@ export class Cluster implements ClusterModel, ClusterState {
|
||||
};
|
||||
}
|
||||
|
||||
protected getAllowedNamespacesErrorCount = 0;
|
||||
|
||||
protected async getAllowedNamespaces() {
|
||||
if (this.accessibleNamespaces.length) {
|
||||
return this.accessibleNamespaces;
|
||||
@ -683,17 +685,28 @@ export class Cluster implements ClusterModel, ClusterState {
|
||||
const api = (await this.getProxyKubeconfig()).makeApiClient(CoreV1Api);
|
||||
|
||||
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) {
|
||||
const ctx = (await this.getProxyKubeconfig()).getContextObject(this.contextName);
|
||||
const namespaceList = [ctx.namespace].filter(Boolean);
|
||||
|
||||
if (namespaceList.length === 0 && error instanceof HttpError && error.statusCode === 403) {
|
||||
logger.info("[CLUSTER]: listing namespaces is forbidden, broadcasting", { clusterId: this.id });
|
||||
this.getAllowedNamespacesErrorCount += 1;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user