Skip to content

Commit

Permalink
fix: check for namespace
Browse files Browse the repository at this point in the history
Signed-off-by: Lenin Mehedy <lenin.mehedy@swirldslabs.com>
  • Loading branch information
leninmehedy committed Jan 22, 2024
1 parent 12c94ab commit 90b0f4d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions fullstack-network-manager/src/commands/chart.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ export class ChartCommand extends BaseCommand {
config.enableTls, config.tlsClusterIssuerName, config.tlsClusterIssuerNamespace, config.enableHederaExplorerTls,
config.acmeClusterIssuer, config.selfSignedClusterIssuer)

if (!await this.kubectl2.hasNamespace(config.namespace)) {
throw new FullstackTestingError(`namespace ${config.namespace} does not exist`)
}

return config
}

Expand Down
13 changes: 12 additions & 1 deletion fullstack-network-manager/src/commands/node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ export class NodeCommand extends BaseCommand {
chainId: await prompts.promptChainId(task, argv.chainId)
}

if (!await this.kubectl2.hasNamespace(config.namespace)) {
throw new FullstackTestingError(`namespace ${config.namespace} does not exist`)
}

// compute other config parameters
config.releasePrefix = Templates.prepareReleasePrefix(config.releaseTag)
config.buildZipFile = `${config.cacheDir} /${config.releasePrefix}/build-${config.releaseTag}.zip`
Expand Down Expand Up @@ -215,6 +219,10 @@ export class NodeCommand extends BaseCommand {
namespace: await prompts.promptSelectNamespaceArg(task, namespace, namespaces),
nodeIds: await prompts.promptNodeIdsArg(task, argv.nodeIds)
}

if (!await this.kubectl2.hasNamespace(ctx.config.namespace)) {
throw new FullstackTestingError(`namespace ${ctx.config.namespace} does not exist`)
}
}
},
{
Expand Down Expand Up @@ -289,11 +297,14 @@ export class NodeCommand extends BaseCommand {

// get existing choices
const namespaces = await self.kubectl2.getNamespaces()

ctx.config = {
namespace: await prompts.promptSelectNamespaceArg(task, namespace, namespaces),
nodeIds: await prompts.promptNodeIdsArg(task, argv.nodeIds)
}

if (!await this.kubectl2.hasNamespace(ctx.config.namespace)) {
throw new FullstackTestingError(`namespace ${ctx.config.namespace} does not exist`)
}
}
},
{
Expand Down
10 changes: 10 additions & 0 deletions fullstack-network-manager/src/core/kubectl2.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ export class Kubectl2 {
throw new FullstackTestingError('incorrect response received from kubernetes API. Unable to list namespaces')
}

/**
* Returns true if a namespace exists with the given name
* @param namespace namespace name
* @return {Promise<boolean>}
*/
async hasNamespace (namespace) {
const namespaces = await this.getNamespaces()
return namespaces.includes(namespace)
}

/**
* Get a podName by name
* @param name podName name
Expand Down

0 comments on commit 90b0f4d

Please sign in to comment.