Skip to content

Commit

Permalink
fix: make waitForPod non-blocking
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 24, 2024
1 parent 468b0b0 commit 5a9b96c
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions fullstack-network-manager/src/core/kubectl2.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -519,28 +519,37 @@ export class Kubectl2 {

this.logger.debug(`WaitForPod [${fieldSelector}, ${labelSelector}], maxAttempts: ${maxAttempts}`)

// wait for the pod to be available with the given status and labels
for (let attempts = 0; attempts < maxAttempts; attempts++) {
this.logger.debug(`Checking for pod ${fieldSelector}, ${labelSelector} [attempt: ${attempts}/${maxAttempts}]`)
const resp = await this.kubeClient.listNamespacedPod(
ns,
false,
false,
undefined,
fieldSelector,
labelSelector,
podCount
)
return new Promise((resolve, reject) => {
let attempts = 0

const check = async () => {
this.logger.debug(`Checking for pod ${fieldSelector}, ${labelSelector} [attempt: ${attempts}/${maxAttempts}]`)

// wait for the pod to be available with the given status and labels
const resp = await this.kubeClient.listNamespacedPod(
ns,
false,
false,
undefined,
fieldSelector,
labelSelector,
podCount
)

if (resp.body && resp.body.items && resp.body.items.length === podCount) {
this.logger.debug(`Found ${resp.body.items.length}/${podCount} pod with ${fieldSelector}, ${labelSelector} [attempt: ${attempts}/${maxAttempts}]`)
return resolve(true)
}

if (resp.body && resp.body.items && resp.body.items.length === podCount) {
this.logger.debug(`Found ${resp.body.items.length}/${podCount} pod with ${fieldSelector}, ${labelSelector} [attempt: ${attempts}/${maxAttempts}]`)
return true
if (attempts < maxAttempts) {
setTimeout(check, delay)
} else {
reject(new FullstackTestingError(`Expected number of pod (${podCount}) not found ${fieldSelector} ${labelSelector} [maxAttempts = ${maxAttempts}]`))
}
}

await sleep(delay)
}

throw new FullstackTestingError(`Expected number of pod (${podCount}) not found ${fieldSelector} ${labelSelector} [maxAttempts = ${maxAttempts}]`)
check()
})
}

_getNamespace () {
Expand Down

0 comments on commit 5a9b96c

Please sign in to comment.