From cb1a1e7be568ac1ad7092448869d376dfe79c396 Mon Sep 17 00:00:00 2001 From: Maxime Bajeux Date: Sat, 8 Aug 2020 00:46:11 +0200 Subject: [PATCH] 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 --- .../edit/resourcePoolController.js | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/app/kubernetes/views/resource-pools/edit/resourcePoolController.js b/app/kubernetes/views/resource-pools/edit/resourcePoolController.js index ae5f2113e..8c5995b3e 100644 --- a/app/kubernetes/views/resource-pools/edit/resourcePoolController.js +++ b/app/kubernetes/views/resource-pools/edit/resourcePoolController.js @@ -1,7 +1,7 @@ import angular from 'angular'; import _ from 'lodash-es'; 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 KubernetesEventHelper from 'Kubernetes/helpers/eventHelper'; @@ -19,7 +19,8 @@ class KubernetesResourcePoolController { KubernetesEventService, KubernetesPodService, KubernetesApplicationService, - KubernetesNamespaceHelper + KubernetesNamespaceHelper, + ModalService ) { this.$async = $async; this.$state = $state; @@ -34,6 +35,7 @@ class KubernetesResourcePoolController { this.KubernetesPodService = KubernetesPodService; this.KubernetesApplicationService = KubernetesApplicationService; this.KubernetesNamespaceHelper = KubernetesNamespaceHelper; + this.ModalService = ModalService; this.onInit = this.onInit.bind(this); this.createResourceQuotaAsync = this.createResourceQuotaAsync.bind(this); @@ -81,6 +83,17 @@ class KubernetesResourcePoolController { 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() { this.state.actionInProgress = true; try { @@ -112,7 +125,18 @@ class KubernetesResourcePoolController { } 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() { @@ -200,6 +224,7 @@ class KubernetesResourcePoolController { const quota = pool.Quota; if (quota) { + this.oldQuota = angular.copy(quota); this.formValues.hasQuota = true; this.formValues.CpuLimit = quota.CpuLimit; this.formValues.MemoryLimit = KubernetesResourceReservationHelper.megaBytesValue(quota.MemoryLimit);