From 1c59ff100eb01144bcebd1c15dfccba9e9c9312b Mon Sep 17 00:00:00 2001 From: instamenta Date: Thu, 19 Sep 2024 13:57:26 +0300 Subject: [PATCH] Add '--mirror-node-version' flag to override default mirror node version Signed-off-by: instamenta --- src/commands/flags.mjs | 13 ++++++++++++- src/commands/mirror_node.mjs | 11 +++++++++-- src/commands/prompts.mjs | 9 +++++++++ src/core/chart_manager.mjs | 28 ++++++++++++++++++---------- 4 files changed, 48 insertions(+), 13 deletions(-) diff --git a/src/commands/flags.mjs b/src/commands/flags.mjs index cc4f290a2..a9bb67466 100644 --- a/src/commands/flags.mjs +++ b/src/commands/flags.mjs @@ -755,6 +755,16 @@ export const adminKey = { } } +/** @type {CommandFlag} **/ +export const mirrorNodeVersion = { + constName: 'mirrorNodeVersion', + name: 'mirror-node-version', + definition: { + describe: 'Mirror node chart version', + defaultValue: '', + type: 'string' + } +} /** @type {CommandFlag[]} **/ export const allFlags = [ accountId, @@ -815,7 +825,8 @@ export const allFlags = [ tlsPrivateKey, tlsPublicKey, updateAccountKeys, - valuesFile + valuesFile, + mirrorNodeVersion ] /** diff --git a/src/commands/mirror_node.mjs b/src/commands/mirror_node.mjs index 80901fd4f..58bc18b9b 100644 --- a/src/commands/mirror_node.mjs +++ b/src/commands/mirror_node.mjs @@ -60,7 +60,8 @@ export class MirrorNodeCommand extends BaseCommand { flags.profileFile, flags.profileName, flags.tlsClusterIssuerType, - flags.valuesFile + flags.valuesFile, + flags.mirrorNodeVersion ] } @@ -121,6 +122,10 @@ export class MirrorNodeCommand extends BaseCommand { config.hederaExplorerTlsLoadBalancerIp, config.hederaExplorerTlsHostName) } + if (config.mirrorNodeVersion) { + valuesArg += ` --set global.image.tag=${config.mirrorNodeVersion}` + } + valuesArg += ` --set hedera-mirror-node.enabled=true --set hedera-explorer.enabled=${config.deployHederaExplorer}` return valuesArg } @@ -147,7 +152,8 @@ export class MirrorNodeCommand extends BaseCommand { flags.hederaExplorerTlsHostName, flags.hederaExplorerTlsLoadBalancerIp, flags.tlsClusterIssuerType, - flags.valuesFile + flags.valuesFile, + flags.mirrorNodeVersion ]) await prompts.execute(task, self.configManager, MirrorNodeCommand.DEPLOY_FLAGS_LIST) @@ -169,6 +175,7 @@ export class MirrorNodeCommand extends BaseCommand { * -- extra args -- * @property {string} chartPath * @property {string} valuesArg + * @property {string} mirrorNodeVersion * -- methods -- * @property {getUnusedConfigs} getUnusedConfigs */ diff --git a/src/commands/prompts.mjs b/src/commands/prompts.mjs index 59cdcc838..69c134b26 100644 --- a/src/commands/prompts.mjs +++ b/src/commands/prompts.mjs @@ -421,6 +421,14 @@ export async function promptPersistentVolumeClaims (task, input) { flags.persistentVolumeClaims.name) } +export async function promptMirrorNodeVersion (task, input) { + return await promptToggle(task, input, + flags.mirrorNodeVersion.definition.defaultValue, + 'Would you like to choose mirror node version? ', + null, + flags.mirrorNodeVersion.name) +} + /** * @returns {Map} */ @@ -464,6 +472,7 @@ export function getPromptMap () { .set(flags.gossipEndpoints.name, promptGossipEndpoints) .set(flags.grpcEndpoints.name, promptGrpcEndpoints) .set(flags.endpointType.name, promptEndpointType) + .set(flags.mirrorNodeVersion.name, promptMirrorNodeVersion) } // build the prompt registry diff --git a/src/core/chart_manager.mjs b/src/core/chart_manager.mjs index f97c8bb20..a6cbc2bf6 100644 --- a/src/core/chart_manager.mjs +++ b/src/core/chart_manager.mjs @@ -39,28 +39,36 @@ export class ChartManager { * * @param {Map} repoURLs - a map of name and chart repository URLs * @param {boolean} force - whether or not to update the repo - * @returns {Promise} + * @returns {Promise} - returns the urls */ async setup (repoURLs = constants.DEFAULT_CHART_REPO, force = true) { try { - let forceUpdateArg = '' - if (force) { - forceUpdateArg = '--force-update' - } + const forceUpdateArg = force ? '--force-update' : '' - const urls = [] + /** @type {Array>} */ + const promises = [] for (const [name, url] of repoURLs.entries()) { - this.logger.debug(`Adding repo ${name} -> ${url}`, { repoName: name, repoURL: url }) - await this.helm.repo('add', name, url, forceUpdateArg) - urls.push(url) + promises.push(this.addRepo(name, url, forceUpdateArg)) } - return urls + return await Promise.all(promises) // urls } catch (e) { throw new FullstackTestingError(`failed to setup chart repositories: ${e.message}`, e) } } + /** + * @param {string} name + * @param {string} url + * @param {string} forceUpdateArg + * @returns {Promise} + */ + async addRepo (name, url, forceUpdateArg) { + this.logger.debug(`Adding repo ${name} -> ${url}`, { repoName: name, repoURL: url }) + await this.helm.repo('add', name, url, forceUpdateArg) + return url + } + /** * List available clusters * @param {string} namespaceName