From 4f18f258a8471c26c72fd0c574ab91fbe5ff81e6 Mon Sep 17 00:00:00 2001 From: Jeffrey Tang Date: Mon, 11 Nov 2024 14:14:04 -0600 Subject: [PATCH 01/11] add timeout flag Signed-off-by: Jeffrey Tang --- examples/custom-network-config/Taskfile.yml | 22 ++++++++++++--------- src/commands/flags.ts | 11 +++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/examples/custom-network-config/Taskfile.yml b/examples/custom-network-config/Taskfile.yml index 5c76ab0ce..5f7ac5793 100644 --- a/examples/custom-network-config/Taskfile.yml +++ b/examples/custom-network-config/Taskfile.yml @@ -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" @@ -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 @@ -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}" --node-aliases-unparsed {{.node_identifiers}} --delete-pvcs --delete-secrets --force 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 diff --git a/src/commands/flags.ts b/src/commands/flags.ts index 99ead3899..cd42935c1 100644 --- a/src/commands/flags.ts +++ b/src/commands/flags.ts @@ -309,6 +309,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', @@ -789,6 +799,7 @@ export const allFlags: CommandFlag[] = [ ed25519PrivateKey, enableHederaExplorerTls, enablePrometheusSvcMonitor, + enableTimeout, endpointType, soloChartVersion, generateGossipKeys, From cc4aabc20bd2ee3e57b68ce4f104aa9239e65a4a Mon Sep 17 00:00:00 2001 From: Jeffrey Tang Date: Mon, 11 Nov 2024 19:09:18 -0600 Subject: [PATCH 02/11] check if timeout enabled Signed-off-by: Jeffrey Tang --- src/commands/network.ts | 91 +++++++++++++++++++++++++---------------- src/core/constants.ts | 1 + 2 files changed, 57 insertions(+), 35 deletions(-) diff --git a/src/commands/network.ts b/src/commands/network.ts index 05636d830..3bd932a37 100644 --- a/src/commands/network.ts +++ b/src/commands/network.ts @@ -24,11 +24,12 @@ import { constants, Templates } from '../core/index.ts' import * as prompts from './prompts.ts' import * as helpers from '../core/helpers.ts' import path from 'path' -import { addDebugOptions, validatePath } from '../core/helpers.ts' +import { addDebugOptions, sleep, validatePath } from '../core/helpers.ts' import fs from 'fs' import type { CertificateManager, KeyManager, PlatformInstaller, ProfileManager } from '../core/index.ts' import type { NodeAlias, NodeAliases } from '../types/aliases.ts' import type { Opts } from '../types/index.ts' +import { SECONDS } from '../core/constants.js' export interface NetworkDeployConfigClass { applicationEnv: string @@ -227,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 @@ -430,15 +458,16 @@ export class NetworkCommand extends BaseCommand { async destroy (argv: any) { const self = this const lease = self.leaseManager.instantiateLease() - interface Context { config: { deletePvcs: boolean deleteSecrets: boolean namespace: string + enableTimeout: boolean } + checkTimeout: boolean } - + let networkDestroySuccess = true const tasks = new Listr([ { title: 'Initialize', @@ -465,43 +494,34 @@ export class NetworkCommand extends BaseCommand { ctx.config = { deletePvcs: self.configManager.getFlag(flags.deletePvcs) as boolean, deleteSecrets: self.configManager.getFlag(flags.deleteSecrets) as boolean, - namespace: self.configManager.getFlag(flags.namespace) as string + namespace: self.configManager.getFlag(flags.namespace) as string, + enableTimeout: self.configManager.getFlag(flags.enableTimeout) as boolean, } + ctx.checkTimeout = ctx.config.deletePvcs && ctx.config.deleteSecrets && ctx.config.namespace && ctx.config.enableTimeout + this.logger.debug(`===== Loaded cached config === ${JSON.stringify(ctx.config)}`) + return lease.buildAcquireTask(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) - - if (secrets) { - for (const secret of secrets) { - await self.k8.deleteSecret(secret, ctx.config.namespace) - } + title: 'Running sub-tasks to destroy network', + task: async (ctx, task) => { + if (ctx.checkTimeout) { + const timeoutId = setTimeout(() => { + const message = `\n\nUnable to finish network destroy in ${constants.NETWORK_DESTROY_WAIT_TIMEOUT} seconds\n\n` + this.logger.error(message) + this.logger.showUser(chalk.red(message)) + networkDestroySuccess = false + }, constants.NETWORK_DESTROY_WAIT_TIMEOUT) + + await self.destroyTask(ctx, task) + + clearTimeout(timeoutId) + } else { + await self.destroyTask(ctx, task) } - }, - skip: (ctx) => !ctx.config.deleteSecrets + } } ], { concurrent: false, @@ -516,7 +536,7 @@ export class NetworkCommand extends BaseCommand { await lease.release() } - return true + return networkDestroySuccess } /** Run helm upgrade to refresh network components with new settings */ @@ -605,7 +625,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\' ===') diff --git a/src/core/constants.ts b/src/core/constants.ts index 58d1d9407..94d2e5fd8 100644 --- a/src/core/constants.ts +++ b/src/core/constants.ts @@ -180,3 +180,4 @@ 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 \ No newline at end of file From 3a38542e7393a0d9d364359132b81b04f50cd132 Mon Sep 17 00:00:00 2001 From: Jeffrey Tang Date: Mon, 11 Nov 2024 23:01:29 -0600 Subject: [PATCH 03/11] save Signed-off-by: Jeffrey Tang --- examples/custom-network-config/Taskfile.yml | 2 +- src/commands/network.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/custom-network-config/Taskfile.yml b/examples/custom-network-config/Taskfile.yml index 5f7ac5793..68f34f6fd 100644 --- a/examples/custom-network-config/Taskfile.yml +++ b/examples/custom-network-config/Taskfile.yml @@ -114,7 +114,7 @@ tasks: solo:network:destroy: internal: true cmds: - - solo network destroy --namespace "${SOLO_NAMESPACE}" --node-aliases-unparsed {{.node_identifiers}} --delete-pvcs --delete-secrets --force + - solo network destroy --namespace "${SOLO_NAMESPACE}" --node-aliases-unparsed {{.node_identifiers}} --delete-pvcs --delete-secrets --force --enable-timeout solo:node:start: internal: true diff --git a/src/commands/network.ts b/src/commands/network.ts index 3bd932a37..7eddbf1f9 100644 --- a/src/commands/network.ts +++ b/src/commands/network.ts @@ -513,6 +513,7 @@ export class NetworkCommand extends BaseCommand { this.logger.error(message) this.logger.showUser(chalk.red(message)) networkDestroySuccess = false + self.k8.deleteNamespace(ctx.config.namespace) }, constants.NETWORK_DESTROY_WAIT_TIMEOUT) await self.destroyTask(ctx, task) From 9bf7bc6c8e7af40aa56168090a50a21564c564b1 Mon Sep 17 00:00:00 2001 From: Jeffrey Tang Date: Mon, 11 Nov 2024 23:26:36 -0600 Subject: [PATCH 04/11] fix: timeout unit Signed-off-by: Jeffrey Tang --- examples/custom-network-config/Taskfile.yml | 2 +- src/commands/network.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/custom-network-config/Taskfile.yml b/examples/custom-network-config/Taskfile.yml index 68f34f6fd..86dcf5b0e 100644 --- a/examples/custom-network-config/Taskfile.yml +++ b/examples/custom-network-config/Taskfile.yml @@ -114,7 +114,7 @@ tasks: solo:network:destroy: internal: true cmds: - - solo network destroy --namespace "${SOLO_NAMESPACE}" --node-aliases-unparsed {{.node_identifiers}} --delete-pvcs --delete-secrets --force --enable-timeout + - solo network destroy --namespace "${SOLO_NAMESPACE}" --delete-pvcs --delete-secrets --force --enable-timeout solo:node:start: internal: true diff --git a/src/commands/network.ts b/src/commands/network.ts index 7eddbf1f9..35af7efd2 100644 --- a/src/commands/network.ts +++ b/src/commands/network.ts @@ -514,10 +514,10 @@ export class NetworkCommand extends BaseCommand { this.logger.showUser(chalk.red(message)) networkDestroySuccess = false self.k8.deleteNamespace(ctx.config.namespace) - }, constants.NETWORK_DESTROY_WAIT_TIMEOUT) + }, constants.NETWORK_DESTROY_WAIT_TIMEOUT * 1000) await self.destroyTask(ctx, task) - + clearTimeout(timeoutId) } else { await self.destroyTask(ctx, task) From d7b71f996b908f836b58c8258ab2f095c18bec26 Mon Sep 17 00:00:00 2001 From: JeffreyDallas <39912573+JeffreyDallas@users.noreply.github.com> Date: Tue, 19 Nov 2024 12:45:08 -0600 Subject: [PATCH 05/11] Update src/commands/network.ts Co-authored-by: Jeromy Cannon Signed-off-by: JeffreyDallas <39912573+JeffreyDallas@users.noreply.github.com> --- src/commands/network.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/commands/network.ts b/src/commands/network.ts index 35af7efd2..9795ddb57 100644 --- a/src/commands/network.ts +++ b/src/commands/network.ts @@ -498,7 +498,6 @@ export class NetworkCommand extends BaseCommand { enableTimeout: self.configManager.getFlag(flags.enableTimeout) as boolean, } - ctx.checkTimeout = ctx.config.deletePvcs && ctx.config.deleteSecrets && ctx.config.namespace && ctx.config.enableTimeout this.logger.debug(`===== Loaded cached config === ${JSON.stringify(ctx.config)}`) return lease.buildAcquireTask(task) From 4b83fa7588ed455d3ea4fb0d6b960bcea65aa605 Mon Sep 17 00:00:00 2001 From: JeffreyDallas <39912573+JeffreyDallas@users.noreply.github.com> Date: Tue, 19 Nov 2024 12:45:13 -0600 Subject: [PATCH 06/11] Update src/commands/network.ts Co-authored-by: Jeromy Cannon Signed-off-by: JeffreyDallas <39912573+JeffreyDallas@users.noreply.github.com> --- src/commands/network.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/network.ts b/src/commands/network.ts index 9795ddb57..46446e71d 100644 --- a/src/commands/network.ts +++ b/src/commands/network.ts @@ -506,7 +506,7 @@ export class NetworkCommand extends BaseCommand { { title: 'Running sub-tasks to destroy network', task: async (ctx, task) => { - if (ctx.checkTimeout) { + if (ctx.config.enableTimeout) { const timeoutId = setTimeout(() => { const message = `\n\nUnable to finish network destroy in ${constants.NETWORK_DESTROY_WAIT_TIMEOUT} seconds\n\n` this.logger.error(message) From 25f56c56812951a03c1307401125052ad820bf5e Mon Sep 17 00:00:00 2001 From: JeffreyDallas <39912573+JeffreyDallas@users.noreply.github.com> Date: Tue, 19 Nov 2024 12:45:29 -0600 Subject: [PATCH 07/11] Update src/commands/network.ts Co-authored-by: Jeromy Cannon Signed-off-by: JeffreyDallas <39912573+JeffreyDallas@users.noreply.github.com> --- src/commands/network.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/commands/network.ts b/src/commands/network.ts index 46446e71d..3e1bd34cc 100644 --- a/src/commands/network.ts +++ b/src/commands/network.ts @@ -496,6 +496,7 @@ export class NetworkCommand extends BaseCommand { deleteSecrets: self.configManager.getFlag(flags.deleteSecrets) as boolean, namespace: self.configManager.getFlag(flags.namespace) as string, enableTimeout: self.configManager.getFlag(flags.enableTimeout) as boolean, + force: self.configManager.getFlag(flags.force) as boolean, } this.logger.debug(`===== Loaded cached config === ${JSON.stringify(ctx.config)}`) From 46f1fff747962679901db3bbab00e9f5a4cef844 Mon Sep 17 00:00:00 2001 From: JeffreyDallas <39912573+JeffreyDallas@users.noreply.github.com> Date: Tue, 19 Nov 2024 12:45:48 -0600 Subject: [PATCH 08/11] Update src/commands/network.ts Co-authored-by: Jeromy Cannon Signed-off-by: JeffreyDallas <39912573+JeffreyDallas@users.noreply.github.com> --- src/commands/network.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/commands/network.ts b/src/commands/network.ts index 3e1bd34cc..5b9aefdb1 100644 --- a/src/commands/network.ts +++ b/src/commands/network.ts @@ -513,7 +513,9 @@ export class NetworkCommand extends BaseCommand { this.logger.error(message) this.logger.showUser(chalk.red(message)) networkDestroySuccess = false - self.k8.deleteNamespace(ctx.config.namespace) + if (ctx.config.deletePvcs && ctx.config.deleteSecrets && ctx.config.force) { + self.k8.deleteNamespace(ctx.config.namespace) + } }, constants.NETWORK_DESTROY_WAIT_TIMEOUT * 1000) await self.destroyTask(ctx, task) From ac54f49a4c9ed9f141dd51fc7f8d49f89962f5eb Mon Sep 17 00:00:00 2001 From: Jeffrey Tang Date: Tue, 19 Nov 2024 13:19:17 -0600 Subject: [PATCH 09/11] add force to config Signed-off-by: Jeffrey Tang --- src/commands/network.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/commands/network.ts b/src/commands/network.ts index 5b9aefdb1..9d381e2be 100644 --- a/src/commands/network.ts +++ b/src/commands/network.ts @@ -464,6 +464,7 @@ export class NetworkCommand extends BaseCommand { deleteSecrets: boolean namespace: string enableTimeout: boolean + force: boolean } checkTimeout: boolean } From c0dc00387838fbcedaef40f8a2f57791355103b8 Mon Sep 17 00:00:00 2001 From: JeffreyDallas <39912573+JeffreyDallas@users.noreply.github.com> Date: Fri, 22 Nov 2024 09:32:03 -0600 Subject: [PATCH 10/11] Update src/commands/network.ts Co-authored-by: Jeromy Cannon Signed-off-by: JeffreyDallas <39912573+JeffreyDallas@users.noreply.github.com> --- src/commands/network.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/network.ts b/src/commands/network.ts index 4d2a699a0..61a7f755e 100644 --- a/src/commands/network.ts +++ b/src/commands/network.ts @@ -510,8 +510,8 @@ export class NetworkCommand extends BaseCommand { if (ctx.config.enableTimeout) { const timeoutId = setTimeout(() => { const message = `\n\nUnable to finish network destroy in ${constants.NETWORK_DESTROY_WAIT_TIMEOUT} seconds\n\n` - this.logger.error(message) - this.logger.showUser(chalk.red(message)) + 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) From 8922e32e732ea181a1e6e15624d1c8760c960c80 Mon Sep 17 00:00:00 2001 From: Jeffrey Tang Date: Fri, 22 Nov 2024 14:57:12 -0600 Subject: [PATCH 11/11] remove extra line Signed-off-by: Jeffrey Tang --- examples/custom-network-config/Taskfile.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/custom-network-config/Taskfile.yml b/examples/custom-network-config/Taskfile.yml index 89f93f41a..3dd173f8f 100644 --- a/examples/custom-network-config/Taskfile.yml +++ b/examples/custom-network-config/Taskfile.yml @@ -11,7 +11,6 @@ env: SOLO_CLUSTER_SETUP_NAMESPACE: solo-setup SOLO_CLUSTER_RELEASE_NAME: solo-cluster-setup SOLO_NETWORK_SIZE: 7 - SOLO_CLUSTER_RELEASE_NAME: solo-cluster-setup SOLO_CLUSTER_NAME: solo-cluster MIRROR_RELEASE_NAME: mirror