Skip to content

Commit d9c014e

Browse files
committed
Allow setting request+lmit for cpu and memory resources
1 parent eb4e0cc commit d9c014e

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,22 @@ Should be used with some care, since the actual storage used is outside the cont
177177

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

180+
### `resources-request-cpu` (optional, string)
181+
182+
Sets [cpu request](https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/) for the build container.
183+
184+
### `resources-limit-cpu` (optional, string)
185+
186+
Sets [cpu limit](https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/) for the build container.
187+
188+
### `resources-request-memory` (optional, string)
189+
190+
Sets [memory request](https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/) for the build container.
191+
192+
### `resources-limit-memory` (optional, string)
193+
194+
Sets [memory limit](https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/) for the build container.
195+
180196
### `workdir` (optional, string)
181197

182198
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.

lib/job.jsonnet

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ function(jobName, agentEnv={}, stepEnvFile='', patchFunc=identity) patchFunc({
5252
BUILDKITE_PLUGIN_K8S_MOUNT_SECRET: '',
5353
BUILDKITE_PLUGIN_K8S_MOUNT_BUILDKITE_AGENT: 'true',
5454
BUILDKITE_PLUGIN_K8S_PRIVILEGED: 'false',
55+
BUILDKITE_PLUGIN_K8S_RESOURCES_REQUEST_CPU: '',
56+
BUILDKITE_PLUGIN_K8S_RESOURCES_LIMIT_CPU: '',
57+
BUILDKITE_PLUGIN_K8S_RESOURCES_REQUEST_MEMORY: '',
58+
BUILDKITE_PLUGIN_K8S_RESOURCES_LIMIT_MEMORY: '',
5559
BUILDKITE_PLUGIN_K8S_WORKDIR: std.join('/', [env.BUILDKITE_BUILD_PATH, buildSubPath]),
5660
} + agentEnv,
5761

@@ -276,6 +280,24 @@ function(jobName, agentEnv={}, stepEnvFile='', patchFunc=identity) patchFunc({
276280
securityContext: {
277281
privileged: std.asciiLower(env.BUILDKITE_PLUGIN_K8S_PRIVILEGED) == 'true',
278282
},
283+
resources: {
284+
requests:
285+
(if env.BUILDKITE_PLUGIN_K8S_RESOURCES_REQUEST_CPU != '' then
286+
{ cpu: env.BUILDKITE_PLUGIN_K8S_RESOURCES_REQUEST_CPU }
287+
else {})
288+
+
289+
(if env.BUILDKITE_PLUGIN_K8S_RESOURCES_REQUEST_MEMORY != '' then
290+
{ memory: env.BUILDKITE_PLUGIN_K8S_RESOURCES_REQUEST_MEMORY }
291+
else {}),
292+
limits:
293+
(if env.BUILDKITE_PLUGIN_K8S_RESOURCES_LIMIT_CPU != '' then
294+
{ cpu: env.BUILDKITE_PLUGIN_K8S_RESOURCES_LIMIT_CPU }
295+
else {})
296+
+
297+
(if env.BUILDKITE_PLUGIN_K8S_RESOURCES_LIMIT_MEMORY != '' then
298+
{ memory: env.BUILDKITE_PLUGIN_K8S_RESOURCES_LIMIT_MEMORY }
299+
else {}),
300+
},
279301
volumeMounts: [
280302
{ mountPath: env.BUILDKITE_PLUGIN_K8S_WORKDIR, name: 'build', subPath: buildSubPath },
281303
{ mountPath: '/build', name: 'build', subPath: buildSubPath },

plugin.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ configuration:
4949
type: string
5050
patch:
5151
type: string
52+
resources-request-cpu:
53+
type: string
54+
resources-limit-cpu:
55+
type: string
56+
resources-request-memory:
57+
type: string
58+
resources-limit-memory:
59+
type: string
5260
required:
5361
- image
5462
additionalProperties: false

0 commit comments

Comments
 (0)