fix(app): remove duplicate values for multinode cluster [EE-6386] (#10947)

pull/10956/head
Ali 2024-01-15 14:34:54 +13:00 committed by GitHub
parent 3a959208a8
commit ae6333bf7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 9 deletions

View File

@ -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;
}