mirror of https://github.com/portainer/portainer
fix(app): NaN validation for autoscaling [EE-6714] (#11238)
parent
8f9b265f5a
commit
1bbe98379a
|
@ -1,5 +1,7 @@
|
||||||
import { SchemaOf, boolean, number, object } from 'yup';
|
import { SchemaOf, boolean, number, object } from 'yup';
|
||||||
|
|
||||||
|
import { nanNumberSchema } from '@/react-tools/yup-schemas';
|
||||||
|
|
||||||
import { AutoScalingFormValues } from './types';
|
import { AutoScalingFormValues } from './types';
|
||||||
|
|
||||||
type ValidationData = {
|
type ValidationData = {
|
||||||
|
@ -14,7 +16,7 @@ export function autoScalingValidation(
|
||||||
isUsed: boolean().required(),
|
isUsed: boolean().required(),
|
||||||
minReplicas: number().when('isUsed', (isUsed: boolean) =>
|
minReplicas: number().when('isUsed', (isUsed: boolean) =>
|
||||||
isUsed
|
isUsed
|
||||||
? number()
|
? nanNumberSchema('Minimum instances is required.')
|
||||||
.required('Minimum instances is required.')
|
.required('Minimum instances is required.')
|
||||||
.min(1, 'Minimum instances must be greater than 0.')
|
.min(1, 'Minimum instances must be greater than 0.')
|
||||||
.test(
|
.test(
|
||||||
|
@ -33,7 +35,7 @@ export function autoScalingValidation(
|
||||||
),
|
),
|
||||||
maxReplicas: number().when('isUsed', (isUsed: boolean) =>
|
maxReplicas: number().when('isUsed', (isUsed: boolean) =>
|
||||||
isUsed
|
isUsed
|
||||||
? number()
|
? nanNumberSchema('Maximum instances is required.')
|
||||||
.required('Maximum instances is required.')
|
.required('Maximum instances is required.')
|
||||||
.test(
|
.test(
|
||||||
'minReplicas',
|
'minReplicas',
|
||||||
|
@ -58,7 +60,7 @@ export function autoScalingValidation(
|
||||||
'isUsed',
|
'isUsed',
|
||||||
(isUsed: boolean) =>
|
(isUsed: boolean) =>
|
||||||
isUsed
|
isUsed
|
||||||
? number()
|
? nanNumberSchema('Target CPU utilization percentage is required.')
|
||||||
.min(0, 'Target CPU usage must be greater than 0.')
|
.min(0, 'Target CPU usage must be greater than 0.')
|
||||||
.max(100, 'Target CPU usage must be smaller than 100.')
|
.max(100, 'Target CPU usage must be smaller than 100.')
|
||||||
.required('Target CPU utilization percentage is required.')
|
.required('Target CPU utilization percentage is required.')
|
||||||
|
|
|
@ -23,8 +23,8 @@ export function resourceReservationValidation(
|
||||||
validationData?: ValidationData
|
validationData?: ValidationData
|
||||||
): SchemaOf<ResourceQuotaFormValues> {
|
): SchemaOf<ResourceQuotaFormValues> {
|
||||||
return object().shape({
|
return object().shape({
|
||||||
memoryLimit: nanNumberSchema()
|
memoryLimit: nanNumberSchema('Memory limit is required.')
|
||||||
.min(0, 'Value must be greater than or equal to 0')
|
.min(0, 'Value must be greater than or equal to 0.')
|
||||||
.test(
|
.test(
|
||||||
'exhaused',
|
'exhaused',
|
||||||
`The memory capacity for this namespace has been exhausted, so you cannot deploy the application.${
|
`The memory capacity for this namespace has been exhausted, so you cannot deploy the application.${
|
||||||
|
@ -37,7 +37,7 @@ export function resourceReservationValidation(
|
||||||
.max(
|
.max(
|
||||||
validationData?.maxMemoryLimit || 0,
|
validationData?.maxMemoryLimit || 0,
|
||||||
({ value }) =>
|
({ value }) =>
|
||||||
`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 now - the previous value of ${value} exceeds this.`
|
||||||
)
|
)
|
||||||
.test(
|
.test(
|
||||||
'hasSuitableNode',
|
'hasSuitableNode',
|
||||||
|
@ -56,7 +56,7 @@ export function resourceReservationValidation(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.required(),
|
.required('Memory limit is required.'),
|
||||||
cpuLimit: number()
|
cpuLimit: number()
|
||||||
.min(0)
|
.min(0)
|
||||||
.test(
|
.test(
|
||||||
|
@ -71,7 +71,7 @@ export function resourceReservationValidation(
|
||||||
.max(
|
.max(
|
||||||
validationData?.maxCpuLimit || 0,
|
validationData?.maxCpuLimit || 0,
|
||||||
({ value }) =>
|
({ value }) =>
|
||||||
`Value must be between 0 and ${validationData?.maxCpuLimit} now - the previous value of ${value} exceeds this`
|
`Value must be between 0 and ${validationData?.maxCpuLimit} now - the previous value of ${value} exceeds this.`
|
||||||
)
|
)
|
||||||
.test(
|
.test(
|
||||||
'hasSuitableNode',
|
'hasSuitableNode',
|
||||||
|
|
Loading…
Reference in New Issue