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

feature: add namespace to starshipjs #473

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions clients/js/packages/cli/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const params: string[] = [
'helmRepoUrl',
'helmChart',
'helmVersion',
'helmNamespace',
]

export const loadConfig = (argv: any): Config => {
Expand Down
30 changes: 24 additions & 6 deletions clients/js/packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface StarshipContext {
helmRepoUrl?: string;
helmChart?: string;
helmVersion?: string;
helmNamespace?: string;
kindCluster?: string;
verbose?: boolean;
curdir?: string;
Expand All @@ -29,7 +30,8 @@ export const defaultStarshipContext: Partial<StarshipContext> = {
helmRepo: 'starship',
helmRepoUrl: 'https://cosmology-tech.github.io/starship/',
helmChart: 'devnet',
helmVersion: 'v0.2.1'
helmVersion: 'v0.2.1',
helmNamespace: '',
};

export interface PodPorts {
Expand Down Expand Up @@ -197,6 +199,14 @@ export class StarshipClient implements StarshipClientI {
this.podPorts = deepmerge(defaultPorts, ports);
}

public getArgs(): string[] {
const args = [];
if (this.ctx.helmNamespace) {
args.push('--namespace', this.ctx.helmNamespace);
}
return args;
}

// TODO do we need this here?
public test(): void {
this.exec([
Expand Down Expand Up @@ -250,6 +260,7 @@ export class StarshipClient implements StarshipClientI {
public deploy(): void {
this.ensureFileExists(this.ctx.helmFile);
this.log("Installing the helm chart. This is going to take a while.....");

this.exec([
'helm',
'install',
Expand All @@ -258,7 +269,8 @@ export class StarshipClient implements StarshipClientI {
this.ctx.helmName,
`${this.ctx.helmRepo}/${this.ctx.helmChart}`,
'--version',
this.ctx.helmVersion
this.ctx.helmVersion,
...this.getArgs(),
]);
this.log("Run \"starship get-pods\" to check the status of the cluster");
}
Expand All @@ -273,7 +285,8 @@ export class StarshipClient implements StarshipClientI {
'-f',
this.ctx.helmFile,
this.ctx.helmName,
`${this.ctx.helmRepo}/${this.ctx.helmChart}`
`${this.ctx.helmRepo}/${this.ctx.helmChart}`,
...this.getArgs(),,
]);
}

Expand All @@ -284,7 +297,8 @@ export class StarshipClient implements StarshipClientI {
public getPods(): void {
this.exec([
"kubectl",
"get pods"
"get pods",
...this.getArgs(),
// "--all-namespaces"
]);
}
Expand All @@ -296,7 +310,8 @@ export class StarshipClient implements StarshipClientI {
'pods',
'--no-headers',
'-o',
'custom-columns=:metadata.name'
'custom-columns=:metadata.name',
...this.getArgs(),
], false, true)

// Split the output by new lines and filter out any empty lines
Expand All @@ -323,7 +338,8 @@ export class StarshipClient implements StarshipClientI {
podName,
'--no-headers',
'-o',
'custom-columns=:status.phase,:status.containerStatuses[*].state.waiting.reason'
'custom-columns=:status.phase,:status.containerStatuses[*].state.waiting.reason',
...this.getArgs(),
], false, true).trim();

const [status, reason] = result.split(' ');
Expand Down Expand Up @@ -378,6 +394,7 @@ export class StarshipClient implements StarshipClientI {
"kubectl", "port-forward",
`pods/${chain.id}-genesis-0`,
`${localPort}:${externalPort}`,
...this.getArgs(),
">", "/dev/null",
"2>&1", "&"
]);
Expand All @@ -391,6 +408,7 @@ export class StarshipClient implements StarshipClientI {
"kubectl", "port-forward",
`service/${serviceName}`,
`${localPort}:${externalPort}`,
...this.getArgs(),
">", "/dev/null",
"2>&1", "&"
]);
Expand Down