-
Notifications
You must be signed in to change notification settings - Fork 596
/
validations.ts
33 lines (29 loc) · 1.23 KB
/
validations.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { AFFINITY_CONDITIONS } from '../shared/consts';
import { AffinityRowData, AffinityLabel } from './types';
export const isWeightValid = (focusedAffinity: AffinityRowData) =>
focusedAffinity.condition === AFFINITY_CONDITIONS.required ||
(focusedAffinity.weight > 0 && focusedAffinity.weight <= 100);
export const isTermsInvalid = (terms: AffinityLabel[]) =>
terms?.some(
({ key, values, operator }) =>
!key || ((operator === 'In' || operator === 'NotIn') && values?.length === 0),
);
export const getTopologyKeyValidation = ({ type, condition, topologyKey }: AffinityRowData) => {
const topology = {
isTopologyDisabled: false,
isTopologyInvalid: false,
topologyValidationMessage: '',
};
if (condition === AFFINITY_CONDITIONS.required) {
if (type === 'podAffinity') {
topology.topologyValidationMessage = 'Topology key must not be empty';
topology.isTopologyInvalid = !topologyKey;
} else {
topology.isTopologyDisabled = true;
topology.topologyValidationMessage = 'topologyKey is limited with current config';
}
} else if (type === 'podAntiAffinity') {
topology.topologyValidationMessage = 'Empty topologyKey is interpreted as “all topologies”';
}
return topology;
};