Skip to content

Commit

Permalink
chore: Relocate flags used for mirror node deployment (#583)
Browse files Browse the repository at this point in the history
Signed-off-by: Jeffrey Tang <jeffrey@swirldslabs.com>
  • Loading branch information
JeffreyDallas authored Sep 18, 2024
1 parent c92a49b commit 11880c5
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 104 deletions.
13 changes: 0 additions & 13 deletions src/commands/flags.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,6 @@ export const namespace = {
}
}

/** @type {CommandFlag} **/
export const deployMirrorNode = {
constName: 'deployMirrorNode',
name: 'mirror-node',
definition: {
describe: 'Deploy mirror node',
defaultValue: true,
alias: 'm',
type: 'boolean'
}
}

/** @type {CommandFlag} **/
export const deployHederaExplorer = {
constName: 'deployHederaExplorer',
Expand Down Expand Up @@ -789,7 +777,6 @@ export const allFlags = [
deployHederaExplorer,
deployJsonRpcRelay,
deployMinio,
deployMirrorNode,
deployPrometheusStack,
devMode,
ecdsaPrivateKey,
Expand Down
70 changes: 60 additions & 10 deletions src/commands/mirror_node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,62 @@ export class MirrorNodeCommand extends BaseCommand {
return [
flags.chartDirectory,
flags.deployHederaExplorer,
flags.enableHederaExplorerTls,
flags.fstChartVersion,
flags.hederaExplorerTlsHostName,
flags.hederaExplorerTlsLoadBalancerIp,
flags.namespace,
flags.profileFile,
flags.profileName,
flags.tlsClusterIssuerType,
flags.valuesFile
]
}

/**
* @param {string} valuesFile
* @param {boolean} deployHederaExplorer
* @param {string} tlsClusterIssuerType
* @param {boolean} enableHederaExplorerTls
* @param {string} namespace
* @param {string} hederaExplorerTlsLoadBalancerIp
* @param {string} hederaExplorerTlsHostName
* @returns {string}
*/
getTlsValueArguments (tlsClusterIssuerType, enableHederaExplorerTls, namespace, hederaExplorerTlsLoadBalancerIp, hederaExplorerTlsHostName) {
let valuesArg = ''

if (enableHederaExplorerTls) {
if (!['acme-staging', 'acme-prod', 'self-signed'].includes(tlsClusterIssuerType)) {
throw new Error(`Invalid TLS cluster issuer type: ${tlsClusterIssuerType}, must be one of: "acme-staging", "acme-prod", or "self-signed"`)
}

valuesArg += ' --set hedera-explorer.ingress.enabled=true'
valuesArg += ' --set cloud.haproxyIngressController.enabled=true'
valuesArg += ` --set global.ingressClassName=${namespace}-hedera-explorer-ingress-class`
valuesArg += ` --set-json 'hedera-explorer.ingress.hosts[0]={"host":"${hederaExplorerTlsHostName}","paths":[{"path":"/","pathType":"Prefix"}]}'`

if (hederaExplorerTlsLoadBalancerIp !== '') {
valuesArg += ` --set haproxy-ingress.controller.service.loadBalancerIP=${hederaExplorerTlsLoadBalancerIp}`
}

if (tlsClusterIssuerType === 'self-signed') {
valuesArg += ' --set cloud.selfSignedClusterIssuer.enabled=true'
} else {
valuesArg += ' --set cloud.acmeClusterIssuer.enabled=true'
valuesArg += ` --set hedera-explorer.certClusterIssuerType=${tlsClusterIssuerType}`
}
}

return valuesArg
}

/**
* @param {Object} config
* @returns {Promise<string>}
*/
async prepareValuesArg (valuesFile, deployHederaExplorer) {
async prepareValuesArg (config) {
let valuesArg = ''
if (valuesFile) {
valuesArg += this.prepareValuesFiles(valuesFile)
if (config.valuesFile) {
valuesArg += this.prepareValuesFiles(config.valuesFile)
}

const profileName = this.configManager.getFlag(flags.profileName)
Expand All @@ -77,7 +116,12 @@ export class MirrorNodeCommand extends BaseCommand {
valuesArg += this.prepareValuesFiles(profileValuesFile)
}

valuesArg += ` --set hedera-mirror-node.enabled=true --set hedera-explorer.enabled=${deployHederaExplorer}`
if (config.enableHederaExplorerTls) {
valuesArg += this.getTlsValueArguments(config.tlsClusterIssuerType, config.enableHederaExplorerTls, config.namespace,
config.hederaExplorerTlsLoadBalancerIp, config.hederaExplorerTlsHostName)
}

valuesArg += ` --set hedera-mirror-node.enabled=true --set hedera-explorer.enabled=${config.deployHederaExplorer}`
return valuesArg
}

Expand All @@ -97,7 +141,12 @@ export class MirrorNodeCommand extends BaseCommand {
// disable the prompts that we don't want to prompt the user for
prompts.disablePrompts([
flags.chartDirectory,
flags.deployHederaExplorer,
flags.enableHederaExplorerTls,
flags.fstChartVersion,
flags.hederaExplorerTlsHostName,
flags.hederaExplorerTlsLoadBalancerIp,
flags.tlsClusterIssuerType,
flags.valuesFile
])

Expand All @@ -108,10 +157,14 @@ export class MirrorNodeCommand extends BaseCommand {
* -- flags --
* @property {string} chartDirectory
* @property {boolean} deployHederaExplorer
* @property {string} enableHederaExplorerTls
* @property {string} fstChartVersion
* @property {string} hederaExplorerTlsHostName
* @property {string} hederaExplorerTlsLoadBalancerIp
* @property {string} namespace
* @property {string} profileFile
* @property {string} profileName
* @property {string} tlsClusterIssuerType
* @property {string} valuesFile
* -- extra args --
* @property {string} chartPath
Expand All @@ -130,10 +183,7 @@ export class MirrorNodeCommand extends BaseCommand {
ctx.config.chartPath = await self.prepareChartPath(ctx.config.chartDirectory,
constants.FULLSTACK_TESTING_CHART, constants.FULLSTACK_DEPLOYMENT_CHART)

ctx.config.valuesArg = await self.prepareValuesArg(
ctx.config.valuesFile,
ctx.config.deployHederaExplorer
)
ctx.config.valuesArg = await self.prepareValuesArg(ctx.config)

if (!await self.k8.hasNamespace(ctx.config.namespace)) {
throw new FullstackTestingError(`namespace ${ctx.config.namespace} does not exist`)
Expand Down
57 changes: 0 additions & 57 deletions src/commands/network.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,8 @@ export class NetworkCommand extends BaseCommand {
flags.cacheDir,
flags.chainId,
flags.chartDirectory,
flags.deployHederaExplorer,
flags.deployMirrorNode,
flags.enableHederaExplorerTls,
flags.enablePrometheusSvcMonitor,
flags.fstChartVersion,
flags.hederaExplorerTlsHostName,
flags.hederaExplorerTlsLoadBalancerIp,
flags.debugNodeId,
flags.log4j2Xml,
flags.namespace,
Expand All @@ -83,48 +78,10 @@ export class NetworkCommand extends BaseCommand {
flags.profileName,
flags.releaseTag,
flags.settingTxt,
flags.tlsClusterIssuerType,
flags.valuesFile
]
}

/**
* @param {string} tlsClusterIssuerType
* @param {boolean} enableHederaExplorerTls
* @param {string} namespace
* @param {string} hederaExplorerTlsLoadBalancerIp
* @param {string} hederaExplorerTlsHostName
* @returns {string}
*/
getTlsValueArguments (tlsClusterIssuerType, enableHederaExplorerTls, namespace,
hederaExplorerTlsLoadBalancerIp, hederaExplorerTlsHostName) {
let valuesArg = ''

if (enableHederaExplorerTls) {
if (!['acme-staging', 'acme-prod', 'self-signed'].includes(tlsClusterIssuerType)) {
throw new Error(`Invalid TLS cluster issuer type: ${tlsClusterIssuerType}, must be one of: "acme-staging", "acme-prod", or "self-signed"`)
}

valuesArg += ' --set hedera-explorer.ingress.enabled=true'
valuesArg += ' --set cloud.haproxyIngressController.enabled=true'
valuesArg += ` --set global.ingressClassName=${namespace}-hedera-explorer-ingress-class`
valuesArg += ` --set-json 'hedera-explorer.ingress.hosts[0]={"host":"${hederaExplorerTlsHostName}","paths":[{"path":"/","pathType":"Prefix"}]}'`

if (hederaExplorerTlsLoadBalancerIp !== '') {
valuesArg += ` --set haproxy-ingress.controller.service.loadBalancerIP=${hederaExplorerTlsLoadBalancerIp}`
}

if (tlsClusterIssuerType === 'self-signed') {
valuesArg += ' --set cloud.selfSignedClusterIssuer.enabled=true'
} else {
valuesArg += ' --set cloud.acmeClusterIssuer.enabled=true'
valuesArg += ` --set hedera-explorer.certClusterIssuerType=${tlsClusterIssuerType}`
}
}

return valuesArg
}

/**
* @param {Object} config
* @returns {Promise<string>}
Expand Down Expand Up @@ -160,11 +117,6 @@ export class NetworkCommand extends BaseCommand {
valuesArg += ' --set "hedera-mirror-node.enabled=false" --set "hedera-explorer.enabled=false"'
valuesArg += ` --set "telemetry.prometheus.svcMonitor.enabled=${config.enablePrometheusSvcMonitor}"`

if (config.enableHederaExplorerTls) {
valuesArg += this.getTlsValueArguments(config.tlsClusterIssuerType, config.enableHederaExplorerTls, config.namespace,
config.hederaExplorerTlsLoadBalancerIp, config.hederaExplorerTlsHostName)
}

if (config.releaseTag) {
const rootImage = helpers.getRootImageRepository(config.releaseTag)
valuesArg += ` --set "defaults.root.image.repository=${rootImage}"`
Expand Down Expand Up @@ -195,9 +147,6 @@ export class NetworkCommand extends BaseCommand {
flags.cacheDir,
flags.chainId,
flags.debugNodeId,
flags.deployHederaExplorer,
flags.deployMirrorNode,
flags.hederaExplorerTlsLoadBalancerIp,
flags.log4j2Xml,
flags.persistentVolumeClaims,
flags.profileName,
Expand All @@ -213,20 +162,14 @@ export class NetworkCommand extends BaseCommand {
* @property {string} applicationEnv
* @property {string} cacheDir
* @property {string} chartDirectory
* @property {boolean} deployHederaExplorer
* @property {boolean} deployMirrorNode
* @property {boolean} enableHederaExplorerTls
* @property {boolean} enablePrometheusSvcMonitor
* @property {string} fstChartVersion
* @property {string} hederaExplorerTlsHostName
* @property {string} hederaExplorerTlsLoadBalancerIp
* @property {string} namespace
* @property {string} nodeIDs
* @property {string} persistentVolumeClaims
* @property {string} profileFile
* @property {string} profileName
* @property {string} releaseTag
* @property {string} tlsClusterIssuerType
* -- extra args --
* @property {string} chartPath
* @property {string} keysDir
Expand Down
9 changes: 0 additions & 9 deletions src/commands/prompts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,6 @@ export async function promptDeployCertManagerCrds (task, input) {
flags.deployCertManagerCrds.name)
}

export async function promptDeployMirrorNode (task, input) {
return await promptToggle(task, input,
flags.deployMirrorNode.definition.defaultValue,
'Would you like to deploy Hedera Mirror Node? ',
null,
flags.deployMirrorNode.name)
}

export async function promptDeployHederaExplorer (task, input) {
return await promptToggle(task, input,
flags.deployHederaExplorer.definition.defaultValue,
Expand Down Expand Up @@ -446,7 +438,6 @@ export function getPromptMap () {
.set(flags.deployCertManagerCrds.name, promptDeployCertManagerCrds)
.set(flags.deployHederaExplorer.name, promptDeployHederaExplorer)
.set(flags.deployMinio.name, promptDeployMinio)
.set(flags.deployMirrorNode.name, promptDeployMirrorNode)
.set(flags.deployPrometheusStack.name, promptDeployPrometheusStack)
.set(flags.enableHederaExplorerTls.name, promptEnableHederaExplorerTls)
.set(flags.enablePrometheusSvcMonitor.name, promptEnablePrometheusSvcMonitor)
Expand Down
3 changes: 1 addition & 2 deletions src/core/k8.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,7 @@ export class K8 {
* @param {string} containerName
* @param {string} destPath - path inside the container
* @param {number} [timeout] - timeout in ms
* @returns {Promise<{owner: string, size: number, modifiedAt: string, name: string, directory: boolean, group: string}[]>}
* array of directory entries, custom object
* @returns a promise that returns array of directory entries, custom object
*/
async listDir (podName, containerName, destPath, timeout = 5000) {
try {
Expand Down
5 changes: 4 additions & 1 deletion test/e2e/commands/mirror_node.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,11 @@ describe('MirrorNodeCommand', () => {
}

expect(mirrorNodeCmd.getUnusedConfigs(MirrorNodeCommand.DEPLOY_CONFIGS_NAME)).toEqual([
flags.hederaExplorerTlsHostName.constName,
flags.hederaExplorerTlsLoadBalancerIp.constName,
flags.profileFile.constName,
flags.profileName.constName
flags.profileName.constName,
flags.tlsClusterIssuerType.constName
])
}, 600000)

Expand Down
7 changes: 1 addition & 6 deletions test/e2e/commands/network.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,10 @@ describe('NetworkCommand', () => {
flags.applicationProperties.constName,
flags.bootstrapProperties.constName,
flags.chainId.constName,
flags.deployHederaExplorer.constName,
flags.deployMirrorNode.constName,
flags.hederaExplorerTlsHostName.constName,
flags.hederaExplorerTlsLoadBalancerIp.constName,
flags.log4j2Xml.constName,
flags.profileFile.constName,
flags.profileName.constName,
flags.settingTxt.constName,
flags.tlsClusterIssuerType.constName
flags.settingTxt.constName
])
} catch (e) {
networkCmd.logger.showUserError(e)
Expand Down
7 changes: 1 addition & 6 deletions test/test_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,10 @@ export function bootstrapNetwork (testName, argv,
flags.applicationProperties.constName,
flags.bootstrapProperties.constName,
flags.chainId.constName,
flags.deployHederaExplorer.constName,
flags.deployMirrorNode.constName,
flags.hederaExplorerTlsHostName.constName,
flags.hederaExplorerTlsLoadBalancerIp.constName,
flags.log4j2Xml.constName,
flags.profileFile.constName,
flags.profileName.constName,
flags.settingTxt.constName,
flags.tlsClusterIssuerType.constName
flags.settingTxt.constName
])
}, 180000)

Expand Down

0 comments on commit 11880c5

Please sign in to comment.