Fix isSupportedHarvester

Signed-off-by: Francesco Torchia <francesco.torchia@suse.com>
This commit is contained in:
Francesco Torchia 2024-11-11 19:53:50 +01:00
parent 021a64a5ec
commit fa4ee3ea27
No known key found for this signature in database
GPG Key ID: E6D011B7415D4393
2 changed files with 36 additions and 41 deletions

View File

@ -38,25 +38,6 @@ export default {
this.hciClusters = hash.hciClusters; this.hciClusters = hash.hciClusters;
this.mgmtClusters = hash.mgmtClusters; this.mgmtClusters = hash.mgmtClusters;
for (const cluster of this.mgmtClusters) {
const clusterId = cluster.id;
if (clusterId === 'local') {
continue;
}
if (clusterId) {
try {
const settingUrl = `/k8s/clusters/${ clusterId }/v1/harvester/${ HCI.SETTING }s?exclude=metadata.managedFields`;
const r = await this.$store.dispatch('request', { url: settingUrl, method: 'get' });
console.log('🚀 ~ fetch ~r = ', r);
} catch (e) {
console.info(`Failed to fetch harvester setting from ${ clusterId }, error=${ e }`); // eslint-disable-line no-console
}
}
}
}, },
data() { data() {
@ -92,11 +73,18 @@ export default {
}, },
rows() { rows() {
return this.hciClusters.filter((c) => { return this.hciClusters
const cluster = this.mgmtClusters.find((cluster) => cluster?.metadata?.name === c?.status?.clusterName); .filter((c) => {
const cluster = this.mgmtClusters.find((cluster) => cluster?.metadata?.name === c?.status?.clusterName);
return isHarvesterCluster(cluster); return isHarvesterCluster(cluster);
}); })
.map((row) => {
if (row.isReady) {
row.setSupportedHarvesterVersion();
}
return row;
});
}, },
typeDisplay() { typeDisplay() {
@ -164,7 +152,7 @@ export default {
<td> <td>
<span class="cluster-link"> <span class="cluster-link">
<a <a
v-if="row.isReady && row.isSupportedHarvesterVersion" v-if="row.isReady && row.isSupportedHarvester"
class="link" class="link"
:disabled="navigating ? true : null" :disabled="navigating ? true : null"
@click="goToCluster(row)" @click="goToCluster(row)"

View File

@ -2,13 +2,17 @@ import ProvCluster from '@shell/models/provisioning.cattle.io.cluster';
import { DEFAULT_WORKSPACE, HCI, MANAGEMENT } from '@shell/config/types'; import { DEFAULT_WORKSPACE, HCI, MANAGEMENT } from '@shell/config/types';
import { HARVESTER_NAME, HARVESTER_NAME as VIRTUAL } from '@shell/config/features'; import { HARVESTER_NAME, HARVESTER_NAME as VIRTUAL } from '@shell/config/features';
import { SETTING } from '@shell/config/settings'; import { SETTING } from '@shell/config/settings';
import semver from 'semver';
import { serverVersion } from '../utils/feature-flags';
import { colorForState, stateDisplay, STATES_ENUM } from '@shell/plugins/dashboard-store/resource-class'; import { colorForState, stateDisplay, STATES_ENUM } from '@shell/plugins/dashboard-store/resource-class';
export default class HciCluster extends ProvCluster { export default class HciCluster extends ProvCluster {
_isSupportedHarvester = undefined;
get isSupportedHarvester() {
return this._isSupportedHarvester === undefined ? true : this._isSupportedHarvester;
}
get stateObj() { get stateObj() {
if (!this.isSupportedHarvesterVersion) { if (!this.isSupportedHarvester) {
return { error: true, message: this.t('harvesterManager.cluster.supportMessage') }; return { error: true, message: this.t('harvesterManager.cluster.supportMessage') };
} }
@ -37,7 +41,7 @@ export default class HciCluster extends ProvCluster {
} }
get stateColor() { get stateColor() {
if (!this.isSupportedHarvesterVersion) { if (!this.isSupportedHarvester) {
return colorForState(STATES_ENUM.DENIED); return colorForState(STATES_ENUM.DENIED);
} }
@ -45,25 +49,13 @@ export default class HciCluster extends ProvCluster {
} }
get stateDisplay() { get stateDisplay() {
if (!this.isSupportedHarvesterVersion) { if (!this.isSupportedHarvester) {
return stateDisplay(STATES_ENUM.DENIED); return stateDisplay(STATES_ENUM.DENIED);
} }
return stateDisplay(this.state); return stateDisplay(this.state);
} }
/**
* harvester ui extension only supports harvester cluster version >= 1.3.0
*/
get isSupportedHarvesterVersion() {
const version = serverVersion(this.$rootGetters);
// eslint-disable-next-line no-console
console.log('🚀 ~ HciCluster ~ getisSupportedHarvesterVersion ~ version:', version);
return semver.gte(version, '1.3.0');
}
/** /**
* Fetch and cache the response for /ui-info * Fetch and cache the response for /ui-info
* *
@ -209,4 +201,19 @@ export default class HciCluster extends ProvCluster {
} }
}); });
} }
async setSupportedHarvesterVersion() {
if (this._isSupportedHarvester !== undefined) {
return;
}
const url = `/k8s/clusters/${ this.status.clusterName }/v1`;
try {
const setting = await this.$dispatch('request', { url: `${ url }/${ HCI.SETTING }s/server-version` });
this._isSupportedHarvester = this.$rootGetters['harvester-common/getFeatureEnabled']('supportHarvesterClusterVersion', setting?.value);
} catch (error) {
}
}
} }