mirror of https://github.com/portainer/portainer
feat(k8s/resource-pool): add a modal when reducing the quota of an in use RP (#4170)
* feat(resourcepool): Reducing the Quota assigned to a RP * fix(k8s/resource-pool): fix an issue with hasResourceQuotaBeenReduce condition Co-authored-by: Anthony Lapenna <lapenna.anthony@gmail.com>pull/4177/head
parent
e7a33347c6
commit
cb1a1e7be5
|
@ -1,7 +1,7 @@
|
||||||
import angular from 'angular';
|
import angular from 'angular';
|
||||||
import _ from 'lodash-es';
|
import _ from 'lodash-es';
|
||||||
import filesizeParser from 'filesize-parser';
|
import filesizeParser from 'filesize-parser';
|
||||||
import { KubernetesResourceQuotaDefaults, KubernetesResourceQuota } from 'Kubernetes/models/resource-quota/models';
|
import { KubernetesResourceQuota, KubernetesResourceQuotaDefaults } from 'Kubernetes/models/resource-quota/models';
|
||||||
import KubernetesResourceReservationHelper from 'Kubernetes/helpers/resourceReservationHelper';
|
import KubernetesResourceReservationHelper from 'Kubernetes/helpers/resourceReservationHelper';
|
||||||
import KubernetesEventHelper from 'Kubernetes/helpers/eventHelper';
|
import KubernetesEventHelper from 'Kubernetes/helpers/eventHelper';
|
||||||
|
|
||||||
|
@ -19,7 +19,8 @@ class KubernetesResourcePoolController {
|
||||||
KubernetesEventService,
|
KubernetesEventService,
|
||||||
KubernetesPodService,
|
KubernetesPodService,
|
||||||
KubernetesApplicationService,
|
KubernetesApplicationService,
|
||||||
KubernetesNamespaceHelper
|
KubernetesNamespaceHelper,
|
||||||
|
ModalService
|
||||||
) {
|
) {
|
||||||
this.$async = $async;
|
this.$async = $async;
|
||||||
this.$state = $state;
|
this.$state = $state;
|
||||||
|
@ -34,6 +35,7 @@ class KubernetesResourcePoolController {
|
||||||
this.KubernetesPodService = KubernetesPodService;
|
this.KubernetesPodService = KubernetesPodService;
|
||||||
this.KubernetesApplicationService = KubernetesApplicationService;
|
this.KubernetesApplicationService = KubernetesApplicationService;
|
||||||
this.KubernetesNamespaceHelper = KubernetesNamespaceHelper;
|
this.KubernetesNamespaceHelper = KubernetesNamespaceHelper;
|
||||||
|
this.ModalService = ModalService;
|
||||||
|
|
||||||
this.onInit = this.onInit.bind(this);
|
this.onInit = this.onInit.bind(this);
|
||||||
this.createResourceQuotaAsync = this.createResourceQuotaAsync.bind(this);
|
this.createResourceQuotaAsync = this.createResourceQuotaAsync.bind(this);
|
||||||
|
@ -81,6 +83,17 @@ class KubernetesResourcePoolController {
|
||||||
await this.KubernetesResourceQuotaService.create(quota);
|
await this.KubernetesResourceQuotaService.create(quota);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hasResourceQuotaBeenReduce() {
|
||||||
|
if (this.formValues.hasQuota) {
|
||||||
|
const cpuLimit = this.formValues.CpuLimit;
|
||||||
|
const memoryLimit = KubernetesResourceReservationHelper.bytesValue(this.formValues.MemoryLimit);
|
||||||
|
if (cpuLimit < this.oldQuota.CpuLimit || memoryLimit < this.oldQuota.MemoryLimit) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
async updateResourcePoolAsync() {
|
async updateResourcePoolAsync() {
|
||||||
this.state.actionInProgress = true;
|
this.state.actionInProgress = true;
|
||||||
try {
|
try {
|
||||||
|
@ -112,7 +125,18 @@ class KubernetesResourcePoolController {
|
||||||
}
|
}
|
||||||
|
|
||||||
updateResourcePool() {
|
updateResourcePool() {
|
||||||
return this.$async(this.updateResourcePoolAsync);
|
if (this.hasResourceQuotaBeenReduce()) {
|
||||||
|
this.ModalService.confirmUpdate(
|
||||||
|
'Reducing the quota assigned to an "in-use" resource pool may have unintended consequences, including preventing running applications from functioning correctly and potentially even blocking them from running at all.',
|
||||||
|
(confirmed) => {
|
||||||
|
if (confirmed) {
|
||||||
|
return this.$async(this.updateResourcePoolAsync);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return this.$async(this.updateResourcePoolAsync);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hasEventWarnings() {
|
hasEventWarnings() {
|
||||||
|
@ -200,6 +224,7 @@ class KubernetesResourcePoolController {
|
||||||
|
|
||||||
const quota = pool.Quota;
|
const quota = pool.Quota;
|
||||||
if (quota) {
|
if (quota) {
|
||||||
|
this.oldQuota = angular.copy(quota);
|
||||||
this.formValues.hasQuota = true;
|
this.formValues.hasQuota = true;
|
||||||
this.formValues.CpuLimit = quota.CpuLimit;
|
this.formValues.CpuLimit = quota.CpuLimit;
|
||||||
this.formValues.MemoryLimit = KubernetesResourceReservationHelper.megaBytesValue(quota.MemoryLimit);
|
this.formValues.MemoryLimit = KubernetesResourceReservationHelper.megaBytesValue(quota.MemoryLimit);
|
||||||
|
|
Loading…
Reference in New Issue