From cc60836bb8fb656b917a56e2c775771a6f21f05f Mon Sep 17 00:00:00 2001 From: Ali <83188384+testA113@users.noreply.github.com> Date: Tue, 23 Jul 2024 09:31:13 +1200 Subject: [PATCH] fix(placements) filter out empty items in the required node affinity array [BE-11022] (#12036) Co-authored-by: testa113 --- .../usePlacementTableData.tsx | 82 ++++++++++--------- 1 file changed, 44 insertions(+), 38 deletions(-) diff --git a/app/react/kubernetes/applications/DetailsView/PlacementsDatatable/usePlacementTableData.tsx b/app/react/kubernetes/applications/DetailsView/PlacementsDatatable/usePlacementTableData.tsx index 16f4e9f3f..c6c4fcc61 100644 --- a/app/react/kubernetes/applications/DetailsView/PlacementsDatatable/usePlacementTableData.tsx +++ b/app/react/kubernetes/applications/DetailsView/PlacementsDatatable/usePlacementTableData.tsx @@ -181,46 +181,52 @@ function getUnmatchedRequiredNodeAffinities(node: Node, pod: Pod): Affinity[] { ?.requiredDuringSchedulingIgnoredDuringExecution; const unmatchedRequiredNodeAffinities: Affinity[] = - basicNodeAffinity?.nodeSelectorTerms.map( - (selectorTerm) => - selectorTerm.matchExpressions?.flatMap((matchExpression) => { - const exists = !!node.metadata?.labels?.[matchExpression.key]; - const isIn = - exists && - _.includes( - matchExpression.values, - node.metadata?.labels?.[matchExpression.key] - ); - - // Check if the match expression is satisfied - if ( - (matchExpression.operator === 'Exists' && exists) || - (matchExpression.operator === 'DoesNotExist' && !exists) || - (matchExpression.operator === 'In' && isIn) || - (matchExpression.operator === 'NotIn' && !isIn) || - (matchExpression.operator === 'Gt' && + basicNodeAffinity?.nodeSelectorTerms + .map( + (selectorTerm) => + selectorTerm.matchExpressions?.flatMap((matchExpression) => { + const exists = !!node.metadata?.labels?.[matchExpression.key]; + const isIn = exists && - parseInt(node.metadata?.labels?.[matchExpression.key] || '', 10) > - parseInt(matchExpression.values?.[0] || '', 10)) || - (matchExpression.operator === 'Lt' && - exists && - parseInt(node.metadata?.labels?.[matchExpression.key] || '', 10) < - parseInt(matchExpression.values?.[0] || '', 10)) - ) { - return []; - } + _.includes( + matchExpression.values, + node.metadata?.labels?.[matchExpression.key] + ); - // Return the unmatched affinity - return [ - { - key: matchExpression.key, - operator: - matchExpression.operator as KubernetesPodNodeAffinityNodeSelectorRequirementOperators, - values: matchExpression.values?.join(', ') || '', - }, - ]; - }) || [] - ) || []; + // Check if the match expression is satisfied + if ( + (matchExpression.operator === 'Exists' && exists) || + (matchExpression.operator === 'DoesNotExist' && !exists) || + (matchExpression.operator === 'In' && isIn) || + (matchExpression.operator === 'NotIn' && !isIn) || + (matchExpression.operator === 'Gt' && + exists && + parseInt( + node.metadata?.labels?.[matchExpression.key] || '', + 10 + ) > parseInt(matchExpression.values?.[0] || '', 10)) || + (matchExpression.operator === 'Lt' && + exists && + parseInt( + node.metadata?.labels?.[matchExpression.key] || '', + 10 + ) < parseInt(matchExpression.values?.[0] || '', 10)) + ) { + return []; + } + + // Return the unmatched affinity + return [ + { + key: matchExpression.key, + operator: + matchExpression.operator as KubernetesPodNodeAffinityNodeSelectorRequirementOperators, + values: matchExpression.values?.join(', ') || '', + }, + ]; + }) || [] + ) + .filter((unmatchedAffinity) => unmatchedAffinity.length > 0) || []; return unmatchedRequiredNodeAffinities; }