Skip to content

Commit

Permalink
Allow setting request+lmit for cpu and memory resources
Browse files Browse the repository at this point in the history
  • Loading branch information
dln committed Jun 5, 2019
1 parent eb4e0cc commit d9c014e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,22 @@ Should be used with some care, since the actual storage used is outside the cont

Example: `/var/lib/buildkite/builds`

### `resources-request-cpu` (optional, string)

Sets [cpu request](https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/) for the build container.

### `resources-limit-cpu` (optional, string)

Sets [cpu limit](https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/) for the build container.

### `resources-request-memory` (optional, string)

Sets [memory request](https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/) for the build container.

### `resources-limit-memory` (optional, string)

Sets [memory limit](https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/) for the build container.

### `workdir` (optional, string)

Override the working directory to run the command in, inside the container. The default is the build directory where the buildkite bootstrap and git checkout runs.
Expand Down
22 changes: 22 additions & 0 deletions lib/job.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ function(jobName, agentEnv={}, stepEnvFile='', patchFunc=identity) patchFunc({
BUILDKITE_PLUGIN_K8S_MOUNT_SECRET: '',
BUILDKITE_PLUGIN_K8S_MOUNT_BUILDKITE_AGENT: 'true',
BUILDKITE_PLUGIN_K8S_PRIVILEGED: 'false',
BUILDKITE_PLUGIN_K8S_RESOURCES_REQUEST_CPU: '',
BUILDKITE_PLUGIN_K8S_RESOURCES_LIMIT_CPU: '',
BUILDKITE_PLUGIN_K8S_RESOURCES_REQUEST_MEMORY: '',
BUILDKITE_PLUGIN_K8S_RESOURCES_LIMIT_MEMORY: '',
BUILDKITE_PLUGIN_K8S_WORKDIR: std.join('/', [env.BUILDKITE_BUILD_PATH, buildSubPath]),
} + agentEnv,

Expand Down Expand Up @@ -276,6 +280,24 @@ function(jobName, agentEnv={}, stepEnvFile='', patchFunc=identity) patchFunc({
securityContext: {
privileged: std.asciiLower(env.BUILDKITE_PLUGIN_K8S_PRIVILEGED) == 'true',
},
resources: {
requests:
(if env.BUILDKITE_PLUGIN_K8S_RESOURCES_REQUEST_CPU != '' then
{ cpu: env.BUILDKITE_PLUGIN_K8S_RESOURCES_REQUEST_CPU }
else {})
+
(if env.BUILDKITE_PLUGIN_K8S_RESOURCES_REQUEST_MEMORY != '' then
{ memory: env.BUILDKITE_PLUGIN_K8S_RESOURCES_REQUEST_MEMORY }
else {}),
limits:
(if env.BUILDKITE_PLUGIN_K8S_RESOURCES_LIMIT_CPU != '' then
{ cpu: env.BUILDKITE_PLUGIN_K8S_RESOURCES_LIMIT_CPU }
else {})
+
(if env.BUILDKITE_PLUGIN_K8S_RESOURCES_LIMIT_MEMORY != '' then
{ memory: env.BUILDKITE_PLUGIN_K8S_RESOURCES_LIMIT_MEMORY }
else {}),
},
volumeMounts: [
{ mountPath: env.BUILDKITE_PLUGIN_K8S_WORKDIR, name: 'build', subPath: buildSubPath },
{ mountPath: '/build', name: 'build', subPath: buildSubPath },
Expand Down
8 changes: 8 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ configuration:
type: string
patch:
type: string
resources-request-cpu:
type: string
resources-limit-cpu:
type: string
resources-request-memory:
type: string
resources-limit-memory:
type: string
required:
- image
additionalProperties: false

0 comments on commit d9c014e

Please sign in to comment.