Skip to content

Commit

Permalink
feat: add timeout flag to network destroy command (#821)
Browse files Browse the repository at this point in the history
Signed-off-by: Jeffrey Tang <[email protected]>
Signed-off-by: JeffreyDallas <[email protected]>
Co-authored-by: Jeromy Cannon <[email protected]>
  • Loading branch information
JeffreyDallas and jeromy-cannon authored Nov 25, 2024
1 parent 13ea46d commit 0fb570b
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 36 deletions.
8 changes: 4 additions & 4 deletions examples/custom-network-config/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ dotenv:
- .env

env:
SOLO_CHART_VERSION: v0.32.0
CONSENSUS_NODE_VERSION: v0.54.1
SOLO_NAMESPACE: solo-{{ env "USER" | replace "." "-" | trunc 63 }}
SOLO_CHART_VERSION: 0.34.0
CONSENSUS_NODE_VERSION: v0.56.0
SOLO_NAMESPACE: solo-{{ env "USER" | replace "." "-" | trunc 63 | default "test" }}
SOLO_CLUSTER_SETUP_NAMESPACE: solo-setup
SOLO_NETWORK_SIZE: 7
SOLO_CLUSTER_RELEASE_NAME: solo-cluster-setup
SOLO_NETWORK_SIZE: 7
SOLO_CLUSTER_NAME: solo-cluster
MIRROR_RELEASE_NAME: mirror

Expand Down
11 changes: 11 additions & 0 deletions src/commands/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,16 @@ export const generateTlsKeys: CommandFlag = {
}
}

export const enableTimeout: CommandFlag = {
constName: 'enableTimeout',
name: 'enable-timeout',
definition: {
describe: 'enable time out for running a command',
defaultValue: false,
type: 'boolean'
}
}

export const tlsClusterIssuerType: CommandFlag = {
constName: 'tlsClusterIssuerType',
name: 'tls-cluster-issuer-type',
Expand Down Expand Up @@ -842,6 +852,7 @@ export const allFlags: CommandFlag[] = [
ed25519PrivateKey,
enableHederaExplorerTls,
enablePrometheusSvcMonitor,
enableTimeout,
endpointType,
soloChartVersion,
generateGossipKeys,
Expand Down
87 changes: 55 additions & 32 deletions src/commands/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,33 @@ export class NetworkCommand extends BaseCommand {
return config
}

async destroyTask (ctx: any, task: any) {
const self = this
task.title = `Uninstalling chart ${constants.SOLO_DEPLOYMENT_CHART}`
await self.chartManager.uninstall(ctx.config.namespace, constants.SOLO_DEPLOYMENT_CHART)

if (ctx.config.deletePvcs) {
const pvcs = await self.k8.listPvcsByNamespace(ctx.config.namespace)
task.title = `Deleting PVCs in namespace ${ctx.config.namespace}`
if (pvcs) {
for (const pvc of pvcs) {
await self.k8.deletePvc(pvc, ctx.config.namespace)
}
}
}

if (ctx.config.deleteSecrets) {
task.title = `Deleting secrets in namespace ${ctx.config.namespace}`
const secrets = await self.k8.listSecretsByNamespace(ctx.config.namespace)

if (secrets) {
for (const secret of secrets) {
await self.k8.deleteSecret(secret, ctx.config.namespace)
}
}
}
}

/** Run helm install and deploy network components */
async deploy (argv: any) {
const self = this
Expand Down Expand Up @@ -437,9 +464,12 @@ export class NetworkCommand extends BaseCommand {
deletePvcs: boolean
deleteSecrets: boolean
namespace: string
enableTimeout: boolean
force: boolean
}
checkTimeout: boolean
}

let networkDestroySuccess = true
const tasks = new Listr<Context>([
{
title: 'Initialize',
Expand All @@ -466,43 +496,35 @@ export class NetworkCommand extends BaseCommand {
ctx.config = {
deletePvcs: self.configManager.getFlag<boolean>(flags.deletePvcs) as boolean,
deleteSecrets: self.configManager.getFlag<boolean>(flags.deleteSecrets) as boolean,
namespace: self.configManager.getFlag<string>(flags.namespace) as string
namespace: self.configManager.getFlag<string>(flags.namespace) as string,
enableTimeout: self.configManager.getFlag<boolean>(flags.enableTimeout) as boolean,
force: self.configManager.getFlag<boolean>(flags.force) as boolean,
}

return ListrLease.newAcquireLeaseTask(lease, task)
}
},
{
title: `Uninstall chart ${constants.SOLO_DEPLOYMENT_CHART}`,
task: async (ctx) => {
await self.chartManager.uninstall(ctx.config.namespace, constants.SOLO_DEPLOYMENT_CHART)
}
},
{
title: 'Delete PVCs',
task: async (ctx) => {
const pvcs = await self.k8.listPvcsByNamespace(ctx.config.namespace)

if (pvcs) {
for (const pvc of pvcs) {
await self.k8.deletePvc(pvc, ctx.config.namespace)
}
}
},
skip: (ctx) => !ctx.config.deletePvcs
},
{
title: 'Delete Secrets',
task: async (ctx) => {
const secrets = await self.k8.listSecretsByNamespace(ctx.config.namespace)
title: 'Running sub-tasks to destroy network',
task: async (ctx, task) => {
if (ctx.config.enableTimeout) {
const timeoutId = setTimeout(() => {
const message = `\n\nUnable to finish network destroy in ${constants.NETWORK_DESTROY_WAIT_TIMEOUT} seconds\n\n`
self.logger.error(message)
self.logger.showUser(chalk.red(message))
networkDestroySuccess = false
if (ctx.config.deletePvcs && ctx.config.deleteSecrets && ctx.config.force) {
self.k8.deleteNamespace(ctx.config.namespace)
}
}, constants.NETWORK_DESTROY_WAIT_TIMEOUT * 1000)

if (secrets) {
for (const secret of secrets) {
await self.k8.deleteSecret(secret, ctx.config.namespace)
}
await self.destroyTask(ctx, task)

clearTimeout(timeoutId)
} else {
await self.destroyTask(ctx, task)
}
},
skip: (ctx) => !ctx.config.deleteSecrets
}
}
], {
concurrent: false,
Expand All @@ -517,7 +539,7 @@ export class NetworkCommand extends BaseCommand {
await lease.release()
}

return true
return networkDestroySuccess
}

/** Run helm upgrade to refresh network components with new settings */
Expand Down Expand Up @@ -606,7 +628,8 @@ export class NetworkCommand extends BaseCommand {
flags.deletePvcs,
flags.deleteSecrets,
flags.force,
flags.namespace
flags.namespace,
flags.enableTimeout
),
handler: (argv: any) => {
networkCmd.logger.debug('==== Running \'network destroy\' ===')
Expand Down
1 change: 1 addition & 0 deletions src/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export const RELAY_PODS_RUNNING_DELAY = +process.env.RELAY_PODS_RUNNING_DELAY ||
export const RELAY_PODS_READY_MAX_ATTEMPTS = +process.env.RELAY_PODS_READY_MAX_ATTEMPTS || 100
export const RELAY_PODS_READY_DELAY = +process.env.RELAY_PODS_READY_DELAY || 1_000

export const NETWORK_DESTROY_WAIT_TIMEOUT = +process.env.NETWORK_DESTROY_WAIT_TIMEOUT || 120

export const DEFAULT_LOCAL_CONFIG_FILE = 'local-config.yaml'
export const IGNORED_NODE_ACCOUNT_ID = '0.0.0'

0 comments on commit 0fb570b

Please sign in to comment.