Skip to content

Commit

Permalink
Make runner pod resources configurable
Browse files Browse the repository at this point in the history
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
  • Loading branch information
linosgian committed Mar 24, 2023
1 parent 89ff7d1 commit cb50f5f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
16 changes: 15 additions & 1 deletion packages/k8s/src/hooks/prepare-job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions packages/k8s/src/hooks/run-container-step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit cb50f5f

Please sign in to comment.