mirror of
https://github.com/actions/runner-container-hooks.git
synced 2025-12-14 08:36:45 +00:00
Repaired prepare-job hook without job container
This commit is contained in:
@@ -1,12 +1,6 @@
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as io from '@actions/io'
|
import * as io from '@actions/io'
|
||||||
import * as k8s from '@kubernetes/client-node'
|
import * as k8s from '@kubernetes/client-node'
|
||||||
import {
|
|
||||||
PodPhase,
|
|
||||||
containerVolumes,
|
|
||||||
DEFAULT_CONTAINER_ENTRY_POINT,
|
|
||||||
DEFAULT_CONTAINER_ENTRY_POINT_ARGS
|
|
||||||
} from '../k8s/utils'
|
|
||||||
import { ContextPorts, prepareJobArgs, writeToResponseFile } from 'hooklib'
|
import { ContextPorts, prepareJobArgs, writeToResponseFile } from 'hooklib'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import {
|
import {
|
||||||
@@ -19,6 +13,12 @@ import {
|
|||||||
requiredPermissions,
|
requiredPermissions,
|
||||||
waitForPodPhases
|
waitForPodPhases
|
||||||
} from '../k8s'
|
} from '../k8s'
|
||||||
|
import {
|
||||||
|
containerVolumes,
|
||||||
|
DEFAULT_CONTAINER_ENTRY_POINT,
|
||||||
|
DEFAULT_CONTAINER_ENTRY_POINT_ARGS,
|
||||||
|
PodPhase
|
||||||
|
} from '../k8s/utils'
|
||||||
import { JOB_CONTAINER_NAME } from './constants'
|
import { JOB_CONTAINER_NAME } from './constants'
|
||||||
|
|
||||||
export async function prepareJob(
|
export async function prepareJob(
|
||||||
@@ -71,24 +71,23 @@ export async function prepareJob(
|
|||||||
new Set([PodPhase.RUNNING]),
|
new Set([PodPhase.RUNNING]),
|
||||||
new Set([PodPhase.PENDING])
|
new Set([PodPhase.PENDING])
|
||||||
)
|
)
|
||||||
|
core.debug('Job pod is ready for traffic')
|
||||||
|
|
||||||
|
let isAlpine = false
|
||||||
|
try {
|
||||||
|
isAlpine = await isPodContainerAlpine(
|
||||||
|
createdPod.metadata.name,
|
||||||
|
JOB_CONTAINER_NAME
|
||||||
|
)
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error(`Failed to determine if the pod is alpine: ${err}`)
|
||||||
|
}
|
||||||
|
core.debug(`Setting isAlpine to ${isAlpine}`)
|
||||||
|
generateResponseFile(responseFile, createdPod, isAlpine)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await prunePods()
|
await prunePods()
|
||||||
throw new Error(`Pod failed to come online with error: ${err}`)
|
throw new Error(`Pod failed to come online with error: ${err}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
core.debug('Job pod is ready for traffic')
|
|
||||||
|
|
||||||
let isAlpine = false
|
|
||||||
try {
|
|
||||||
isAlpine = await isPodContainerAlpine(
|
|
||||||
createdPod.metadata.name,
|
|
||||||
JOB_CONTAINER_NAME
|
|
||||||
)
|
|
||||||
} catch (err) {
|
|
||||||
throw new Error(`Failed to determine if the pod is alpine: ${err}`)
|
|
||||||
}
|
|
||||||
core.debug(`Setting isAlpine to ${isAlpine}`)
|
|
||||||
generateResponseFile(responseFile, createdPod, isAlpine)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateResponseFile(
|
function generateResponseFile(
|
||||||
|
|||||||
@@ -68,4 +68,11 @@ describe('Prepare job', () => {
|
|||||||
prepareJob(prepareJobData.args, prepareJobOutputFilePath)
|
prepareJob(prepareJobData.args, prepareJobOutputFilePath)
|
||||||
).rejects.toThrow()
|
).rejects.toThrow()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should run prepare job without the job container', async () => {
|
||||||
|
prepareJobData.args.container = undefined
|
||||||
|
await expect(
|
||||||
|
prepareJob(prepareJobData.args, prepareJobOutputFilePath)
|
||||||
|
).resolves.not.toThrow()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user