1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 15:59:41 +02:00

fix(app): only show special message when limits change for existing app resource limit [EE-6837] (#11367)

Co-authored-by: testa113 <testa113>
This commit is contained in:
Ali 2024-03-14 08:45:48 +13:00 committed by GitHub
parent a2a4c85f2d
commit 3b1d853090
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 29 additions and 8 deletions

View file

@ -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;