Skip to content

Commit

Permalink
working version
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 24, 2024
1 parent 0933869 commit d12877c
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 3 deletions.
27 changes: 25 additions & 2 deletions fullstack-network-manager/src/commands/chart.mjs
Original file line number Diff line number Diff line change
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.metadata.name, 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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)
}
}
28 changes: 28 additions & 0 deletions fullstack-network-manager/src/core/k8.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,34 @@ export class K8 {
})
}

/**
* Get a list of persistent volume claims by namespace
* @param namespace the namespace of the persistent volume claims to return
* @returns {Promise<Array<V1PersistentVolumeClaim>>} list of persistent volume claims
*/
async listPvcsByNamespace (namespace) {
const resp = await this.kubeClient.listNamespacedPersistentVolumeClaim (
namespace
)

return resp.body.items
}

/**
* 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

0 comments on commit d12877c

Please sign in to comment.