mirror of
https://github.com/actions/runner-container-hooks.git
synced 2025-12-15 09:16:44 +00:00
setup ci to run k8s tests
This commit is contained in:
@@ -59,7 +59,7 @@ export async function prepareJob(
|
||||
createdPod = await createPod(container, services, args.registry)
|
||||
} catch (err) {
|
||||
await podPrune()
|
||||
throw new Error(`failed to create job pod: ${err}`)
|
||||
throw new Error(`failed to create job pod: ${JSON.stringify(err)}`)
|
||||
}
|
||||
|
||||
if (!createdPod?.metadata?.name) {
|
||||
|
||||
@@ -25,12 +25,11 @@ export async function runContainerStep(stepContainer): Promise<number> {
|
||||
)} to have correctly set the metadata.name`
|
||||
)
|
||||
}
|
||||
|
||||
const podName = await getContainerJobPodName(job.metadata.name)
|
||||
await waitForPodPhases(
|
||||
podName,
|
||||
new Set([PodPhase.COMPLETED, PodPhase.RUNNING]),
|
||||
new Set([PodPhase.PENDING])
|
||||
new Set([PodPhase.COMPLETED, PodPhase.RUNNING, PodPhase.SUCCEEDED]),
|
||||
new Set([PodPhase.PENDING, PodPhase.UNKNOWN])
|
||||
)
|
||||
await getPodLogs(podName, JOB_CONTAINER_NAME)
|
||||
await waitForJobToComplete(job.metadata.name)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
import { RunScriptStepArgs } from 'hooklib'
|
||||
import { execPodStep } from '../k8s'
|
||||
import { JOB_CONTAINER_NAME } from './constants'
|
||||
import { getJobPodName, JOB_CONTAINER_NAME } from './constants'
|
||||
|
||||
export async function runScriptStep(
|
||||
args: RunScriptStepArgs,
|
||||
@@ -13,7 +13,7 @@ export async function runScriptStep(
|
||||
args.entryPointArgs,
|
||||
args.environmentVariables
|
||||
)
|
||||
await execPodStep(cb.command, state.jobPod, JOB_CONTAINER_NAME)
|
||||
await execPodStep(cb.command, getJobPodName(), JOB_CONTAINER_NAME)
|
||||
}
|
||||
|
||||
class CommandsBuilder {
|
||||
|
||||
@@ -5,6 +5,7 @@ import { v4 as uuidv4 } from 'uuid'
|
||||
import {
|
||||
getJobPodName,
|
||||
getRunnerPodName,
|
||||
getStepPodName,
|
||||
getVolumeClaimName,
|
||||
RunnerInstanceLabel
|
||||
} from '../hooks/constants'
|
||||
@@ -119,7 +120,7 @@ export async function createJob(
|
||||
job.apiVersion = 'batch/v1'
|
||||
job.kind = 'Job'
|
||||
job.metadata = new k8s.V1ObjectMeta()
|
||||
job.metadata.name = getJobPodName()
|
||||
job.metadata.name = getStepPodName()
|
||||
job.metadata.labels = { 'runner-pod': getRunnerPodName() }
|
||||
|
||||
job.spec = new k8s.V1JobSpec()
|
||||
@@ -173,7 +174,13 @@ export async function getContainerJobPodName(jobName: string): Promise<string> {
|
||||
}
|
||||
|
||||
export async function deletePod(podName: string): Promise<void> {
|
||||
await k8sApi.deleteNamespacedPod(podName, namespace())
|
||||
await k8sApi.deleteNamespacedPod(
|
||||
podName,
|
||||
namespace(),
|
||||
undefined,
|
||||
undefined,
|
||||
0
|
||||
)
|
||||
}
|
||||
|
||||
export async function execPodStep(
|
||||
@@ -273,7 +280,6 @@ export async function waitForPodPhases(
|
||||
try {
|
||||
while (true) {
|
||||
phase = await getPodPhase(podName)
|
||||
|
||||
if (awaitingPhases.has(phase)) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import * as k8s from '@kubernetes/client-node'
|
||||
import { Mount } from 'hooklib'
|
||||
import * as path from 'path'
|
||||
import { POD_VOLUME_NAME } from './index'
|
||||
|
||||
export const DEFAULT_CONTAINER_ENTRY_POINT_ARGS = [`-f`, `/dev/null`]
|
||||
@@ -43,6 +42,9 @@ export function containerVolumes(
|
||||
return mounts
|
||||
}
|
||||
|
||||
// TODO: we need to ensure this is a local path under the github workspace or fail/skip
|
||||
// subpath only accepts a local path under the runner workspace
|
||||
/*
|
||||
for (const userVolume of userMountVolumes) {
|
||||
const sourceVolumePath = `${
|
||||
path.isAbsolute(userVolume.sourceVolumePath)
|
||||
@@ -52,7 +54,6 @@ export function containerVolumes(
|
||||
userVolume.sourceVolumePath
|
||||
)
|
||||
}`
|
||||
|
||||
mounts.push({
|
||||
name: POD_VOLUME_NAME,
|
||||
mountPath: userVolume.targetVolumePath,
|
||||
@@ -60,6 +61,7 @@ export function containerVolumes(
|
||||
readOnly: userVolume.readOnly
|
||||
})
|
||||
}
|
||||
*/
|
||||
|
||||
return mounts
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user