mirror of
https://github.com/portainer/portainer.git
synced 2025-07-23 07:19:41 +02:00
fix(app): remove duplicate validation messages [EE-5933] (#10967)
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
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
This commit is contained in:
parent
93593e1379
commit
a58b4f479b
5 changed files with 80 additions and 6 deletions
|
@ -1,11 +1,21 @@
|
|||
import { SchemaOf, number, object } from 'yup';
|
||||
import { SchemaOf, TestContext, number, object } from 'yup';
|
||||
|
||||
import KubernetesResourceReservationHelper from '@/kubernetes/helpers/resourceReservationHelper';
|
||||
|
||||
import { ResourceQuotaFormValues } from './types';
|
||||
|
||||
type NodeLimit = {
|
||||
CPU: number;
|
||||
Memory: number;
|
||||
};
|
||||
|
||||
type NodesLimits = Record<string, NodeLimit>;
|
||||
|
||||
type ValidationData = {
|
||||
maxMemoryLimit: number;
|
||||
maxCpuLimit: number;
|
||||
isEnvironmentAdmin: boolean;
|
||||
nodeLimits: NodesLimits;
|
||||
};
|
||||
|
||||
export function resourceReservationValidation(
|
||||
|
@ -28,6 +38,23 @@ export function resourceReservationValidation(
|
|||
({ value }) =>
|
||||
`Value must be between 0 and ${validationData?.maxMemoryLimit}MB now - the previous value of ${value} exceeds this`
|
||||
)
|
||||
.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) {
|
||||
if (!validationData || value === undefined) {
|
||||
// explicitely check for undefined, since 0 is a valid value
|
||||
return true;
|
||||
}
|
||||
const { memoryLimit, cpuLimit } = context.parent;
|
||||
return hasSuitableNode(
|
||||
memoryLimit,
|
||||
cpuLimit,
|
||||
validationData.nodeLimits
|
||||
);
|
||||
}
|
||||
)
|
||||
.required(),
|
||||
cpuLimit: number()
|
||||
.min(0)
|
||||
|
@ -45,6 +72,41 @@ export function resourceReservationValidation(
|
|||
({ value }) =>
|
||||
`Value must be between 0 and ${validationData?.maxCpuLimit} now - the previous value of ${value} exceeds this`
|
||||
)
|
||||
.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) {
|
||||
if (!validationData || value === undefined) {
|
||||
// explicitely check for undefined, since 0 is a valid value
|
||||
return true;
|
||||
}
|
||||
const { memoryLimit, cpuLimit } = context.parent;
|
||||
return hasSuitableNode(
|
||||
memoryLimit,
|
||||
cpuLimit,
|
||||
validationData.nodeLimits
|
||||
);
|
||||
}
|
||||
)
|
||||
.required(),
|
||||
});
|
||||
}
|
||||
|
||||
function hasSuitableNode(
|
||||
memoryLimit: number,
|
||||
cpuLimit: number,
|
||||
nodeLimits: NodesLimits
|
||||
) {
|
||||
// transform the nodelimits from bytes to MB
|
||||
const limits = Object.values(nodeLimits).map((nodeLimit) => ({
|
||||
...nodeLimit,
|
||||
Memory: KubernetesResourceReservationHelper.megaBytesValue(
|
||||
nodeLimit.Memory
|
||||
),
|
||||
}));
|
||||
// make sure there's a node available with enough memory and cpu
|
||||
return limits.some(
|
||||
(nodeLimit) => nodeLimit.Memory >= memoryLimit && nodeLimit.CPU >= cpuLimit
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue