From 23dc9356b5a602710e9c7fd7f6158c8787faac5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ey=C3=BE=C3=B3r=20Magn=C3=BAsson?= Date: Thu, 1 Nov 2018 00:00:01 +0100 Subject: [PATCH] fix(k8s): don't throw if api returns 404 when checking object status Circumvents #353 --- garden-service/src/actions.ts | 3 +++ .../src/plugins/kubernetes/status.ts | 21 +++++++++++++++---- package.json | 2 +- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/garden-service/src/actions.ts b/garden-service/src/actions.ts index d1d37951a2..0912a4d200 100644 --- a/garden-service/src/actions.ts +++ b/garden-service/src/actions.ts @@ -125,6 +125,9 @@ export class ActionHelper implements TypeGuard { { force?: boolean, pluginName?: string, logEntry?: LogEntry, allowUserInput?: boolean }, ) { const handlers = this.garden.getActionHandlers("prepareEnvironment", pluginName) + // FIXME: We're calling getEnvironmentStatus before preparing the environment. + // Results in 404 errors for unprepared/missing services. + // See: https://github.com/garden-io/garden/issues/353 const statuses = await this.getEnvironmentStatus({ pluginName }) const needUserInput = Object.entries(statuses) diff --git a/garden-service/src/plugins/kubernetes/status.ts b/garden-service/src/plugins/kubernetes/status.ts index 0c8f6efaf1..4bb60a9600 100644 --- a/garden-service/src/plugins/kubernetes/status.ts +++ b/garden-service/src/plugins/kubernetes/status.ts @@ -114,7 +114,6 @@ async function checkPodStatus(obj: KubernetesObject, pods: V1Pod[]): Promise { - // const out: RolloutStatus = { state: "unhealthy", obj, @@ -301,10 +300,24 @@ export async function checkObjectStatus( const statuses: RolloutStatus[] = await Bluebird.map(objects, async (obj, i) => { const handler = objHandlers[obj.kind] const prevStatus = prevStatuses && prevStatuses[i] - const status: RolloutStatus = handler - ? await handler(api, namespace, obj, prevStatus && prevStatus.resourceVersion) + let status: RolloutStatus + if (handler) { + try { + status = await handler(api, namespace, obj, prevStatus && prevStatus.resourceVersion) + } catch (err) { + // We handle 404s specifically since this might be invoked before some objects are deployed + // See: https://github.com/garden-io/garden/issues/353 + // TODO: Figure out whether we'll need this check after issue #353 above has been resolved + if (err.code === 404) { + status = { state: "missing", obj } + } else { + throw err + } + } + } else { // if there is no explicit handler to check the status, we assume there's no rollout phase to wait for - : { state: "ready", obj } + status = { state: "ready", obj } + } if (status.state !== "ready") { ready = false diff --git a/package.json b/package.json index 53d9cb1856..1c9fd5f5a6 100644 --- a/package.json +++ b/package.json @@ -67,4 +67,4 @@ }, "snyk": true, "dependencies": {} -} \ No newline at end of file +}