mirror of
https://github.com/portainer/portainer.git
synced 2025-08-04 21:35:23 +02:00
refactor(k8s): namespace core logic (#12142)
Co-authored-by: testA113 <aliharriss1995@gmail.com> Co-authored-by: Anthony Lapenna <anthony.lapenna@portainer.io> Co-authored-by: James Carppe <85850129+jamescarppe@users.noreply.github.com> Co-authored-by: Ali <83188384+testA113@users.noreply.github.com>
This commit is contained in:
parent
da010f3d08
commit
ea228c3d6d
276 changed files with 9241 additions and 3361 deletions
|
@ -76,12 +76,12 @@
|
|||
<div style="padding: 8px">
|
||||
<kubernetes-resource-reservation
|
||||
ng-if="ctrl.resourceReservation"
|
||||
cpu-reservation="ctrl.resourceReservation.CPU"
|
||||
cpu-reservation="ctrl.resourceReservation.CpuRequest"
|
||||
cpu-usage="ctrl.resourceUsage.CPU"
|
||||
cpu-limit="ctrl.node.CPU"
|
||||
memory-reservation="ctrl.resourceReservation.Memory"
|
||||
memory-reservation="ctrl.resourceReservation.MemoryRequest"
|
||||
memory-usage="ctrl.resourceUsage.Memory"
|
||||
memory-limit="ctrl.memoryLimit"
|
||||
memory-limit="ctrl.node.Memory"
|
||||
description="Resource reservation represents the total amount of resource assigned to all the applications running on this node."
|
||||
display-usage="ctrl.hasResourceUsageAccess()"
|
||||
>
|
||||
|
@ -267,11 +267,5 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<kubernetes-node-applications-datatable
|
||||
ng-if="ctrl.applications && ctrl.applications.length > 0"
|
||||
dataset="ctrl.applications"
|
||||
on-refresh="(ctrl.getApplications)"
|
||||
is-loading="ctrl.state.applicationsLoading"
|
||||
>
|
||||
</kubernetes-node-applications-datatable>
|
||||
<kubernetes-node-applications-datatable></kubernetes-node-applications-datatable>
|
||||
</div>
|
||||
|
|
|
@ -9,7 +9,7 @@ import { KubernetesNodeTaintEffects, KubernetesNodeAvailabilities } from 'Kubern
|
|||
import KubernetesFormValidationHelper from 'Kubernetes/helpers/formValidationHelper';
|
||||
import { KubernetesNodeHelper } from 'Kubernetes/node/helper';
|
||||
import { confirmUpdateNode } from '@/react/kubernetes/cluster/NodeView/ConfirmUpdateNode';
|
||||
import { getMetricsForNode } from '@/react/kubernetes/services/service.ts';
|
||||
import { getMetricsForNode, getTotalResourcesForAllApplications } from '@/react/kubernetes/metrics/metrics.ts';
|
||||
|
||||
class KubernetesNodeController {
|
||||
/* @ngInject */
|
||||
|
@ -40,7 +40,6 @@ class KubernetesNodeController {
|
|||
this.getNodesAsync = this.getNodesAsync.bind(this);
|
||||
this.getEvents = this.getEvents.bind(this);
|
||||
this.getEventsAsync = this.getEventsAsync.bind(this);
|
||||
this.getApplicationsAsync = this.getApplicationsAsync.bind(this);
|
||||
this.getEndpointsAsync = this.getEndpointsAsync.bind(this);
|
||||
this.updateNodeAsync = this.updateNodeAsync.bind(this);
|
||||
this.drainNodeAsync = this.drainNodeAsync.bind(this);
|
||||
|
@ -300,6 +299,8 @@ class KubernetesNodeController {
|
|||
try {
|
||||
const nodeName = this.$transition$.params().nodeName;
|
||||
const node = await getMetricsForNode(this.$state.params.endpointId, nodeName);
|
||||
node.CPU = node.usage.cpu;
|
||||
node.Memory = KubernetesResourceReservationHelper.megaBytesValue(node.usage.memory);
|
||||
this.resourceUsage = new KubernetesResourceReservation();
|
||||
this.resourceUsage.CPU = KubernetesResourceReservationHelper.parseCPU(node.usage.cpu);
|
||||
this.resourceUsage.Memory = KubernetesResourceReservationHelper.megaBytesValue(node.usage.memory);
|
||||
|
@ -338,43 +339,6 @@ class KubernetesNodeController {
|
|||
this.selectTab(2);
|
||||
}
|
||||
|
||||
async getApplicationsAsync() {
|
||||
try {
|
||||
this.state.applicationsLoading = true;
|
||||
this.applications = await this.KubernetesApplicationService.get();
|
||||
|
||||
this.resourceReservation = new KubernetesResourceReservation();
|
||||
this.applications = _.map(this.applications, (app) => {
|
||||
app.Pods = _.filter(app.Pods, (pod) => pod.Node === this.node.Name);
|
||||
return app;
|
||||
});
|
||||
this.applications = _.filter(this.applications, (app) => app.Pods.length !== 0);
|
||||
this.applications = _.map(this.applications, (app) => {
|
||||
const resourceReservation = KubernetesResourceReservationHelper.computeResourceReservation(app.Pods);
|
||||
app.CPU = resourceReservation.CPU;
|
||||
app.Memory = resourceReservation.Memory;
|
||||
this.resourceReservation.CPU += resourceReservation.CPU;
|
||||
this.resourceReservation.Memory += resourceReservation.Memory;
|
||||
return app;
|
||||
});
|
||||
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.hasResourceUsageAccess()) {
|
||||
await this.getNodeUsage();
|
||||
}
|
||||
} catch (err) {
|
||||
this.Notifications.error('Failure', err, 'Unable to retrieve applications');
|
||||
} finally {
|
||||
this.state.applicationsLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
getApplications() {
|
||||
return this.$async(this.getApplicationsAsync);
|
||||
}
|
||||
|
||||
async onInit() {
|
||||
this.availabilities = KubernetesNodeAvailabilities;
|
||||
|
||||
|
@ -399,7 +363,6 @@ class KubernetesNodeController {
|
|||
|
||||
await this.getNodes();
|
||||
await this.getEvents();
|
||||
await this.getApplications();
|
||||
await this.getEndpoints();
|
||||
|
||||
this.availableEffects = _.values(KubernetesNodeTaintEffects);
|
||||
|
@ -407,6 +370,11 @@ class KubernetesNodeController {
|
|||
this.formValues.Labels = KubernetesNodeHelper.computeUsedLabels(this.applications, this.formValues.Labels);
|
||||
this.formValues.Labels = KubernetesNodeHelper.reorderLabels(this.formValues.Labels);
|
||||
|
||||
this.resourceReservation = await getTotalResourcesForAllApplications(this.$state.params.endpointId, this.node.Name);
|
||||
this.resourceReservation.CpuRequest = Math.round(this.resourceReservation.CpuRequest / 1000);
|
||||
this.resourceReservation.MemoryRequest = KubernetesResourceReservationHelper.megaBytesValue(this.resourceReservation.MemoryRequest);
|
||||
this.node.Memory = KubernetesResourceReservationHelper.megaBytesValue(this.node.Memory);
|
||||
|
||||
this.state.viewReady = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import moment from 'moment';
|
|||
import filesizeParser from 'filesize-parser';
|
||||
import KubernetesResourceReservationHelper from 'Kubernetes/helpers/resourceReservationHelper';
|
||||
import { PORTAINER_FADEOUT } from '@/constants';
|
||||
import { getMetricsForNode } from '@/react/kubernetes/services/service.ts';
|
||||
import { getMetricsForNode } from '@/react/kubernetes/metrics/metrics.ts';
|
||||
|
||||
class KubernetesNodeStatsController {
|
||||
/* @ngInject */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue