Skip to content

feat: add --job-context-dir to configure job coordination file locations#4090

Open
aeijdenberg-canva wants to merge 1 commit into
buildkite:mainfrom
aeijdenberg-canva:job-context-dir
Open

feat: add --job-context-dir to configure job coordination file locations#4090
aeijdenberg-canva wants to merge 1 commit into
buildkite:mainfrom
aeijdenberg-canva:job-context-dir

Conversation

@aeijdenberg-canva

Copy link
Copy Markdown

Description

When running under k8s we would like more control over where the start command writes it's socket and other job information which the other containers need to talk about to ti.

Context

The agent creates several files to coordinate with the processes running a job: the job env files (BUILDKITE_ENV_FILE / BUILDKITE_ENV_JSON_FILE), the job timeout marker file (BUILDKITE_AGENT_JOB_TIMEOUT_FILE), and, in Kubernetes mode, the socket that kubernetes-bootstrap connects to. The directory for these was previously hardcoded to /workspace in Kubernetes mode.

Changes

This adds a --job-context-dir flag (BUILDKITE_JOB_CONTEXT_DIR) to both agent start and kubernetes-bootstrap. All coordination files are created in that directory, with the socket at a predictable name within it (buildkite.sock).

Defaults are unchanged (os.TempDir(), or /workspace under --kubernetes-exec).

The env var is included in kubernetes-bootstrap's existingEnvPriority so that each container's own value survives the registration-env overlay (the shared volume may be mounted at different paths per container), and in protectedEnv so job-level env cannot redirect it.

Testing

  • Tests have run locally (with go test ./...). Buildkite employees may check this if the pipeline has run automatically.
  • Code is formatted (with go tool gofumpt -extra -w .)

Also deployed into our k8s environment with the new var set to a different directory and jobs ran fine.

Affiliation (optional, external contributors)

Canva

Disclosures / Credits

  • Claude helped write this change and test, I reviewed and asked it to make a bunch of changes along the way.

The agent creates several files to coordinate with the processes running
a job: the job env files (BUILDKITE_ENV_FILE / BUILDKITE_ENV_JSON_FILE),
the job timeout marker file (BUILDKITE_AGENT_JOB_TIMEOUT_FILE), and, in
Kubernetes mode, the socket that kubernetes-bootstrap connects to. The
directory for these was previously hardcoded: os.TempDir() normally, and
/workspace in Kubernetes mode.

This adds a --job-context-dir flag (BUILDKITE_JOB_CONTEXT_DIR) to both
`agent start` and `kubernetes-bootstrap`. All coordination files are
created in that directory, with the socket at a predictable name within
it (buildkite.sock). Only the directory needs to be agreed upon between
containers; the env/timeout file paths continue to flow to the other
containers through the registration env.

Defaults are unchanged (os.TempDir(), or /workspace under
--kubernetes-exec), so existing stacks are unaffected. A stack can set
BUILDKITE_JOB_CONTEXT_DIR pod-wide to a small dedicated shared volume,
and drop the workspace mount from the agent container.

The env var is included in kubernetes-bootstrap's existingEnvPriority so
that each container's own value survives the registration-env overlay
(the shared volume may be mounted at different paths per container), and
in protectedEnv so job-level env cannot redirect it.

Signed-off-by: Adam Eijdenberg <aeijdenberg@canva.com>
@aeijdenberg-canva aeijdenberg-canva requested review from a team as code owners July 16, 2026 03:27
@DrJosh9000 DrJosh9000 added the feature New user-facing feature! label Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New user-facing feature!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants