fix(placements) filter out empty items in the required node affinity array [BE-11022] (#12036)

Co-authored-by: testa113 <testa113>
pull/12045/head
Ali 2024-07-23 09:31:13 +12:00 committed by GitHub
parent e2830019d7
commit cc60836bb8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 44 additions and 38 deletions

View File

@ -181,7 +181,8 @@ function getUnmatchedRequiredNodeAffinities(node: Node, pod: Pod): Affinity[] {
?.requiredDuringSchedulingIgnoredDuringExecution; ?.requiredDuringSchedulingIgnoredDuringExecution;
const unmatchedRequiredNodeAffinities: Affinity[] = const unmatchedRequiredNodeAffinities: Affinity[] =
basicNodeAffinity?.nodeSelectorTerms.map( basicNodeAffinity?.nodeSelectorTerms
.map(
(selectorTerm) => (selectorTerm) =>
selectorTerm.matchExpressions?.flatMap((matchExpression) => { selectorTerm.matchExpressions?.flatMap((matchExpression) => {
const exists = !!node.metadata?.labels?.[matchExpression.key]; const exists = !!node.metadata?.labels?.[matchExpression.key];
@ -200,12 +201,16 @@ function getUnmatchedRequiredNodeAffinities(node: Node, pod: Pod): Affinity[] {
(matchExpression.operator === 'NotIn' && !isIn) || (matchExpression.operator === 'NotIn' && !isIn) ||
(matchExpression.operator === 'Gt' && (matchExpression.operator === 'Gt' &&
exists && exists &&
parseInt(node.metadata?.labels?.[matchExpression.key] || '', 10) > parseInt(
parseInt(matchExpression.values?.[0] || '', 10)) || node.metadata?.labels?.[matchExpression.key] || '',
10
) > parseInt(matchExpression.values?.[0] || '', 10)) ||
(matchExpression.operator === 'Lt' && (matchExpression.operator === 'Lt' &&
exists && exists &&
parseInt(node.metadata?.labels?.[matchExpression.key] || '', 10) < parseInt(
parseInt(matchExpression.values?.[0] || '', 10)) node.metadata?.labels?.[matchExpression.key] || '',
10
) < parseInt(matchExpression.values?.[0] || '', 10))
) { ) {
return []; return [];
} }
@ -220,7 +225,8 @@ function getUnmatchedRequiredNodeAffinities(node: Node, pod: Pod): Affinity[] {
}, },
]; ];
}) || [] }) || []
) || []; )
.filter((unmatchedAffinity) => unmatchedAffinity.length > 0) || [];
return unmatchedRequiredNodeAffinities; return unmatchedRequiredNodeAffinities;
} }