From 87d0ba350c6d6eff09b24cc75f32c2591bcd5709 Mon Sep 17 00:00:00 2001 From: Francesco Torchia Date: Tue, 10 Dec 2024 12:50:15 +0100 Subject: [PATCH 1/5] Clean up code Signed-off-by: Francesco Torchia --- .../harvesterhci.io.management.cluster.vue | 39 +++++++------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/pkg/harvester-manager/list/harvesterhci.io.management.cluster.vue b/pkg/harvester-manager/list/harvesterhci.io.management.cluster.vue index 05ef49013d..2af5caacf7 100644 --- a/pkg/harvester-manager/list/harvesterhci.io.management.cluster.vue +++ b/pkg/harvester-manager/list/harvesterhci.io.management.cluster.vue @@ -79,7 +79,7 @@ export default { hciClusters: [], mgmtClusters: [], harvesterRepository: null, - harvesterLatestVersion: null, + harvesterUpdateVersion: null, harvesterRepositoryError: false, harvesterExtensionInstallError: false, harvesterExtensionUpdateError: false, @@ -104,7 +104,7 @@ export default { await refreshHelmRepository(this.$store, HARVESTER_REPO.spec.gitRepo, HARVESTER_REPO.spec.gitBranch); if (this.harvester.extension) { - await this.setHarvesterLatestVersion(); + await this.setHarvesterUpdateVersion(); } } } @@ -116,8 +116,7 @@ export default { harvester() { const extension = this.uiplugins?.find((c) => c.name === HARVESTER_CHART.name); const missingRepository = !!extension && !this.harvesterRepository; - const isLatestVersionAvailable = !!this.harvesterLatestVersion; - + const action = async(btnCb) => { const action = `${ !extension ? 'install' : 'update' }HarvesterExtension`; @@ -138,7 +137,7 @@ export default { action = 'error'; } else if (missingRepository) { action = 'missingRepo'; - } else if (isLatestVersionAvailable) { + } else if (!!this.harvesterUpdateVersion) { action = 'update'; } else if (!extension) { action = 'install'; @@ -159,9 +158,8 @@ export default { return { extension, missingRepository, - isLatestVersionAvailable, - toInstall: !extension, - toUpdate: missingRepository || isLatestVersionAvailable, + toInstall: !extension, + toUpdate: missingRepository || !!this.harvesterUpdateVersion, action, panelLabel, hasErrors, @@ -214,12 +212,12 @@ export default { } }, - async setHarvesterLatestVersion() { + async setHarvesterUpdateVersion() { try { const version = await getLatestExtensionVersion(this.$store, HARVESTER_CHART.name); if (semver.gt(version, this.harvester.extension.version)) { - this.harvesterLatestVersion = version; + this.harvesterUpdateVersion = version; } } catch (error) { this.harvesterExtensionUpdateError = true; @@ -246,10 +244,7 @@ export default { installed = await waitForUIPackage(this.$store, extension); } catch (error) { - this.harvesterExtensionInstallError = true; - - btnCb(false); - } + } this.harvesterExtensionInstallError = !installed; @@ -264,24 +259,20 @@ export default { let updated = false; try { - let harvesterRepository = this.harvesterRepository; - if (this.harvester.missingRepository) { - harvesterRepository = await ensureHelmRepository(this.$store, HARVESTER_REPO.spec.gitRepo, HARVESTER_REPO.metadata.name, HARVESTER_REPO.spec.gitBranch); + this.harvesterRepository = await ensureHelmRepository(this.$store, HARVESTER_REPO.spec.gitRepo, HARVESTER_REPO.metadata.name, HARVESTER_REPO.spec.gitBranch); - await this.setHarvesterLatestVersion(); + await this.setHarvesterUpdateVersion(); } - await installHelmChart(harvesterRepository, { ...HARVESTER_CHART, version: this.harvesterLatestVersion }, {}, UI_PLUGIN_NAMESPACE, 'upgrade'); + + await installHelmChart(this.harvesterRepository, { ...HARVESTER_CHART, version: this.harvesterUpdateVersion }, {}, UI_PLUGIN_NAMESPACE, 'upgrade'); const extension = await waitForUIExtension(this.$store, HARVESTER_CHART.name); - updated = await waitForUIPackage(this.$store, { ...extension, version: this.harvesterLatestVersion }); + updated = await waitForUIPackage(this.$store, { ...extension, version: this.harvesterUpdateVersion }); } catch (error) { - this.harvesterExtensionUpdateError = true; - - btnCb(false); - } + } this.harvesterExtensionUpdateError = !updated; From 0fc688ce2e8d00cf3acfbc28373d5c16ba624c67 Mon Sep 17 00:00:00 2001 From: Francesco Torchia Date: Tue, 10 Dec 2024 13:44:10 +0100 Subject: [PATCH 2/5] Show Error message in case of Harvester extension is not compatible with Rancher Signed-off-by: Francesco Torchia --- pkg/harvester-manager/l10n/en-us.yaml | 4 +++ .../harvesterhci.io.management.cluster.vue | 33 ++++++++++++++----- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/pkg/harvester-manager/l10n/en-us.yaml b/pkg/harvester-manager/l10n/en-us.yaml index adcfae96ed..cc302fd559 100644 --- a/pkg/harvester-manager/l10n/en-us.yaml +++ b/pkg/harvester-manager/l10n/en-us.yaml @@ -33,6 +33,10 @@ harvesterManager: warning: "The Harvester UI Extension repository is missing" prompt: "Please click on Update button to add the Harvester repository and install the latest Harvester UI Extension, if any" prompt-standard-user: Please contact your system administrator to install the latest Harvester UI Extension, if any + missingVersion: + warning: "Could not find a compatible version" + prompt: "Please update Rancher to get the latest version of the Harvester UI extension" + prompt-standard-user: Please contact your system administrator error: warning: "Warning, Harvester UI extension automatic installation failed" prompt: "Please refresh the page and try again or install the Harvester UI extension manually" diff --git a/pkg/harvester-manager/list/harvesterhci.io.management.cluster.vue b/pkg/harvester-manager/list/harvesterhci.io.management.cluster.vue index 2af5caacf7..d4cc806b74 100644 --- a/pkg/harvester-manager/list/harvesterhci.io.management.cluster.vue +++ b/pkg/harvester-manager/list/harvesterhci.io.management.cluster.vue @@ -79,6 +79,7 @@ export default { hciClusters: [], mgmtClusters: [], harvesterRepository: null, + harvesterInstallVersion: true, harvesterUpdateVersion: null, harvesterRepositoryError: false, harvesterExtensionInstallError: false, @@ -116,14 +117,15 @@ export default { harvester() { const extension = this.uiplugins?.find((c) => c.name === HARVESTER_CHART.name); const missingRepository = !!extension && !this.harvesterRepository; - + const action = async(btnCb) => { const action = `${ !extension ? 'install' : 'update' }HarvesterExtension`; await this[action](btnCb); }; - const hasErrors = this.harvesterRepositoryError || + const hasErrors = !this.harvesterInstallVersion || + this.harvesterRepositoryError || this.harvesterExtensionInstallError || this.harvesterExtensionUpdateError; @@ -133,7 +135,9 @@ export default { ].reduce((acc, label) => { let action = ''; - if (hasErrors) { + if (!this.harvesterInstallVersion) { + action = 'missingVersion'; + } else if (hasErrors) { action = 'error'; } else if (missingRepository) { action = 'missingRepo'; @@ -158,7 +162,7 @@ export default { return { extension, missingRepository, - toInstall: !extension, + toInstall: !extension, toUpdate: missingRepository || !!this.harvesterUpdateVersion, action, panelLabel, @@ -236,15 +240,21 @@ export default { */ await refreshHelmRepository(this.$store, HARVESTER_REPO.spec.gitRepo, HARVESTER_REPO.spec.gitBranch); - const version = await getLatestExtensionVersion(this.$store, HARVESTER_CHART.name); + this.harvesterInstallVersion = await getLatestExtensionVersion(this.$store, HARVESTER_CHART.name); + + if (!this.harvesterInstallVersion) { + btnCb(false); + + return; + } - await installHelmChart(harvesterRepo, { ...HARVESTER_CHART, version }, {}, UI_PLUGIN_NAMESPACE, 'install'); + await installHelmChart(harvesterRepo, { ...HARVESTER_CHART, version: this.harvesterInstallVersion }, {}, UI_PLUGIN_NAMESPACE, 'install'); const extension = await waitForUIExtension(this.$store, HARVESTER_CHART.name); installed = await waitForUIPackage(this.$store, extension); } catch (error) { - } + } this.harvesterExtensionInstallError = !installed; @@ -265,6 +275,11 @@ export default { await this.setHarvesterUpdateVersion(); } + if (!this.harvesterUpdateVersion) { + btnCb(true); + + return; + } await installHelmChart(this.harvesterRepository, { ...HARVESTER_CHART, version: this.harvesterUpdateVersion }, {}, UI_PLUGIN_NAMESPACE, 'upgrade'); @@ -272,7 +287,7 @@ export default { updated = await waitForUIPackage(this.$store, { ...extension, version: this.harvesterUpdateVersion }); } catch (error) { - } + } this.harvesterExtensionUpdateError = !updated; @@ -413,7 +428,7 @@ export default { /> -