mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
- requestNamespaceListPermissions is infallable so no need to have the extra try/catch - Refactor isMetricHidden method away from Cluster - Refactor shouldShowResource out of Cluster - Refactor isInLocalKubeconfig out of Cluster - Remove depecrated and unused workspace from Cluster - Refactor out kubectl as a dependency of Cluster - Remove from cluster getter used only once - Split out ClusterConnection from Cluster - Also split out KubeAuthProxyServer from ContextHandler - Rename ContextHandler to PrometheusHandler - Cleanup onNetworkOffline/Online impls within ClusterManager - Remove annotations from ClusterConnection - Remove mobx annotations from Cluster - Rename loadConfigFromFileInjectable - Remove all uses of dead createClusterInjectionToken - Fix type errors related to broadcastConnectionUpdate Signed-off-by: Sebastian Malton <sebastian@malton.name>
83 lines
3.1 KiB
TypeScript
83 lines
3.1 KiB
TypeScript
/**
|
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
*/
|
|
|
|
import { getInjectable } from "@ogre-tools/injectable";
|
|
import loggerInjectable from "../../common/logger.injectable";
|
|
import type { KubeApiResource } from "../../common/rbac";
|
|
import type { Cluster } from "../../common/cluster/cluster";
|
|
import { requestApiVersionsInjectionToken } from "./request-api-versions";
|
|
import { withConcurrencyLimit } from "../../common/utils/with-concurrency-limit";
|
|
import requestKubeApiResourcesForInjectable from "./request-kube-api-resources-for.injectable";
|
|
import type { AsyncResult } from "../../common/utils/async-result";
|
|
import { backoffCaller } from "../../common/utils/backoff-caller";
|
|
import broadcastConnectionUpdateInjectable from "./broadcast-connection-update.injectable";
|
|
|
|
export type RequestApiResources = (cluster: Cluster) => Promise<AsyncResult<KubeApiResource[], Error>>;
|
|
|
|
export interface KubeResourceListGroup {
|
|
group: string;
|
|
path: string;
|
|
}
|
|
|
|
const requestApiResourcesInjectable = getInjectable({
|
|
id: "request-api-resources",
|
|
instantiate: (di): RequestApiResources => {
|
|
const logger = di.inject(loggerInjectable);
|
|
const apiVersionRequesters = di.injectMany(requestApiVersionsInjectionToken);
|
|
const requestKubeApiResourcesFor = di.inject(requestKubeApiResourcesForInjectable);
|
|
|
|
return async (...args) => {
|
|
const [cluster] = args;
|
|
const broadcastConnectionUpdate = di.inject(broadcastConnectionUpdateInjectable, cluster);
|
|
const requestKubeApiResources = withConcurrencyLimit(5)(requestKubeApiResourcesFor(cluster));
|
|
|
|
const groupLists: KubeResourceListGroup[] = [];
|
|
|
|
for (const apiVersionRequester of apiVersionRequesters) {
|
|
const result = await backoffCaller(() => apiVersionRequester(cluster), {
|
|
onIntermediateError: (error, attempt) => {
|
|
broadcastConnectionUpdate({
|
|
message: `Failed to list kube API resource kinds, attempt ${attempt}: ${error}`,
|
|
level: "warning",
|
|
});
|
|
logger.warn(`[LIST-API-RESOURCES]: failed to list kube api resources: ${error}`, { attempt, clusterId: cluster.id });
|
|
},
|
|
});
|
|
|
|
if (!result.callWasSuccessful) {
|
|
return result;
|
|
}
|
|
|
|
groupLists.push(...result.response);
|
|
}
|
|
|
|
const apiResourceRequests = groupLists.map(async listGroup => (
|
|
Object.assign(await requestKubeApiResources(listGroup), { listGroup })
|
|
));
|
|
const results = await Promise.all(apiResourceRequests);
|
|
const resources: KubeApiResource[] = [];
|
|
|
|
for (const result of results) {
|
|
if (!result.callWasSuccessful) {
|
|
broadcastConnectionUpdate({
|
|
message: `Kube APIs under "${result.listGroup.path}" may not be displayed`,
|
|
level: "warning",
|
|
});
|
|
continue;
|
|
}
|
|
|
|
resources.push(...result.response);
|
|
}
|
|
|
|
return {
|
|
callWasSuccessful: true,
|
|
response: resources,
|
|
};
|
|
};
|
|
},
|
|
});
|
|
|
|
export default requestApiResourcesInjectable;
|