Skip to content

Commit

Permalink
add pre check to check connection with k8s cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
Anmol1696 committed Jul 18, 2024
1 parent 82e748e commit c7c9cd4
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions clients/js/packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ export class StarshipClient implements StarshipClientI {
}

public async start(): Promise<void> {
this.checkConnection();
this.setup();
this.deploy();
await this.waitForPods(); // Ensure waitForPods completes before starting port forwarding
Expand Down Expand Up @@ -384,6 +385,18 @@ export class StarshipClient implements StarshipClientI {
]);
}

public checkConnection(): void {
const result = this.exec(['kubectl', 'get', 'nodes'], false, true);

if (result.code !== 0) {
this.log(chalk.red('Error: Unable to connect to the Kubernetes cluster.'));
this.log(chalk.red('Please ensure that the Kubernetes cluster is configured correctly.'));
this.exit(1);
} else {
this.log(chalk.green('Kubernetes cluster connection is working correctly.'));
}
}

private getPodNames(): string[] {
const result = this.exec([
'kubectl',
Expand Down

0 comments on commit c7c9cd4

Please sign in to comment.