From 3b1d853090b93d6663c481812314a37313fcb473 Mon Sep 17 00:00:00 2001 From: Ali <83188384+testA113@users.noreply.github.com> Date: Thu, 14 Mar 2024 08:45:48 +1300 Subject: [PATCH] fix(app): only show special message when limits change for existing app resource limit [EE-6837] (#11367) Co-authored-by: testa113 --- .../applications/create/createApplication.html | 2 +- .../create/createApplicationController.js | 18 ++++++++++++++++++ .../resourceReservationValidation.ts | 17 ++++++++++------- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/app/kubernetes/views/applications/create/createApplication.html b/app/kubernetes/views/applications/create/createApplication.html index e80ab6d3b..23ca602cf 100644 --- a/app/kubernetes/views/applications/create/createApplication.html +++ b/app/kubernetes/views/applications/create/createApplication.html @@ -290,7 +290,7 @@ min-cpu-limit="ctrl.state.sliders.cpu.min" max-memory-limit="ctrl.state.sliders.memory.max" max-cpu-limit="ctrl.state.sliders.cpu.max" - validation-data="{isEdit: ctrl.state.isEdit, maxMemoryLimit: ctrl.state.sliders.memory.max, maxCpuLimit: ctrl.state.sliders.cpu.max, isEnvironmentAdmin: ctrl.isAdmin, nodeLimits: ctrl.nodesLimits.nodesLimits}" + validation-data="{isExistingCPUReservationUnchanged: ctrl.state.isExistingCPUReservationUnchanged, isExistingMemoryReservationUnchanged: ctrl.state.isExistingMemoryReservationUnchanged, maxMemoryLimit: ctrl.state.sliders.memory.max, maxCpuLimit: ctrl.state.sliders.cpu.max, isEnvironmentAdmin: ctrl.isAdmin, nodeLimits: ctrl.nodesLimits.nodesLimits}" resource-quota-capacity-exceeded="ctrl.resourceQuotaCapacityExceeded()" > diff --git a/app/kubernetes/views/applications/create/createApplicationController.js b/app/kubernetes/views/applications/create/createApplicationController.js index 8177f362e..63bfcf739 100644 --- a/app/kubernetes/views/applications/create/createApplicationController.js +++ b/app/kubernetes/views/applications/create/createApplicationController.js @@ -123,6 +123,10 @@ class KubernetesCreateApplicationController { persistedFoldersUseExistingVolumes: false, pullImageValidity: false, nodePortServices: [], + // when the namespace available resources changes, and the existing app not has a resource limit that exceeds whats available, + // a validation message will be shown. isExistingCPUReservationUnchanged and isExistingMemoryReservationUnchanged (with available resources being exceeded) is used to decide whether to show the message or not. + isExistingCPUReservationUnchanged: false, + isExistingMemoryReservationUnchanged: false, }; this.isAdmin = this.Authentication.isAdmin(); @@ -514,6 +518,13 @@ class KubernetesCreateApplicationController { return this.$async(async () => { this.formValues.MemoryLimit = values.memoryLimit; this.formValues.CpuLimit = values.cpuLimit; + + if (this.oldFormValues.CpuLimit !== this.formValues.CpuLimit && this.state.isExistingCPUReservationUnchanged) { + this.state.isExistingCPUReservationUnchanged = false; + } + if (this.oldFormValues.MemoryLimit !== this.formValues.MemoryLimit && this.state.isExistingMemoryReservationUnchanged) { + this.state.isExistingMemoryReservationUnchanged = false; + } }); } @@ -1063,6 +1074,13 @@ class KubernetesCreateApplicationController { this.originalServicePorts = structuredClone(this.formValues.Services.flatMap((service) => service.Ports)); this.originalIngressPaths = structuredClone(this.originalServicePorts.flatMap((port) => port.ingressPaths).filter((ingressPath) => ingressPath.Host)); + if (this.formValues.CpuLimit) { + this.state.isExistingCPUReservationUnchanged = true; + } + if (this.formValues.MemoryLimit) { + this.state.isExistingMemoryReservationUnchanged = true; + } + if (this.application.ApplicationKind) { this.state.appType = KubernetesDeploymentTypes[this.application.ApplicationKind.toUpperCase()]; if (this.application.ApplicationKind === KubernetesDeploymentTypes.URL) { diff --git a/app/react/kubernetes/applications/components/ResourceReservationFormSection/resourceReservationValidation.ts b/app/react/kubernetes/applications/components/ResourceReservationFormSection/resourceReservationValidation.ts index 2a785cb5e..1abc32be7 100644 --- a/app/react/kubernetes/applications/components/ResourceReservationFormSection/resourceReservationValidation.ts +++ b/app/react/kubernetes/applications/components/ResourceReservationFormSection/resourceReservationValidation.ts @@ -17,7 +17,8 @@ type ValidationData = { maxCpuLimit: number; isEnvironmentAdmin: boolean; nodeLimits: NodesLimits; - isEdit: boolean; + isExistingCPUReservationUnchanged: boolean; + isExistingMemoryReservationUnchanged: boolean; }; export function resourceReservationValidation( @@ -36,15 +37,16 @@ export function resourceReservationValidation( () => !!validationData && validationData.maxMemoryLimit > 0 ) .max(validationData?.maxMemoryLimit || 0, ({ value }) => - validationData?.isEdit + // when the existing reservation is unchanged and exceeds the new limit, show a different error message + // https://portainer.atlassian.net/browse/EE-5933?focusedCommentId=29308 + validationData?.isExistingMemoryReservationUnchanged ? `Value must be between 0 and ${validationData?.maxMemoryLimit}MB now - the previous value of ${value} exceeds this.` : `Value must be between 0 and ${validationData?.maxMemoryLimit}MB.` ) .test( 'hasSuitableNode', `These reservations would exceed the resources currently available in the cluster.`, - // eslint-disable-next-line prefer-arrow-callback, func-names - function (value: number | undefined, context: TestContext) { + (value: number | undefined, context: TestContext) => { if (!validationData || value === undefined) { // explicitely check for undefined, since 0 is a valid value return true; @@ -70,15 +72,16 @@ export function resourceReservationValidation( () => !!validationData && validationData.maxCpuLimit > 0 ) .max(validationData?.maxCpuLimit || 0, ({ value }) => - validationData?.isEdit + // when the existing reservation is unchanged and exceeds the new limit, show a different error message + // https://portainer.atlassian.net/browse/EE-5933?focusedCommentId=29308 + validationData?.isExistingCPUReservationUnchanged ? `Value must be between 0 and ${validationData?.maxCpuLimit} now - the previous value of ${value} exceeds this.` : `Value must be between 0 and ${validationData?.maxCpuLimit}.` ) .test( 'hasSuitableNode', `These reservations would exceed the resources currently available in the cluster.`, - // eslint-disable-next-line prefer-arrow-callback, func-names - function (value: number | undefined, context: TestContext) { + (value: number | undefined, context: TestContext) => { if (!validationData || value === undefined) { // explicitely check for undefined, since 0 is a valid value return true;