mirror of
https://github.com/portainer/portainer.git
synced 2025-07-22 23:09:41 +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
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue