From 17677f34993a5000524be01dba387053fc95f787 Mon Sep 17 00:00:00 2001 From: Francesco Torchia Date: Tue, 16 Apr 2024 17:51:44 +0200 Subject: [PATCH] Add Unknown to architecture possible values; Add translations Signed-off-by: Francesco Torchia --- shell/assets/translations/en-us.yaml | 5 +++++ shell/models/provisioning.cattle.io.cluster.js | 10 +++++----- .../pages/c/_cluster/explorer/__tests__/index.test.ts | 4 +++- shell/pages/c/_cluster/explorer/index.vue | 10 +++++----- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/shell/assets/translations/en-us.yaml b/shell/assets/translations/en-us.yaml index 1567494f3b..064ec0072e 100644 --- a/shell/assets/translations/en-us.yaml +++ b/shell/assets/translations/en-us.yaml @@ -1726,6 +1726,11 @@ cluster: } rkeTemplateUpgrade: Template revision {name} available for upgrade + architecture: + label: + unknown: Unknown + mixed: Mixed + availabilityWarnings: node: Node {name} is inactive machine: Machine {name} is inactive diff --git a/shell/models/provisioning.cattle.io.cluster.js b/shell/models/provisioning.cattle.io.cluster.js index b72cbff99b..3b72713f15 100644 --- a/shell/models/provisioning.cattle.io.cluster.js +++ b/shell/models/provisioning.cattle.io.cluster.js @@ -408,11 +408,11 @@ export default class ProvCluster extends SteveModel { const obj = {}; this.nodes?.forEach((node) => { - const key = capitalize(node.status?.nodeLabels?.[NODE_ARCHITECTURE] || ''); + const architecture = node.status?.nodeLabels?.[NODE_ARCHITECTURE]; - if (key) { - obj[key] = (obj[key] || 0) + 1; - } + const key = architecture ? capitalize(architecture) : this.t('cluster.architecture.label.unknown'); + + obj[key] = (obj[key] || 0) + 1; }); return obj; @@ -422,7 +422,7 @@ export default class ProvCluster extends SteveModel { const keys = Object.keys(this.nodesArchitecture); return { - label: keys.length === 1 ? keys[0] : 'Mixed', + label: keys.length === 1 ? keys[0] : this.t('cluster.architecture.label.mixed'), tooltip: keys.length === 1 ? undefined : keys.reduce((acc, k) => `${ acc }${ k }: ${ this.nodesArchitecture[k] }
`, '') }; } diff --git a/shell/pages/c/_cluster/explorer/__tests__/index.test.ts b/shell/pages/c/_cluster/explorer/__tests__/index.test.ts index 6637e3e8af..61371a0086 100644 --- a/shell/pages/c/_cluster/explorer/__tests__/index.test.ts +++ b/shell/pages/c/_cluster/explorer/__tests__/index.test.ts @@ -160,8 +160,10 @@ describe('page: cluster dashboard', () => { ['clusterProvider', [], 'other'], ['kubernetesVersion', [], '0.0.0 k3s'], ['created', [], 'glance.created'], - ['architecture', [{ labels: { [NODE_ARCHITECTURE]: 'amd64' } }, { labels: { [NODE_ARCHITECTURE]: 'intel' } }], 'Mixed'], + ['architecture', [{ labels: { [NODE_ARCHITECTURE]: 'amd64' } }, { labels: { [NODE_ARCHITECTURE]: 'intel' } }], 'mixed'], + ['architecture', [{ labels: { [NODE_ARCHITECTURE]: 'amd64' } }, { labels: { } }], 'mixed'], ['architecture', [{ labels: { [NODE_ARCHITECTURE]: 'amd64' } }], 'Amd64'], + ['architecture', [{ labels: { } }], 'unknown'], ])('should show %p label', (label, nodes, text) => { const options = clone(mountOptions); diff --git a/shell/pages/c/_cluster/explorer/index.vue b/shell/pages/c/_cluster/explorer/index.vue index 9c2ef28bef..3fccd74397 100644 --- a/shell/pages/c/_cluster/explorer/index.vue +++ b/shell/pages/c/_cluster/explorer/index.vue @@ -204,11 +204,11 @@ export default { const obj = {}; this.nodes?.forEach((node) => { - const key = capitalize(node.labels?.[NODE_ARCHITECTURE] || ''); + const architecture = node.labels?.[NODE_ARCHITECTURE]; - if (key) { - obj[key] = (obj[key] || 0) + 1; - } + const key = architecture ? capitalize(architecture) : this.t('cluster.architecture.label.unknown'); + + obj[key] = (obj[key] || 0) + 1; }); return obj; @@ -218,7 +218,7 @@ export default { const keys = Object.keys(this.nodesArchitecture); return { - label: keys.length === 1 ? keys[0] : 'Mixed', + label: keys.length === 1 ? keys[0] : this.t('cluster.architecture.label.mixed'), tooltip: keys.length === 1 ? undefined : keys.reduce((acc, k) => `${ acc }${ k }: ${ this.nodesArchitecture[k] }
`, '') }; },