From 709138411fc03b53b1cef91da41451b85596e68f Mon Sep 17 00:00:00 2001 From: Anmol Date: Sun, 16 Jun 2024 18:25:33 +0530 Subject: [PATCH] add check for each container readyness check as well (#486) --- clients/js/packages/client/src/client.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/clients/js/packages/client/src/client.ts b/clients/js/packages/client/src/client.ts index dd06319f..e40c7a52 100644 --- a/clients/js/packages/client/src/client.ts +++ b/clients/js/packages/client/src/client.ts @@ -366,21 +366,25 @@ export class StarshipClient implements StarshipClientI { podName, '--no-headers', '-o', - 'custom-columns=:status.phase,:status.containerStatuses[*].state.waiting.reason', + 'custom-columns=:status.phase,:status.containerStatuses[*].ready,:status.containerStatuses[*].state.waiting.reason', ...this.getArgs(), ], false, true).trim(); - - const [status, reason] = result.split(' '); - this.podStatuses.set(podName, status); - if (status === 'Running') { + const [status, readyList, reason] = result.split(/\s+/); + const ready = readyList.split(',').every(state => state === 'true'); + + if (status === 'Running' && ready) { // this.log(`[${chalk.blue(podName)}]: ${chalk.green('RUNNING')}`); + this.podStatuses.set(podName, status); + } else if (status === 'Running' && !ready) { + this.podStatuses.set(podName, 'RunningButNotReady'); } else if (status === 'Terminating') { // this.log(`[${chalk.blue(podName)}]: ${chalk.gray('TERMINATING')}`); } else if (reason && (reason.includes('ImagePullBackOff') || reason.includes('ErrImagePull'))) { // this.log(`${chalk.blue(podName)} failed due to ${chalk.red(reason)}. Exiting...`); this.exit(1); } else { + this.podStatuses.set(podName, 'Pending'); // this.log(`[${chalk.blue(podName)}]: ${chalk.red(status)}`); // setTimeout(() => this.checkPodStatus(podName), 2500); // check every 2.5 seconds } @@ -399,6 +403,10 @@ export class StarshipClient implements StarshipClientI { if (!this.areAllPodsRunning()) { await new Promise(resolve => setTimeout(resolve, 2500)); await this.waitForPods(); // Recursive call + } else { + this.log(chalk.green('All pods are running!')); + // once the pods are in running state, wait for 10 more seconds + await new Promise(resolve => setTimeout(resolve, 10000)); } }