Skip to content

Commit

Permalink
fix(k8s): handle injected service mesh containers for tests+tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed Mar 8, 2021
1 parent 1033e59 commit a9f6697
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
12 changes: 3 additions & 9 deletions core/src/plugins/kubernetes/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -688,13 +688,6 @@ export class PodRunner extends PodRunnerParams {
})
}

params.pod.metadata.annotations = {
...(params.pod.metadata.annotations || {}),
// Workaround to make sure sidecars are not injected,
// due to https://github.com/kubernetes/kubernetes/issues/25908
"sidecar.istio.io/inject": "false",
}

Object.assign(this, params)

this.podName = this.pod.metadata.name
Expand Down Expand Up @@ -746,7 +739,7 @@ export class PodRunner extends PodRunnerParams {
try {
await this.createPod({ log, tty })

// Wait until Pod terminates
// Wait until main container terminates
while (true) {
const serverPod = await this.api.core.readNamespacedPodStatus(podName, namespace)
const state = checkPodStatus(serverPod)
Expand Down Expand Up @@ -779,7 +772,8 @@ export class PodRunner extends PodRunnerParams {
})
}

if (state === "stopped") {
// reason "Completed" means main container is done, but sidecars or other containers possibly still alive
if (state === "stopped" || exitReason === "Completed") {
success = exitCode === 0
break
}
Expand Down
25 changes: 17 additions & 8 deletions core/src/plugins/kubernetes/status/pod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,43 @@ export const POD_LOG_LINES = 30
export function checkPodStatus(pod: KubernetesServerResource<V1Pod>): ServiceState {
const phase = pod.status!.phase

if (phase === "Pending") {
// Return "unhealthy" if image or command is invalid
// phase can be "Running" even if some containers have failed, so we need to check container statuses
if (phase === "Pending" || phase === "Running") {
const containerStatuses = pod.status!.containerStatuses

if (containerStatuses) {
let allTerminated = true

for (const c of containerStatuses) {
// Return "unhealthy" if image or command is invalid
if (
c.state &&
c.state.waiting &&
(c.state.waiting.reason === "ImageInspectError" || c.state.waiting.reason === "ErrImagePull")
) {
return "unhealthy"
}
if (c.state && c.state.terminated) {
if (c.state.terminated.exitCode === 0) {
return "stopped"
} else {

// One of the containers failed
if (c.state?.terminated) {
if (c.state?.terminated?.exitCode !== 0) {
return "unhealthy"
}
} else {
allTerminated = false
}
}

if (phase === "Running") {
return "ready"
} else if (allTerminated) {
return "stopped"
}
}

return "deploying"
} else if (phase === "Failed") {
return "unhealthy"
} else if (phase === "Running") {
return "ready"
} else if (phase === "Succeeded" || phase === "Completed") {
return "stopped"
} else {
Expand Down

0 comments on commit a9f6697

Please sign in to comment.