Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions docs/adrs/0134-hook-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions packages/k8s/src/hooks/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion packages/k8s/src/hooks/prepare-job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
)
Expand Down