diff --git a/examples/extension.yaml b/examples/extension.yaml index 9e828536..15bb48fa 100644 --- a/examples/extension.yaml +++ b/examples/extension.yaml @@ -9,7 +9,7 @@ spec: runAsGroup: 3000 restartPolicy: Never containers: - - name: $job # overwirtes job container + - name: $job # overwrites job container env: - name: ENV1 value: "value1" @@ -20,11 +20,22 @@ spec: args: - -c - sleep 50 + - name: $redis # overwrites redis service + env: + - name: ENV2 + value: "value2" + image: "busybox:1.28" # Ignored + resources: + requests: + memory: "1Mi" + cpu: "1" + limits: + memory: "1Gi" + cpu: "2" - name: side-car image: "ubuntu:latest" # required command: - - sh + - sh args: - - -c - - sleep 60 - + - -c + - sleep 60 diff --git a/packages/k8s/src/hooks/constants.ts b/packages/k8s/src/hooks/constants.ts index a5d63a16..293de34f 100644 --- a/packages/k8s/src/hooks/constants.ts +++ b/packages/k8s/src/hooks/constants.ts @@ -41,6 +41,7 @@ export function getSecretName(): string { export const MAX_POD_NAME_LENGTH = 63 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' diff --git a/packages/k8s/src/hooks/prepare-job.ts b/packages/k8s/src/hooks/prepare-job.ts index f1facbfa..7f3d81b6 100644 --- a/packages/k8s/src/hooks/prepare-job.ts +++ b/packages/k8s/src/hooks/prepare-job.ts @@ -26,7 +26,7 @@ import { PodPhase, fixArgs } from '../k8s/utils' -import { JOB_CONTAINER_EXTENSION_NAME, JOB_CONTAINER_NAME } from './constants' +import { CONTAINER_EXTENSION_PREFIX, JOB_CONTAINER_NAME } from './constants' export async function prepareJob( args: PrepareJobArgs, @@ -60,7 +60,7 @@ export async function prepareJob( service, generateContainerName(service.image), false, - undefined + extension ) }) } @@ -235,7 +235,7 @@ export function createContainerSpec( } const from = extension.spec?.containers?.find( - c => c.name === JOB_CONTAINER_EXTENSION_NAME + c => c.name === CONTAINER_EXTENSION_PREFIX + name ) if (from) { diff --git a/packages/k8s/src/k8s/utils.ts b/packages/k8s/src/k8s/utils.ts index 53da888c..0358155f 100644 --- a/packages/k8s/src/k8s/utils.ts +++ b/packages/k8s/src/k8s/utils.ts @@ -6,7 +6,7 @@ import { Mount } from 'hooklib' import * as path from 'path' import { v1 as uuidv4 } from 'uuid' import { POD_VOLUME_NAME } from './index' -import { JOB_CONTAINER_EXTENSION_NAME } from '../hooks/constants' +import { CONTAINER_EXTENSION_PREFIX } from '../hooks/constants' import * as shlex from 'shlex' export const DEFAULT_CONTAINER_ENTRY_POINT_ARGS = [`-f`, `/dev/null`] @@ -180,7 +180,7 @@ export function mergeContainerWithOptions( ): void { for (const [key, value] of Object.entries(from)) { if (key === 'name') { - if (value !== base.name && value !== JOB_CONTAINER_EXTENSION_NAME) { + if (value !== CONTAINER_EXTENSION_PREFIX + base.name) { core.warning("Skipping name override: name can't be overwritten") } continue @@ -209,7 +209,9 @@ export function mergePodSpecWithOptions( for (const [key, value] of Object.entries(from)) { if (key === 'containers') { base.containers.push( - ...from.containers.filter(e => !e.name?.startsWith('$')) + ...from.containers.filter( + e => !e.name?.startsWith(CONTAINER_EXTENSION_PREFIX) + ) ) } else if (key === 'volumes' && value) { const volumes = value as k8s.V1Volume[] diff --git a/packages/k8s/tests/prepare-job-test.ts b/packages/k8s/tests/prepare-job-test.ts index 80cb6dc7..c2df2c92 100644 --- a/packages/k8s/tests/prepare-job-test.ts +++ b/packages/k8s/tests/prepare-job-test.ts @@ -133,6 +133,8 @@ describe('Prepare job', () => { expect(got.spec?.containers[1].image).toBe('redis') expect(got.spec?.containers[1].command).toBeFalsy() expect(got.spec?.containers[1].args).toBeFalsy() + expect(got.spec?.containers[1].env).toBe([ { name: 'ENV2', value: 'value2' } ]) + expect(got.spec?.containers[1].resources).toBe({ requests: { memory: "1Mi", cpu: "1"}, limits: { memory: "1Gi", cpu: "2" }}) // side-car expect(got.spec?.containers[2].name).toBe('side-car') expect(got.spec?.containers[2].image).toBe('ubuntu:latest')