Skip to content

Commit b649e11

Browse files
committed
Add in hook extensions to be able to extend all container services
1 parent 7da5474 commit b649e11

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

docs/adrs/0134-hook-extensions.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ In case the hook is able to read the extended spec, it will first create a defau
2929
3. The volumes are applied in form of appending additional volumes to the default volumes.
3030
4. The containers are merged based on the name assigned to them:
3131
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.
32-
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.
33-
If there is no container service with such name defined in the workflow, such spec extension will be ignored.
34-
3. If the name of the container *does not start with* "$", the entire spec of the container will be added to the pod definition.
32+
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.
33+
If there is no container service with such name defined in the workflow, such spec extension will be ignored.
34+
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.
35+
4. If the name of the container *does not start with* "$", the entire spec of the container will be added to the pod definition.
3536

3637
## Consequences
3738

packages/k8s/src/hooks/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export const STEP_POD_NAME_SUFFIX_LENGTH = 8
4444
export const CONTAINER_EXTENSION_PREFIX = '$'
4545
export const JOB_CONTAINER_NAME = 'job'
4646
export const JOB_CONTAINER_EXTENSION_NAME = '$job'
47+
export const DEFAULT_CONTAINER_EXTENSION_NAME = '$default'
4748

4849
export class RunnerInstanceLabel {
4950
private podName: string

packages/k8s/src/hooks/prepare-job.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ import {
2626
PodPhase,
2727
fixArgs
2828
} from '../k8s/utils'
29-
import { CONTAINER_EXTENSION_PREFIX, JOB_CONTAINER_NAME } from './constants'
29+
import {
30+
CONTAINER_EXTENSION_PREFIX,
31+
JOB_CONTAINER_NAME,
32+
DEFAULT_CONTAINER_EXTENSION_NAME
33+
} from './constants'
3034

3135
export async function prepareJob(
3236
args: PrepareJobArgs,
@@ -250,6 +254,14 @@ export function createContainerSpec(
250254
return podContainer
251255
}
252256

257+
const all = extension.spec?.containers?.find(
258+
c => c.name === DEFAULT_CONTAINER_EXTENSION_NAME
259+
)
260+
261+
if (all) {
262+
mergeContainerWithOptions(podContainer, all)
263+
}
264+
253265
const from = extension.spec?.containers?.find(
254266
c => c.name === CONTAINER_EXTENSION_PREFIX + name
255267
)

0 commit comments

Comments
 (0)