Skip to content

Commit

Permalink
fix: rename chart command to network
Browse files Browse the repository at this point in the history
Signed-off-by: Lenin Mehedy <lenin.mehedy@swirldslabs.com>
  • Loading branch information
leninmehedy committed Jan 24, 2024
1 parent b2250cb commit c5fd507
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 35 deletions.
1 change: 0 additions & 1 deletion fullstack-network-manager/src/commands/flags.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ export const allFlags = [
relayReleaseTag,
cacheDir,
nodeIDs,
force,
chartDirectory,
replicaCount,
chainId,
Expand Down
6 changes: 3 additions & 3 deletions fullstack-network-manager/src/commands/index.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ClusterCommand } from './cluster.mjs'
import { InitCommand } from './init.mjs'
import { ChartCommand } from './chart.mjs'
import { NetworkCommand } from './network.mjs'
import { NodeCommand } from './node.mjs'
import { RelayCommand } from './relay.mjs'
import * as flags from './flags.mjs'
Expand All @@ -12,14 +12,14 @@ import * as flags from './flags.mjs'
function Initialize (opts) {
const initCmd = new InitCommand(opts)
const clusterCmd = new ClusterCommand(opts)
const chartCmd = new ChartCommand(opts)
const networkCommand = new NetworkCommand(opts)
const nodeCmd = new NodeCommand(opts)
const relayCmd = new RelayCommand(opts)

return [
InitCommand.getCommandDefinition(initCmd),
ClusterCommand.getCommandDefinition(clusterCmd),
ChartCommand.getCommandDefinition(chartCmd),
NetworkCommand.getCommandDefinition(networkCommand),
NodeCommand.getCommandDefinition(nodeCmd),
RelayCommand.getCommandDefinition(relayCmd)
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ListrEnquirerPromptAdapter } from '@listr2/prompt-adapter-enquirer'
import chalk from 'chalk'
import { Listr } from 'listr2'
import { FullstackTestingError } from '../core/errors.mjs'
Expand All @@ -7,7 +8,7 @@ import * as paths from 'path'
import { constants, Templates } from '../core/index.mjs'
import * as prompts from './prompts.mjs'

export class ChartCommand extends BaseCommand {
export class NetworkCommand extends BaseCommand {
getTlsValueArguments (enableTls, tlsClusterIssuerName, tlsClusterIssuerNamespace, enableHederaExplorerTls) {
const gatewayPrefix = 'gatewayApi.gateway'
let valuesArg = ` --set ${gatewayPrefix}.tlsEnabled=${enableTls}`
Expand Down Expand Up @@ -102,7 +103,12 @@ export class ChartCommand extends BaseCommand {
return config
}

async install (argv) {
/**
* Run helm install and deploy network components
* @param argv
* @return {Promise<boolean>}
*/
async deploy (argv) {
const self = this

const tasks = new Listr([
Expand Down Expand Up @@ -167,13 +173,30 @@ export class ChartCommand extends BaseCommand {
return true
}

async uninstall (argv) {
/**
* Run helm uninstall and destroy network components
* @param argv
* @return {Promise<boolean>}
*/
async destroy (argv) {
const self = this

const tasks = new Listr([
{
title: 'Initialize',
task: async (ctx, task) => {
if (!argv.force) {
const confirm = await task.prompt(ListrEnquirerPromptAdapter).run({
type: 'toggle',
default: false,
message: 'Are you sure you would like to destroy the network components?'
})

if (!confirm) {
process.exit(0)
}
}

self.configManager.load(argv)
const namespace = self.configManager.getFlag(flags.namespace)
ctx.config = {
Expand Down Expand Up @@ -201,7 +224,12 @@ export class ChartCommand extends BaseCommand {
return true
}

async upgrade (argv) {
/**
* Run helm upgrade to refresh network components with new settings
* @param argv
* @return {Promise<boolean>}
*/
async refresh (argv) {
const self = this

const tasks = new Listr([
Expand Down Expand Up @@ -243,15 +271,15 @@ export class ChartCommand extends BaseCommand {
return true
}

static getCommandDefinition (chartCmd) {
static getCommandDefinition (networkCmd) {
return {
command: 'chart',
desc: 'Manage chart deployment',
command: 'network',
desc: 'Manage fullstack testing network deployment',
builder: yargs => {
return yargs
.command({
command: 'install',
desc: 'Install network deployment chart',
command: 'deploy',
desc: 'Deploy fullstack testing network',
builder: y => {
flags.setCommandFlags(y,
flags.namespace,
Expand All @@ -270,40 +298,40 @@ export class ChartCommand extends BaseCommand {
)
},
handler: argv => {
chartCmd.logger.debug("==== Running 'chart install' ===")
chartCmd.logger.debug(argv)
networkCmd.logger.debug("==== Running 'network deploy' ===")
networkCmd.logger.debug(argv)

chartCmd.install(argv).then(r => {
chartCmd.logger.debug('==== Finished running `chart install`====')
networkCmd.deploy(argv).then(r => {
networkCmd.logger.debug('==== Finished running `network deploy`====')

if (!r) process.exit(1)
}).catch(err => {
chartCmd.logger.showUserError(err)
networkCmd.logger.showUserError(err)
process.exit(1)
})
}
})
.command({
command: 'uninstall',
desc: 'Uninstall network deployment chart',
builder: y => flags.setCommandFlags(y, flags.namespace),
command: 'destroy',
desc: 'Destroy fullstack testing network',
builder: y => flags.setCommandFlags(y, flags.namespace, flags.force),
handler: argv => {
chartCmd.logger.debug("==== Running 'chart uninstall' ===")
chartCmd.logger.debug(argv)
networkCmd.logger.debug("==== Running 'network destroy' ===")
networkCmd.logger.debug(argv)

chartCmd.uninstall(argv).then(r => {
chartCmd.logger.debug('==== Finished running `chart uninstall`====')
networkCmd.destroy(argv).then(r => {
networkCmd.logger.debug('==== Finished running `network destroy`====')

if (!r) process.exit(1)
}).catch(err => {
chartCmd.logger.showUserError(err)
networkCmd.logger.showUserError(err)
process.exit(1)
})
}
})
.command({
command: 'upgrade',
desc: 'Refresh existing network deployment with new values',
command: 'refresh',
desc: 'Refresh fullstack testing network deployment',
builder: y => flags.setCommandFlags(y,
flags.namespace,
flags.deployMirrorNode,
Expand All @@ -318,15 +346,15 @@ export class ChartCommand extends BaseCommand {
flags.selfSignedClusterIssuer
),
handler: argv => {
chartCmd.logger.debug("==== Running 'chart upgrade' ===")
chartCmd.logger.debug(argv)
networkCmd.logger.debug("==== Running 'chart upgrade' ===")
networkCmd.logger.debug(argv)

chartCmd.upgrade(argv).then(r => {
chartCmd.logger.debug('==== Finished running `chart upgrade`====')
networkCmd.refresh(argv).then(r => {
networkCmd.logger.debug('==== Finished running `chart upgrade`====')

if (!r) process.exit(1)
}).catch(err => {
chartCmd.logger.showUserError(err)
networkCmd.logger.showUserError(err)
process.exit(1)
})
}
Expand Down
9 changes: 7 additions & 2 deletions fullstack-network-manager/src/core/config_manager.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ export class ConfigManager {

// extract flags from argv
if (argv) {
flagList.forEach(flag => {
for (const flag of flagList) {
// we don't want to cache force flag
if (flag.name === 'force') {
continue
}

if (argv && argv[flag.name]) {
let val = argv[flag.name]
if (val && flag.name === flags.chartDirectory.name) {
Expand All @@ -72,7 +77,7 @@ export class ConfigManager {
}
writeConfig = true
}
})
}

// store last command that was run
if (argv._) {
Expand Down

0 comments on commit c5fd507

Please sign in to comment.