Files
runner-container-hooks/packages/k8s/src/hooks/constants.ts
T

66 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-06-02 15:53:11 -04:00
import { v4 as uuidv4 } from 'uuid'
export function getRunnerPodName(): string {
const name = process.env.ACTIONS_RUNNER_POD_NAME
if (!name) {
throw new Error(
"'ACTIONS_RUNNER_POD_NAME' env is required, please contact your self hosted runner administrator"
)
}
return name
}
export function getJobPodName(): string {
return `${getRunnerPodName().substring(
0,
MAX_POD_NAME_LENGTH - '-workflow'.length
)}-workflow`
}
export function getStepPodName(): string {
return `${getRunnerPodName().substring(
0,
MAX_POD_NAME_LENGTH - ('-step-'.length + STEP_POD_NAME_SUFFIX_LENGTH)
2022-06-02 15:53:11 -04:00
)}-step-${uuidv4().substring(0, STEP_POD_NAME_SUFFIX_LENGTH)}`
}
export function getVolumeClaimName(): string {
const name = process.env.ACTIONS_RUNNER_CLAIM_NAME
if (!name) {
2022-06-20 15:09:04 -04:00
return `${getRunnerPodName()}-work`
2022-06-02 15:53:11 -04:00
}
return name
}
export function getSecretName(): string {
return `${getRunnerPodName().substring(
0,
MAX_POD_NAME_LENGTH - ('-secret-'.length + STEP_POD_NAME_SUFFIX_LENGTH)
)}-secret-${uuidv4().substring(0, STEP_POD_NAME_SUFFIX_LENGTH)}`
}
export const MAX_POD_NAME_LENGTH = 63
export const STEP_POD_NAME_SUFFIX_LENGTH = 8
export const CONTAINER_EXTENSION_PREFIX = '$'
2022-06-02 15:53:11 -04:00
export const JOB_CONTAINER_NAME = 'job'
export const JOB_CONTAINER_EXTENSION_NAME = '$job'
2022-06-02 15:53:11 -04:00
export class RunnerInstanceLabel {
private podName: string
2022-06-02 15:53:11 -04:00
constructor() {
this.podName = getRunnerPodName()
2022-06-02 15:53:11 -04:00
}
get key(): string {
return 'runner-pod'
}
get value(): string {
return this.podName
2022-06-02 15:53:11 -04:00
}
toString(): string {
return `runner-pod=${this.podName}`
2022-06-02 15:53:11 -04:00
}
}