1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 13:29:41 +02:00
portainer/app/react/kubernetes/applications/components/ReplicationFormSection/replicationValidation.ts
Ali a58b4f479b
Some checks are pending
ci / build_images (map[arch:amd64 platform:linux]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
fix(app): remove duplicate validation messages [EE-5933] (#10967)
2024-01-17 16:30:30 +13:00

52 lines
1.8 KiB
TypeScript

import { SchemaOf, number, object } from 'yup';
import { ReplicaCountFormValues } from './types';
type ValidationData = {
resourceReservationsOverflow: boolean;
quotaExceeded: boolean;
nonScalableStorage: string;
supportScalableReplicaDeployment: boolean;
};
export function replicationValidation(
validationData?: ValidationData
): SchemaOf<ReplicaCountFormValues> {
const {
resourceReservationsOverflow,
quotaExceeded,
nonScalableStorage,
supportScalableReplicaDeployment,
} = validationData || {};
return object({
replicaCount: number()
.min(0, 'Instance count must be greater than or equal to 0.')
.test(
'overflow',
'This application would exceed available resources. Please review resource reservations or the instance count.',
(value) => {
// the user can't fix the error here with 1 replica. There are validation errors in the resource reservations section that are helpful in a case of resourceReservationsOverflow.
if (value === 1) {
return true;
}
return !resourceReservationsOverflow;
}
)
.test(
'quota',
'This application would exceed available storage. Please review the persisted folders or the instance count.',
() => !quotaExceeded // must not have quota exceeded
)
.test(
'scalable',
`The following storage option(s) do not support concurrent access from multiples instances: ${nonScalableStorage}. You will not be able to scale that application.`,
(value) => {
if (!value || value <= 1) {
return true;
}
return !!supportScalableReplicaDeployment;
} // must have support scalable replica deployment
)
.required('Instance count is required.'),
});
}