Skip to content

Commit

Permalink
fix: add flag for fsnetman to delete PVCs on uninstall (#693)
Browse files Browse the repository at this point in the history
Signed-off-by: Jeromy Cannon <jeromy@swirldslabs.com>
  • Loading branch information
jeromy-cannon committed Jan 25, 2024
1 parent b2250cb commit 13b423a
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 9 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/zxc-compile-code.yaml
@@ -1,5 +1,5 @@
##
# Copyright (C) 2023 Hedera Hashgraph, LLC
# Copyright (C) 2023-2024 Hedera Hashgraph, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -118,12 +118,20 @@ jobs:
with:
node-version: ${{ inputs.node-version }}

- name: Docker Prune
id: docker-prune
if: ${{ inputs.enable-unit-tests && !cancelled() && !failure() }}
run: |
docker system prune -f
docker image prune -f
- name: Setup Kind
uses: helm/kind-action@dda0770415bac9fc20092cacbc54aa298604d140 # v1.8.0
if: ${{ inputs.enable-unit-tests && !cancelled() && !failure() }}
with:
node_image: kindest/node:v1.27.3@sha256:3966ac761ae0136263ffdb6cfd4db23ef8a83cba8a463690e98317add2c9ba72
config: dev/dev-cluster.yaml
version: v0.19.0
version: v0.20.0
verbosity: 3
wait: 120s

Expand Down
13 changes: 12 additions & 1 deletion .github/workflows/zxc-fsnetman-tests.yaml
Expand Up @@ -86,12 +86,20 @@ jobs:
with:
node-version: ${{ inputs.node-version }}

- name: Docker Prune
id: docker-prune
if: ${{ steps.check-changed-files.outputs.run-tests && !cancelled() && !failure() }}
run: |
docker system prune -f
docker image prune -f
- name: Setup Kind
uses: helm/kind-action@dda0770415bac9fc20092cacbc54aa298604d140 # v1.8.0
if: ${{ steps.check-changed-files.outputs.run-tests && !cancelled() && !failure() }}
with:
node_image: kindest/node:v1.27.3@sha256:3966ac761ae0136263ffdb6cfd4db23ef8a83cba8a463690e98317add2c9ba72
config: dev/dev-cluster.yaml
version: v0.19.0
version: v0.20.0
verbosity: 3
wait: 120s

Expand Down Expand Up @@ -127,6 +135,9 @@ jobs:
run: |
npm i
npm link
kind delete cluster -n chart-testing || true
docker system prune -f
docker image prune -f
./test/e2e/setup-e2e.sh
npm run test-e2e
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/zxc-helm-chart-tests.yaml
@@ -1,5 +1,5 @@
##
# Copyright (C) 2023 Hedera Hashgraph, LLC
# Copyright (C) 2023-2024 Hedera Hashgraph, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -96,12 +96,20 @@ jobs:
# the fetch depth defaults to only the commit that triggered the workflow unless the spotless check was enabled
fetch-depth: ${{ inputs.enable-spotless-check && '0' || '' }}

- name: Docker Prune
id: docker-prune
if: ${{ steps.check-changed-files.outputs.run-tests && !cancelled() && !failure() }}
run: |
docker system prune -f
docker image prune -f
- name: Setup Kind
uses: helm/kind-action@dda0770415bac9fc20092cacbc54aa298604d140 # v1.8.0
if: ${{ steps.check-changed-files.outputs.run-tests && !cancelled() && !failure() }}
with:
node_image: kindest/node:v1.27.3@sha256:3966ac761ae0136263ffdb6cfd4db23ef8a83cba8a463690e98317add2c9ba72
config: dev/dev-cluster.yaml
version: v0.19.0
version: v0.20.0
verbosity: 3
wait: 120s

Expand Down
2 changes: 1 addition & 1 deletion fullstack-network-manager/README.md
@@ -1,6 +1,6 @@
# Full Stack Network Manager CLI

Full Stack Network Manager (fsnetman) is a CLI tool to manage and deploy a Hedera Network using the FS Helm Chart.
Full Stack Network Manager (fsnetman) is a CLI tool to manage and deploy a Hedera Network using the FS Helm Charts.

## Install

Expand Down
27 changes: 25 additions & 2 deletions fullstack-network-manager/src/commands/chart.mjs
Expand Up @@ -176,8 +176,10 @@ export class ChartCommand extends BaseCommand {
task: async (ctx, task) => {
self.configManager.load(argv)
const namespace = self.configManager.getFlag(flags.namespace)
const deletePvcs = self.configManager.getFlag(flags.deletePvcs)
ctx.config = {
namespace: await prompts.promptNamespaceArg(task, namespace)
namespace: await prompts.promptNamespaceArg(task, namespace),
deletePvcs: await prompts.promptDeletePvcs(task, deletePvcs)
}
}
},
Expand All @@ -186,6 +188,24 @@ export class ChartCommand extends BaseCommand {
task: async (ctx, _) => {
await self.chartManager.uninstall(ctx.config.namespace, constants.CHART_FST_DEPLOYMENT_NAME)
}
},
{
title: 'Get PVCs for namespace',
task: async (ctx, _) => {
if(ctx.config.deletePvcs === true) {
ctx.config.pvcs = await self.k8.listPvcsByNamespace(ctx.config.namespace)
}
}
},
{
title: 'Delete PVCs for namespace',
task: async (ctx, _) => {
if (ctx.config.pvcs) {
for (const pvc of ctx.config.pvcs) {
await self.k8.deletePvc(pvc, ctx.config.namespace)
}
}
}
}
], {
concurrent: false,
Expand Down Expand Up @@ -286,7 +306,10 @@ export class ChartCommand extends BaseCommand {
.command({
command: 'uninstall',
desc: 'Uninstall network deployment chart',
builder: y => flags.setCommandFlags(y, flags.namespace),
builder: y => flags.setCommandFlags(y,
flags.namespace,
flags.deletePvcs
),
handler: argv => {
chartCmd.logger.debug("==== Running 'chart uninstall' ===")
chartCmd.logger.debug(argv)
Expand Down
12 changes: 11 additions & 1 deletion fullstack-network-manager/src/commands/flags.mjs
Expand Up @@ -299,6 +299,15 @@ export const enableHederaExplorerTls = {
}
}

export const deletePvcs = {
name: 'delete-pvcs',
definition: {
describe: 'Delete the persistent volume claims, defaults to false',
default: false,
type: 'boolean'
}
}

export const allFlags = [
devMode,
clusterName,
Expand Down Expand Up @@ -328,5 +337,6 @@ export const allFlags = [
tlsClusterIssuerName,
tlsClusterIssuerNamespace,
enableHederaExplorerTls,
selfSignedClusterIssuer
selfSignedClusterIssuer,
deletePvcs
]
16 changes: 16 additions & 0 deletions fullstack-network-manager/src/commands/prompts.mjs
Expand Up @@ -494,3 +494,19 @@ export async function promptReplicaCount (task, input) {
throw new FullstackTestingError(`input failed: ${flags.replicaCount.name}`, e)
}
}

export async function promptDeletePvcs (task, input) {
try {
if (input === undefined) {
input = await task.prompt(ListrEnquirerPromptAdapter).run({
type: 'toggle',
default: flags.deletePvcs.definition.default,
message: 'Would you like to delete persistent volume claims upon uninstall?'
})
}

return input
} catch (e) {
throw new FullstackTestingError(`input failed: ${flags.deletePvcs.name}`, e)
}
}
33 changes: 33 additions & 0 deletions fullstack-network-manager/src/core/k8.mjs
Expand Up @@ -637,6 +637,39 @@ export class K8 {
})
}

/**
* Get a list of persistent volume claim names for the given namespace
* @param namespace the namespace of the persistent volume claims to return
* @returns {Promise<*[]>} list of persistent volume claims
*/
async listPvcsByNamespace (namespace) {
const pvcs = []
const resp = await this.kubeClient.listNamespacedPersistentVolumeClaim (
namespace
)

for (const item of resp.body.items) {
pvcs.push(item.metadata.name)
}

return pvcs
}

/**
* Delete a persistent volume claim
* @param name the name of the persistent volume claim to delete
* @param namespace the namespace of the persistent volume claim to delete
* @returns {Promise<boolean>} true if the persistent volume claim was deleted
*/
async deletePvc (name, namespace) {
const resp = await this.kubeClient.deleteNamespacedPersistentVolumeClaim (
name,
namespace
)

return resp.response.statusCode === 200.0
}

_getNamespace () {
const ns = this.configManager.getFlag(flags.namespace)
if (!ns) throw new MissingArgumentError('namespace is not set')
Expand Down
5 changes: 5 additions & 0 deletions fullstack-network-manager/test/e2e/core/k8_e2e.test.mjs
Expand Up @@ -131,4 +131,9 @@ describe('K8', () => {

fs.rmdirSync(tmpDir, { recursive: true })
})

it('should be able to get two persistent volume claims', async () => {
const pvcs = await k8.listPvcsByNamespace(k8._getNamespace())
expect(pvcs).toHaveLength(2)
})
})

0 comments on commit 13b423a

Please sign in to comment.