diff --git a/docs/adrs/0134-hook-extensions.md b/docs/adrs/0134-hook-extensions.md index 62c1f1d7..bfb3caac 100644 --- a/docs/adrs/0134-hook-extensions.md +++ b/docs/adrs/0134-hook-extensions.md @@ -29,9 +29,10 @@ In case the hook is able to read the extended spec, it will first create a defau 3. The volumes are applied in form of appending additional volumes to the default volumes. 4. The containers are merged based on the name assigned to them: 1. If the name of the container *is* "$job", the `name` and the `image` fields are going to be ignored and the spec will be applied so that `env`, `volumeMounts`, `ports` are appended to the default container spec created by the hook, while the rest of the fields are going to be applied to the newly created container spec. - 2. If the name of the container *starts with* "$", and matches the name of the [container service](https://docs.github.com/en/actions/using-containerized-services/about-service-containers), the `name` and the `image` fields are going to be ignored and the spec will be applied to that service container, so that `env`, `volumeMounts`, `ports` are appended to the default container spec for service created by the hook, while the rest of the fields are going to be applied to the created container spec. - If there is no container service with such name defined in the workflow, such spec extension will be ignored. - 3. If the name of the container *does not start with* "$", the entire spec of the container will be added to the pod definition. + 2. If the name of the container *starts with* "$", and matches the name of the [container service](https://docs.github.com/en/actions/using-containerized-services/about-service-containers), the `name` and the `image` fields are going to be ignored and the spec will be applied to that service container, so that `env`, `volumeMounts`, `ports` are appended to the default container spec for service created by the hook, while the rest of the fields are going to be applied to the created container spec. + If there is no container service with such name defined in the workflow, such spec extension will be ignored. + 3. If the name of the container *is "$default", the `name` and the `image` fields are going to be ignored and the spec will be applied to all service containers that were not extended at point 2. + 4. If the name of the container *does not start with* "$", the entire spec of the container will be added to the pod definition. ## Consequences diff --git a/packages/k8s/src/hooks/constants.ts b/packages/k8s/src/hooks/constants.ts index 293de34f..3b54ac49 100644 --- a/packages/k8s/src/hooks/constants.ts +++ b/packages/k8s/src/hooks/constants.ts @@ -44,6 +44,7 @@ export const STEP_POD_NAME_SUFFIX_LENGTH = 8 export const CONTAINER_EXTENSION_PREFIX = '$' export const JOB_CONTAINER_NAME = 'job' export const JOB_CONTAINER_EXTENSION_NAME = '$job' +export const DEFAULT_CONTAINER_EXTENSION_NAME = '$default' export class RunnerInstanceLabel { private podName: string diff --git a/packages/k8s/src/hooks/prepare-job.ts b/packages/k8s/src/hooks/prepare-job.ts index 1312fa05..c7c34e41 100644 --- a/packages/k8s/src/hooks/prepare-job.ts +++ b/packages/k8s/src/hooks/prepare-job.ts @@ -27,7 +27,11 @@ import { PodPhase, fixArgs } from '../k8s/utils' -import { CONTAINER_EXTENSION_PREFIX, JOB_CONTAINER_NAME } from './constants' +import { + CONTAINER_EXTENSION_PREFIX, + JOB_CONTAINER_NAME, + DEFAULT_CONTAINER_EXTENSION_NAME +} from './constants' export async function prepareJob( args: PrepareJobArgs, @@ -253,6 +257,14 @@ export function createContainerSpec( return podContainer } + const all = extension.spec?.containers?.find( + c => c.name === DEFAULT_CONTAINER_EXTENSION_NAME + ) + + if (all) { + mergeContainerWithOptions(podContainer, all) + } + const from = extension.spec?.containers?.find( c => c.name === CONTAINER_EXTENSION_PREFIX + name )