From ae6333bf7cf67e168e42b89feea8ea72221b6c41 Mon Sep 17 00:00:00 2001 From: Ali <83188384+testA113@users.noreply.github.com> Date: Mon, 15 Jan 2024 14:34:54 +1300 Subject: [PATCH] fix(app): remove duplicate values for multinode cluster [EE-6386] (#10947) --- .../PlacementFormSection.tsx | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/app/react/kubernetes/applications/components/PlacementFormSection/PlacementFormSection.tsx b/app/react/kubernetes/applications/components/PlacementFormSection/PlacementFormSection.tsx index 66d6b138d..be1685946 100644 --- a/app/react/kubernetes/applications/components/PlacementFormSection/PlacementFormSection.tsx +++ b/app/react/kubernetes/applications/components/PlacementFormSection/PlacementFormSection.tsx @@ -122,15 +122,24 @@ function useNodeLabels(): NodeLabels { })) ) || []; - // get unique node labels with each label's possible values - const uniqueLabels = new Set(nodeLabelPairs.map((pair) => pair.key)); - // create a NodeLabels object with each label's possible values - const nodesLabels = Array.from(uniqueLabels).reduce((acc, key) => { - acc[key] = nodeLabelPairs - .filter((pair) => pair.key === key) - .map((pair) => pair.value); - return acc; - }, {} as NodeLabels); + // create a NodeLabels object with each label key's possible values, without duplicate keys or values. e.g. { 'beta.kubernetes.io/arch': ['amd64', 'arm64'] } + // in multinode clusters, there can be multiple nodes with the same label key + const allNodesLabels = nodeLabelPairs.map((pair) => pair.key); + const uniqueNodesLabels = new Set(allNodesLabels); + const nodesLabels: NodeLabels = Array.from(uniqueNodesLabels).reduce( + (acc: NodeLabels, key) => { + // get all possible values for a given node label key + const allNodeValuesForKey = nodeLabelPairs + .filter((pair) => pair.key === key) + .map((pair) => pair.value); + // in multinode clusters, there can be duplicate values for a given key, so remove them + const uniqueValues = Array.from(new Set(allNodeValuesForKey)); + + acc[key] = uniqueValues; + return acc; + }, + {} as NodeLabels + ); return nodesLabels; }