Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(k8s): don't throw if api returns 404 when checking object status #354

Merged
merged 1 commit into from
Nov 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": {}
}
}