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 15 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
22 changes: 13 additions & 9 deletions examples/custom-network-config/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ dotenv:
silent: false

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_CLUSTER_RELEASE_NAME: solo-cluster-setup
SOLO_NETWORK_SIZE: 7
SOLO_CLUSTER_NAME: solo-cluster
KIND_IMAGE: kindest/node:v1.27.3@sha256:3966ac761ae0136263ffdb6cfd4db23ef8a83cba8a463690e98317add2c9ba72
MIRROR_RELEASE_NAME: mirror

vars:
solo_settings_file: "{{.ROOT_DIR}}/settings.txt"
Expand Down Expand Up @@ -86,7 +90,7 @@ tasks:
#- test "$(yq -r '.flags."node-ids"' < {{ .solo_user_dir }}/solo.yaml)" == "{{ .node_identifiers }}"
- test "$(jq -r '.flags."node-ids"' < {{ .solo_user_dir }}/solo.config)" == "{{ .node_identifiers }}"
cmds:
- solo init --namespace "${SOLO_NAMESPACE}" --node-ids {{.node_identifiers}} --release-tag "${CONSENSUS_NODE_VERSION}" --cluster-setup-namespace "${SOLO_CLUSTER_SETUP_NAMESPACE}"
- solo init

solo:keys:
internal: true
Expand All @@ -99,23 +103,23 @@ tasks:
test -f {{ .solo_keys_dir }}/s-private-node${n}.pem
done
cmds:
- solo node keys --gossip-keys --tls-keys
- solo node keys --gossip-keys --tls-keys --node-aliases-unparsed {{.node_identifiers}}

solo:network:deploy:
internal: true
cmds:
- solo network deploy --release-tag "${CONSENSUS_NODE_VERSION}" --solo-chart-version "${SOLO_CHART_VERSION}" --values-file {{ .solo_values_file }} --settings-txt {{ .solo_settings_file }}
- solo node setup --release-tag "${CONSENSUS_NODE_VERSION}"
- solo network deploy --namespace "${SOLO_NAMESPACE}" --node-aliases-unparsed {{.node_identifiers}} --release-tag "${CONSENSUS_NODE_VERSION}" --solo-chart-version "${SOLO_CHART_VERSION}" --values-file {{ .solo_values_file }} --settings-txt {{ .solo_settings_file }}
- solo node setup --namespace "${SOLO_NAMESPACE}" --node-aliases-unparsed {{.node_identifiers}} --release-tag "${CONSENSUS_NODE_VERSION}"

solo:network:destroy:
internal: true
cmds:
- solo network destroy --namespace "${SOLO_NAMESPACE}" --delete-pvcs --delete-secrets --force
- solo network destroy --namespace "${SOLO_NAMESPACE}" --delete-pvcs --delete-secrets --force --enable-timeout

solo:node:start:
internal: true
cmds:
- solo node start --namespace "${SOLO_NAMESPACE}" {{ .CLI_ARGS }}
- solo node start --namespace "${SOLO_NAMESPACE}" --node-aliases-unparsed {{.node_identifiers}} {{ .CLI_ARGS }}

solo:node:stop:
internal: true
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 @@ -309,6 +309,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 @@ -821,6 +831,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 @@ 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,
JeffreyDallas marked this conversation as resolved.
Show resolved Hide resolved
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,5 +178,6 @@ 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'
Loading