Skip to content

Commit

Permalink
fix(k8s): don't throw if api returns 404 when checking object status
Browse files Browse the repository at this point in the history
Circumvents #353
  • Loading branch information
eysi09 committed Nov 1, 2018
1 parent fc50a8e commit 23dc935
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
3 changes: 3 additions & 0 deletions garden-service/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 17 additions & 4 deletions garden-service/src/plugins/kubernetes/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ async function checkPodStatus(obj: KubernetesObject, pods: V1Pod[]): Promise<Rol
export async function checkDeploymentStatus(
api: KubeApi, namespace: string, obj: KubernetesObject, resourceVersion?: number,
): Promise<RolloutStatus> {
//
const out: RolloutStatus = {
state: "unhealthy",
obj,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@
},
"snyk": true,
"dependencies": {}
}
}

0 comments on commit 23dc935

Please sign in to comment.