Skip to content

Commit a41cb04

Browse files
committed
Add patch property to allow arbitrary transforms as post-processing
1 parent 59ff42e commit a41cb04

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,21 @@ Optionally mount an existing [Persistent Volume Claim](https://kubernetes.io/doc
150150

151151
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.
152152

153+
### `patch` (optional, string)
154+
155+
(Advanced / hack use). Provide a [jsonnet](https://jsonnet.org/) function to transform the resulting job manifest.
156+
157+
Example:
158+
```
159+
function(job) job {
160+
metadata: {
161+
labels: job.metadata.labels {
162+
foo: 'some extra label value',
163+
},
164+
},
165+
}
166+
```
167+
153168
## License
154169

155170
Apache 2.0 (see [LICENSE](LICENSE))

hooks/command

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,17 @@ function tail_logs {
2222

2323
echo "--- :kubernetes: Starting Kubernetes Job ($(kubectl config current-context))"
2424

25+
patchFunc="identity"
26+
if [[ -n "${BUILDKITE_PLUGIN_K8S_PATCH}" ]]; then
27+
patchFunc=${BUILDKITE_PLUGIN_K8S_PATCH}
28+
fi
29+
export patchFunc
30+
2531
jsonnet \
2632
--tla-str "jobName=${job_name}" \
2733
--tla-str-file "stepEnvFile=${BUILDKITE_ENV_FILE}" \
2834
--tla-code "agentEnv=$(jq -c -n env)" \
35+
--tla-code patchFunc \
2936
"${basedir}/lib/job.jsonnet" \
3037
| kubectl apply -f -
3138

lib/job.jsonnet

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ local allowedEnvs = std.set(
2626
]
2727
);
2828

29-
function(jobName, agentEnv={}, stepEnvFile='') {
29+
local identity = function(f) f;
30+
31+
function(jobName, agentEnv={}, stepEnvFile='', patchFunc=identity) patchFunc({
3032
local env = {
3133
BUILDKITE_PLUGIN_K8S_SECRET_NAME: 'buildkite',
3234
BUILDKITE_PLUGIN_K8S_GIT_CREDENTIALS_SECRET_KEY: '',
@@ -236,4 +238,4 @@ function(jobName, agentEnv={}, stepEnvFile='') {
236238
},
237239
},
238240
},
239-
}
241+
})

plugin.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ configuration:
4343
type: string
4444
workdir:
4545
type: string
46+
patch:
47+
type: string
4648
required:
4749
- image
4850
additionalProperties: false

0 commit comments

Comments
 (0)