Skip to content

Commit

Permalink
Do not throw error if several pods are found (#886)
Browse files Browse the repository at this point in the history
Signed-off-by: Anatolii Bazko <abazko@redhat.com>
  • Loading branch information
tolusha committed Sep 25, 2020
1 parent 7df717b commit 5c04e92
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
15 changes: 6 additions & 9 deletions src/api/kube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ export class KubeHelper {
return (res.body.items.length > 0)
}

async getPodPhase(labelSelector: string, namespace = ''): Promise<string> {
async getPodPhase(labelSelector: string, namespace = ''): Promise<string | undefined> {
const k8sCoreApi = KubeHelper.KUBE_CONFIG.makeApiClient(CoreV1Api)
let res
try {
Expand All @@ -657,16 +657,12 @@ export class KubeHelper {
throw this.wrapK8sClientError(e)
}

if (!res || !res.body || !res.body.items) {
throw new Error(`Get pods by selector "${labelSelector}" returned an invalid response`)
}

if (res.body.items.length !== 1) {
throw new Error(`Get pods by selector "${labelSelector}" returned ${res.body.items.length} pods (1 was expected)`)
if (!res || !res.body || !res.body.items || res.body.items.length !== 1) {
return
}

if (!res.body.items[0].status || !res.body.items[0].status.phase) {
throw new Error(`Get pods by selector "${labelSelector}" returned a pod with an invalid state`)
return
}

return res.body.items[0].status.phase
Expand All @@ -691,7 +687,8 @@ export class KubeHelper {
}

if (res.body.items.length > 1) {
throw new Error(`Get pods by selector "${selector}" returned ${res.body.items.length} pods (1 was expected).`)
// Several pods found, rolling update?
return
}

if (!res.body.items[0].status || !res.body.items[0].status.conditions || !(res.body.items[0].status.conditions.length > 0)) {
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2102,11 +2102,11 @@ ecc-jsbn@~0.1.1:

"eclipse-che-operator@git://github.com/eclipse/che-operator#master":
version "0.0.0"
resolved "git://github.com/eclipse/che-operator#66d2f95e9fb6690b07b00a6d76ceb155ebb4b810"
resolved "git://github.com/eclipse/che-operator#2ba993381c5796cc3cc49456123da5e2250604f9"

"eclipse-che@git://github.com/eclipse/che#master":
version "0.0.0"
resolved "git://github.com/eclipse/che#b2e83ac1a411a15e45ea90f0aebf6072c0723b35"
resolved "git://github.com/eclipse/che#d4ff87e492c3c394272120ec69aed7a309b16ecc"

editorconfig@^0.15.0:
version "0.15.3"
Expand Down

0 comments on commit 5c04e92

Please sign in to comment.