From cb50f5f88f35ff3cea3ddf0acb5b5e1799301325 Mon Sep 17 00:00:00 2001 From: Linos Giannopoulos Date: Fri, 24 Mar 2023 13:10:49 +0200 Subject: [PATCH] Make runner pod resources configurable By default containers spun up within workflow jobs run without any resource requests/limits. This commit enables us to set them through env vars passed on to the runner pod itself. This is done for both the job containers, and Github action steps --- package.json | 2 +- packages/k8s/src/hooks/prepare-job.ts | 16 +++++++++++++++- packages/k8s/src/hooks/run-container-step.ts | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5897a4ad..fb4f8a70 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hooks", - "version": "0.3.1", + "version": "0.3.1-element", "description": "Three projects are included - k8s: a kubernetes hook implementation that spins up pods dynamically to run a job - docker: A hook implementation of the runner's docker implementation - A hook lib, which contains shared typescript definitions and utilities that the other packages consume", "main": "", "directories": { diff --git a/packages/k8s/src/hooks/prepare-job.ts b/packages/k8s/src/hooks/prepare-job.ts index 7d9a1682..e8d24b73 100644 --- a/packages/k8s/src/hooks/prepare-job.ts +++ b/packages/k8s/src/hooks/prepare-job.ts @@ -162,10 +162,24 @@ export function createContainerSpec( container.entryPointArgs = DEFAULT_CONTAINER_ENTRY_POINT_ARGS } + const resources = new k8s.V1ResourceRequirements() + const limit_cpu = process.env.ACTIONS_POD_RESOURCE_LIMIT_CPU + const limit_memory = process.env.ACTIONS_POD_RESOURCE_LIMIT_MEMORY + const request_memory = process.env.ACTIONS_POD_RESOURCE_REQUEST_MEMORY + const request_cpu = process.env.ACTIONS_POD_RESOURCE_REQUEST_CPU + resources.requests = { + ...(request_cpu != undefined) && {cpu: request_cpu}, + ...(request_memory != undefined) && {memory: request_memory}, + } + resources.limits = { + ...(limit_cpu != undefined) && {cpu: limit_cpu}, + ...(limit_memory != undefined) && {memory: limit_memory}, + } const podContainer = { name, image: container.image, - ports: containerPorts(container) + ports: containerPorts(container), + resources: resources } as k8s.V1Container if (container.workingDirectory) { podContainer.workingDir = container.workingDirectory diff --git a/packages/k8s/src/hooks/run-container-step.ts b/packages/k8s/src/hooks/run-container-step.ts index 3fc1ee62..e74e1976 100644 --- a/packages/k8s/src/hooks/run-container-step.ts +++ b/packages/k8s/src/hooks/run-container-step.ts @@ -80,8 +80,22 @@ function createPodSpec( secretName?: string ): k8s.V1Container { const podContainer = new k8s.V1Container() + const resources = new k8s.V1ResourceRequirements() + const limit_cpu = process.env.ACTIONS_POD_RESOURCE_LIMIT_CPU + const limit_memory = process.env.ACTIONS_POD_RESOURCE_LIMIT_MEMORY + const request_memory = process.env.ACTIONS_POD_RESOURCE_REQUEST_MEMORY + const request_cpu = process.env.ACTIONS_POD_RESOURCE_REQUEST_CPU + resources.requests = { + ...(request_cpu != undefined) && {cpu: request_cpu}, + ...(request_memory != undefined) && {memory: request_memory}, + } + resources.limits = { + ...(limit_cpu != undefined) && {cpu: limit_cpu}, + ...(limit_memory != undefined) && {memory: limit_memory}, + } podContainer.name = JOB_CONTAINER_NAME podContainer.image = container.image + podContainer.resources = resources const { entryPoint, entryPointArgs } = container container.entryPoint = 'sh'