Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add timeout flag to network destroy command #821

Merged
merged 18 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -22,8 +22,8 @@

/**
* Set flag from the flag option
* @param y instance of yargs

Check warning on line 25 in src/commands/flags.ts

View workflow job for this annotation

GitHub Actions / Code Style / Standard

tsdoc-param-tag-missing-hyphen: The @param block should be followed by a parameter name and then a hyphen
* @param commandFlags a set of command flags

Check warning on line 26 in src/commands/flags.ts

View workflow job for this annotation

GitHub Actions / Code Style / Standard

tsdoc-param-tag-missing-hyphen: The @param block should be followed by a parameter name and then a hyphen
*
*/
export function setCommandFlags (y: any, ...commandFlags: CommandFlag[]) {
Expand Down Expand Up @@ -319,6 +319,16 @@
}
}

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 @@
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 @@
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 @@
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 @@
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)

Check warning on line 519 in src/commands/network.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/network.ts#L511-L519

Added lines #L511 - L519 were not covered by tests

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

clearTimeout(timeoutId)

Check warning on line 523 in src/commands/network.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/network.ts#L521-L523

Added lines #L521 - L523 were not covered by tests
} else {
await self.destroyTask(ctx, task)
}
},
skip: (ctx) => !ctx.config.deleteSecrets
}
}
], {
concurrent: false,
Expand All @@ -517,7 +539,7 @@
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 @@
flags.deletePvcs,
flags.deleteSecrets,
flags.force,
flags.namespace
flags.namespace,
flags.enableTimeout

Check warning on line 632 in src/commands/network.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/network.ts#L631-L632

Added lines #L631 - L632 were not covered by tests
),
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'
Loading