Skip to content

Commit

Permalink
Add supported chart version filter
Browse files Browse the repository at this point in the history
Signed-off-by: Francesco Torchia <francesco.torchia@suse.com>
  • Loading branch information
torchiaf committed Dec 10, 2024
1 parent 2e1e5b7 commit 9baa78c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
waitForUIExtension,
waitForUIPackage,
} from '@shell/utils/uiplugins';
import { isRancherPrime } from '@shell/config/version';
import { isRancherPrime, getVersionData } from '@shell/config/version';
const HARVESTER_REPO = isRancherPrime() ? HARVESTER_RANCHER_REPO : HARVESTER_COMMUNITY_REPO;
Expand Down Expand Up @@ -62,6 +62,7 @@ export default {
this.hciClusters = hash.hciClusters;
this.mgmtClusters = hash.mgmtClusters;
this.kubeVersion = hash.mgmtClusters.find((c) => c.id === 'local')?.kubernetesVersionBase || '';
this.harvesterRepository = await this.getHarvesterRepository();
},
Expand All @@ -78,6 +79,8 @@ export default {
realSchema: this.$store.getters['management/schemaFor'](CAPI.RANCHER_CLUSTER),
hciClusters: [],
mgmtClusters: [],
rancherVersion: getVersionData()?.Version || '',
kubeVersion: null,
harvesterRepository: null,
harvesterInstallVersion: true,
harvesterUpdateVersion: null,
Expand Down Expand Up @@ -218,7 +221,7 @@ export default {
async setHarvesterUpdateVersion() {
try {
const version = await getLatestExtensionVersion(this.$store, HARVESTER_CHART.name);
const version = await getLatestExtensionVersion(this.$store, HARVESTER_CHART.name, this.rancherVersion, this.kubeVersion);
if (semver.gt(version, this.harvester.extension.version)) {
this.harvesterUpdateVersion = version;
Expand All @@ -240,7 +243,7 @@ export default {
*/
await refreshHelmRepository(this.$store, HARVESTER_REPO.spec.gitRepo, HARVESTER_REPO.spec.gitBranch);
this.harvesterInstallVersion = await getLatestExtensionVersion(this.$store, HARVESTER_CHART.name);
this.harvesterInstallVersion = await getLatestExtensionVersion(this.$store, HARVESTER_CHART.name, this.rancherVersion, this.kubeVersion);
if (!this.harvesterInstallVersion) {
btnCb(false);
Expand Down
19 changes: 16 additions & 3 deletions shell/utils/uiplugins.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CATALOG as CATALOG_ANNOTATIONS } from '@shell/config/labels-annotations';
import { CATALOG } from '@shell/config/types';
import { UI_PLUGIN_BASE_URL } from '@shell/config/uiplugins';

Check failure on line 3 in shell/utils/uiplugins.ts

View workflow job for this annotation

GitHub Actions / lint

'/home/runner/work/dashboard/dashboard/shell/config/uiplugins.js' imported multiple times
import { isSupportedChartVersion } from '@shell/config/uiplugins';

Check failure on line 4 in shell/utils/uiplugins.ts

View workflow job for this annotation

GitHub Actions / lint

'/home/runner/work/dashboard/dashboard/shell/config/uiplugins.js' imported multiple times

const MAX_RETRIES = 10;
const RETRY_WAIT = 2500;
Expand All @@ -13,15 +14,27 @@ export type HelmChart = any;
*
* @param store Vue store
* @param chartName The chartName
* @param rancherVersion Rancher version
* @param kubeVersion K8s version
* @param opt Store options
* @returns The latest compatible version of the extension
* @returns The latest compatible version of the extension; return null If there are no compatible versions.
*/
export async function getLatestExtensionVersion(store: any, chartName: string, opt = { reset: true, force: true }) {
export async function getLatestExtensionVersion(
store: any,
chartName: string,
rancherVersion: string,
kubeVersion: string,
opt = { reset: true, force: true },
) {
await store.dispatch('catalog/load', opt);

const chart = store.getters['catalog/chart']({ chartName });

return chart?.versions?.[0]?.version;
const versions = chart?.versions || [];

const compatibleVersions = versions.filter((version: any) => isSupportedChartVersion({ version, rancherVersion, kubeVersion }));

Check warning on line 35 in shell/utils/uiplugins.ts

View workflow job for this annotation

GitHub Actions / lint

Expected a line break after this opening brace

Check warning on line 35 in shell/utils/uiplugins.ts

View workflow job for this annotation

GitHub Actions / lint

Expected a line break before this closing brace

return compatibleVersions[0]?.version;
}

/**
Expand Down

0 comments on commit 9baa78c

Please sign in to comment.