1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-21 22:39:41 +02:00

feat(kubernetes/resource-usage): k8s resource usage for cluster, node and namespace EE-3 EE-1112 (#5301)

* backported resource usage functionality from EE

* utilising view bound endpoint object instead of depracated EndpointProvider

* refactor flatmap

* addressed merge conflict issues
This commit is contained in:
zees-dev 2021-07-28 14:26:03 +12:00 committed by GitHub
parent cee7ac26e9
commit ce31de5e9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 188 additions and 30 deletions

View file

@ -13,10 +13,10 @@ class KubernetesClusterController {
Notifications,
LocalStorage,
KubernetesNodeService,
KubernetesMetricsService,
KubernetesApplicationService,
KubernetesComponentStatusService,
KubernetesEndpointService,
EndpointProvider
KubernetesEndpointService
) {
this.$async = $async;
this.$state = $state;
@ -24,10 +24,10 @@ class KubernetesClusterController {
this.Notifications = Notifications;
this.LocalStorage = LocalStorage;
this.KubernetesNodeService = KubernetesNodeService;
this.KubernetesMetricsService = KubernetesMetricsService;
this.KubernetesApplicationService = KubernetesApplicationService;
this.KubernetesComponentStatusService = KubernetesComponentStatusService;
this.KubernetesEndpointService = KubernetesEndpointService;
this.EndpointProvider = EndpointProvider;
this.onInit = this.onInit.bind(this);
this.getNodes = this.getNodes.bind(this);
@ -106,6 +106,10 @@ class KubernetesClusterController {
new KubernetesResourceReservation()
);
this.resourceReservation.Memory = KubernetesResourceReservationHelper.megaBytesValue(this.resourceReservation.Memory);
if (this.isAdmin) {
await this.getResourceUsage(this.endpoint.Id);
}
} catch (err) {
this.Notifications.error('Failure', 'Unable to retrieve applications', err);
} finally {
@ -117,14 +121,31 @@ class KubernetesClusterController {
return this.$async(this.getApplicationsAsync);
}
async getResourceUsage(endpointId) {
try {
const nodeMetrics = await this.KubernetesMetricsService.getNodes(endpointId);
const resourceUsageList = nodeMetrics.items.map((i) => i.usage);
const clusterResourceUsage = resourceUsageList.reduce((total, u) => {
total.CPU += KubernetesResourceReservationHelper.parseCPU(u.cpu);
total.Memory += KubernetesResourceReservationHelper.megaBytesValue(u.memory);
return total;
}, new KubernetesResourceReservation());
this.resourceUsage = clusterResourceUsage;
} catch (err) {
this.Notifications.error('Failure', 'Unable to retrieve cluster resource usage', err);
}
}
async onInit() {
this.state = {
applicationsLoading: true,
viewReady: false,
hasUnhealthyComponentStatus: false,
useServerMetrics: false,
};
this.isAdmin = this.Authentication.isAdmin();
this.state.useServerMetrics = this.endpoint.Kubernetes.Configuration.UseServerMetrics;
await this.getNodes();
if (this.isAdmin) {
@ -134,7 +155,6 @@ class KubernetesClusterController {
}
this.state.viewReady = true;
this.state.useServerMetrics = this.EndpointProvider.currentEndpoint().Kubernetes.Configuration.UseServerMetrics;
}
$onInit() {