Skip to content
Merged
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
37 changes: 21 additions & 16 deletions packages/k8s/src/k8s/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,12 @@ export async function waitForPodPhases(
maxTimeSeconds = DEFAULT_WAIT_FOR_POD_TIME_SECONDS
): Promise<void> {
const backOffManager = new BackOffManager(maxTimeSeconds)
let podStatus: k8s.V1PodStatus | undefined = undefined
let phase: PodPhase = PodPhase.UNKNOWN
try {
while (true) {
phase = await getPodPhase(podName)
podStatus = await getPodStatus(podName)
phase = getPodPhaseFromStatus(podStatus)
if (awaitingPhases.has(phase)) {
return
}
Expand All @@ -496,7 +498,13 @@ export async function waitForPodPhases(
await backOffManager.backOff()
}
} catch (error) {
throw new Error(`Pod ${podName} is unhealthy with phase status ${phase}`)
throw new Error(
`Pod ${podName} is unhealthy with phase status ${phase}. Pod message is ${
podStatus?.message
} and pod's container statuses are ${JSON.stringify(
podStatus?.containerStatuses || ''
)}`
)
}
}

Expand All @@ -519,22 +527,19 @@ export function getPrepareJobTimeoutSeconds(): number {
return timeoutSeconds
}

async function getPodPhase(podName: string): Promise<PodPhase> {
const podPhaseLookup = new Set<string>([
PodPhase.PENDING,
PodPhase.RUNNING,
PodPhase.SUCCEEDED,
PodPhase.FAILED,
PodPhase.UNKNOWN
])
const pod = await k8sApi.readNamespacedPod({
name: podName,
namespace: namespace()
})
if (!pod.status?.phase || !podPhaseLookup.has(pod.status.phase)) {
const podPhaseLookup = new Set<string>([
PodPhase.PENDING,
PodPhase.RUNNING,
PodPhase.SUCCEEDED,
PodPhase.FAILED,
PodPhase.UNKNOWN
])

function getPodPhaseFromStatus(podStatus?: k8s.V1PodStatus): PodPhase {
if (!podStatus || !podStatus.phase || !podPhaseLookup.has(podStatus.phase)) {
return PodPhase.UNKNOWN
}
return pod.status?.phase as PodPhase
return podStatus.phase as PodPhase
}

async function isJobSucceeded(jobName: string): Promise<boolean> {
Expand Down
Loading