mirror of
https://github.com/portainer/portainer.git
synced 2025-07-21 14:29:40 +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:
parent
cee7ac26e9
commit
ce31de5e9e
13 changed files with 188 additions and 30 deletions
|
@ -21,7 +21,9 @@ class KubernetesNodeController {
|
|||
KubernetesEventService,
|
||||
KubernetesPodService,
|
||||
KubernetesApplicationService,
|
||||
KubernetesEndpointService
|
||||
KubernetesEndpointService,
|
||||
KubernetesMetricsService,
|
||||
Authentication
|
||||
) {
|
||||
this.$async = $async;
|
||||
this.$state = $state;
|
||||
|
@ -33,6 +35,8 @@ class KubernetesNodeController {
|
|||
this.KubernetesPodService = KubernetesPodService;
|
||||
this.KubernetesApplicationService = KubernetesApplicationService;
|
||||
this.KubernetesEndpointService = KubernetesEndpointService;
|
||||
this.KubernetesMetricsService = KubernetesMetricsService;
|
||||
this.Authentication = Authentication;
|
||||
|
||||
this.onInit = this.onInit.bind(this);
|
||||
this.getNodesAsync = this.getNodesAsync.bind(this);
|
||||
|
@ -42,6 +46,7 @@ class KubernetesNodeController {
|
|||
this.getEndpointsAsync = this.getEndpointsAsync.bind(this);
|
||||
this.updateNodeAsync = this.updateNodeAsync.bind(this);
|
||||
this.drainNodeAsync = this.drainNodeAsync.bind(this);
|
||||
this.getNodeUsageAsync = this.getNodeUsageAsync.bind(this);
|
||||
}
|
||||
|
||||
selectTab(index) {
|
||||
|
@ -327,6 +332,22 @@ class KubernetesNodeController {
|
|||
return this.$async(this.getNodesAsync);
|
||||
}
|
||||
|
||||
async getNodeUsageAsync() {
|
||||
try {
|
||||
const nodeName = this.$transition$.params().name;
|
||||
const node = await this.KubernetesMetricsService.getNode(nodeName);
|
||||
this.resourceUsage = new KubernetesResourceReservation();
|
||||
this.resourceUsage.CPU = KubernetesResourceReservationHelper.parseCPU(node.usage.cpu);
|
||||
this.resourceUsage.Memory = KubernetesResourceReservationHelper.megaBytesValue(node.usage.memory);
|
||||
} catch (err) {
|
||||
this.Notifications.error('Failure', 'Unable to retrieve node resource usage', err);
|
||||
}
|
||||
}
|
||||
|
||||
getNodeUsage() {
|
||||
return this.$async(this.getNodeUsageAsync);
|
||||
}
|
||||
|
||||
hasEventWarnings() {
|
||||
return this.state.eventWarningCount;
|
||||
}
|
||||
|
@ -375,6 +396,10 @@ class KubernetesNodeController {
|
|||
this.resourceReservation.Memory = KubernetesResourceReservationHelper.megaBytesValue(this.resourceReservation.Memory);
|
||||
this.memoryLimit = KubernetesResourceReservationHelper.megaBytesValue(this.node.Memory);
|
||||
this.state.isContainPortainer = _.find(this.applications, { ApplicationName: 'portainer' });
|
||||
|
||||
if (this.state.isAdmin) {
|
||||
await this.getNodeUsage();
|
||||
}
|
||||
} catch (err) {
|
||||
this.Notifications.error('Failure', err, 'Unable to retrieve applications');
|
||||
} finally {
|
||||
|
@ -388,6 +413,7 @@ class KubernetesNodeController {
|
|||
|
||||
async onInit() {
|
||||
this.state = {
|
||||
isAdmin: this.Authentication.isAdmin(),
|
||||
activeTab: 0,
|
||||
currentName: this.$state.$current.name,
|
||||
dataLoading: true,
|
||||
|
@ -402,10 +428,13 @@ class KubernetesNodeController {
|
|||
hasDuplicateLabelKeys: false,
|
||||
isDrainOperation: false,
|
||||
isContainPortainer: false,
|
||||
useServerMetrics: false,
|
||||
};
|
||||
|
||||
this.availabilities = KubernetesNodeAvailabilities;
|
||||
|
||||
this.state.useServerMetrics = this.endpoint.Kubernetes.Configuration.UseServerMetrics;
|
||||
|
||||
this.state.activeTab = this.LocalStorage.getActiveTab('node');
|
||||
|
||||
await this.getNodes();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue