From 1cee3c71fb2cf46a2499aadf11ba6546b36d2948 Mon Sep 17 00:00:00 2001 From: dkwon17 Date: Mon, 15 Jul 2024 21:35:38 +0000 Subject: [PATCH] fix: allow wait for multiple DWO webhook pods Signed-off-by: dkwon17 --- src/api/kube-client.ts | 41 +++++++++++-------- .../dev-workspace/dev-workspace-tasks.ts | 2 +- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/api/kube-client.ts b/src/api/kube-client.ts index 9dc0a63f4..5387c4b76 100644 --- a/src/api/kube-client.ts +++ b/src/api/kube-client.ts @@ -745,7 +745,11 @@ export class KubeClient { return conditions } - async getPodReadyConditionStatus(selector: string, namespace: string): Promise { + async getPodReadyConditionStatus(selector: string, namespace: string): Promise { + return this.getPodsReadyConditionStatus(selector, namespace, 1) + } + + async getPodsReadyConditionStatus(selector: string, namespace: string, pods: number): Promise { const k8sCoreApi = this.kubeConfig.makeApiClient(CoreV1Api) let res try { @@ -758,33 +762,38 @@ export class KubeClient { throw new Error(`Get pods by selector "${selector}" returned an invalid response.`) } - if (res.body.items.length < 1) { - // No pods found by the specified selector. So, it's not ready. - return 'False' - } - - if (res.body.items.length > 1) { - // Several pods found, rolling update? + if (res.body.items.length < pods) { + // Fewer than expected pods found by the specified selector. So, it's not ready. return } - if (!res.body.items[0].status || !res.body.items[0].status.conditions || !(res.body.items[0].status.conditions.length > 0)) { + if (res.body.items.length > pods) { + // More pods than expected found, rolling update? return } - const conditions = res.body.items[0].status.conditions - for (const condition of conditions) { - if (condition.type === 'Ready') { - return condition.status + return res.body.items.map(item => { + if (item.status && item.status.conditions) { + for (const condition of item.status.conditions) { + if (condition.type === 'Ready') { + return condition.status + } + } } - } + + return 'False' + }) } async waitForPodReady(selector: string, namespace: string, intervalMs = 500, timeoutMs = this.podReadyTimeout) { + await this.waitForPodsReady(selector, namespace, 1, intervalMs, timeoutMs) + } + + async waitForPodsReady(selector: string, namespace: string, pods: number, intervalMs = 500, timeoutMs = this.podReadyTimeout) { const iterations = timeoutMs / intervalMs for (let index = 0; index < iterations; index++) { - const readyStatus = await this.getPodReadyConditionStatus(selector, namespace) - if (readyStatus === 'True') { + const readyStatus = await this.getPodsReadyConditionStatus(selector, namespace, pods) + if (readyStatus && readyStatus.every(status => status === 'True')) { return } diff --git a/src/tasks/installers/dev-workspace/dev-workspace-tasks.ts b/src/tasks/installers/dev-workspace/dev-workspace-tasks.ts index 1c2e0ae83..9b1fc93b7 100644 --- a/src/tasks/installers/dev-workspace/dev-workspace-tasks.ts +++ b/src/tasks/installers/dev-workspace/dev-workspace-tasks.ts @@ -133,7 +133,7 @@ export namespace DevWorkspacesTasks { task: async (ctx: any, task: any) => { const kubeHelper = KubeClient.getInstance() await kubeHelper.waitForPodReady('app.kubernetes.io/name=devworkspace-controller', ctx[DevWorkspaceContext.NAMESPACE]) - await kubeHelper.waitForPodReady('app.kubernetes.io/name=devworkspace-webhook-server', ctx[DevWorkspaceContext.NAMESPACE]) + await kubeHelper.waitForPodsReady('app.kubernetes.io/name=devworkspace-webhook-server', ctx[DevWorkspaceContext.NAMESPACE], 2) task.title = `${task.title}...[OK]` }, }