Skip to content

fix: give every K8s workspace pod the standard Coder label set - #179

Merged
nboyers merged 1 commit into
mainfrom
fix/normalize-workspace-pod-labels
Aug 17, 2026
Merged

fix: give every K8s workspace pod the standard Coder label set#179
nboyers merged 1 commit into
mainfrom
fix/normalize-workspace-pod-labels

Conversation

@nboyers

@nboyers nboyers commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Why

Prerequisite for network policy. Six templates were invisible to label selectors, so nothing could select "a Coder workspace pod" fleet-wide:

Template Labels it actually had
datasci, devbox, universal-sandbox, memorycard, realworld com.coder.workspace.uuid only — Coder identity was in annotations, which label selectors cannot match
envbox none at all

Only coder-selenium-demo and awshp-k8s-with-kiro-cli carried the full set. Namespace was the only universal handle.

What

All six now carry the same set those two already use: app.kubernetes.io/{name,instance,part-of}, com.coder.resource, and the workspace/user id and name.

The immutable-selector trap, and how this avoids it

In the five Deployment-based templates, local.labels feeds both the pod template and spec.selector.match_labels. The selector is immutable in Kubernetes — changing it forces a Deployment replacement and recreates every running workspace.

So local.labels is left untouched and a new local is added:

pod_labels = merge(local.labels, { ...standard set... })

applied to the pod template only. merge() guarantees pod_labels ⊇ labels, which is what Kubernetes requires of the selector. Verified in the diff: match_labels is unchanged in all five.

envbox is a bare Pod with no selector constraint, so it gets the set directly.

com.coder.user.email deliberately stays an annotation: @ is not a valid label value.

Testing

terraform validate and terraform fmt -check pass on all six. Agent validation will build a real workspace per template. The thing to confirm in review is that no Deployment is replaced — the pod is recreated (strategy = "Recreate"), PVCs survive, the agent reconnects.

🤖 Generated with Claude Code

Six templates were invisible to label selectors, which blocks any network policy
or fleet-wide query from selecting workspaces:

  datasci, devbox, universal-sandbox, memorycard, realworld
      one label only (com.coder.workspace.uuid); Coder identity lived in
      ANNOTATIONS, which label selectors cannot match
  envbox
      no labels at all

They now carry the same set selenium and awshp-k8s-with-kiro-cli already use:
app.kubernetes.io/{name,instance,part-of}, com.coder.resource, and the
workspace/user id and name.

The five Deployment-based templates use local.labels for BOTH the pod template
and spec.selector.match_labels, and the selector is immutable: changing it forces
a Deployment replacement and recreates running workspaces. So local.labels is
left untouched and a new local.pod_labels = merge(local.labels, {...}) is applied
to the pod template only. merge() guarantees pod_labels is a superset of labels,
which is what Kubernetes requires of the selector.

envbox is a bare Pod, so it has no selector constraint and gets the set directly.

com.coder.user.email stays an annotation: '@' is not a valid label value.

terraform validate passes on all six.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Coder Agents Chat: agent finished or is awaiting input

Chat: https://ai.coder.com/agents/90a15723-3d73-4af5-b308-846d21c76bc2
Status: waiting

@github-actions

Copy link
Copy Markdown

Agent Validation PASSED for template devbox

Field Value
Step ALL
Summary Template found, workspace created and verified.
Chat https://ai.coder.com/agents/90a15723-3d73-4af5-b308-846d21c76bc2
Workspace ID bda33216-b9e5-48d1-abe4-be42fdb6f40c
Workspace Status running
Workflow Run View logs

@github-actions

Copy link
Copy Markdown

Coder Agents Chat: agent finished or is awaiting input

Chat: https://ai.coder.com/agents/f5e0f0bd-a176-4b28-83c8-4c61969048f3
Status: waiting

@github-actions

Copy link
Copy Markdown

Agent Validation PASSED for template memorycard

Field Value
Step ALL
Summary Template found, workspace created and verified.
Chat https://ai.coder.com/agents/f5e0f0bd-a176-4b28-83c8-4c61969048f3
Workspace ID cfe09212-bccf-42de-9c60-902e38dd8088
Workspace Status running
Workflow Run View logs

@github-actions

Copy link
Copy Markdown

Coder Agents Chat: agent finished or is awaiting input

Chat: https://ai.coder.com/agents/6cc7db19-278b-468a-b70b-fa4ecea28ef9
Status: waiting

@github-actions

Copy link
Copy Markdown

Agent Validation PASSED for template realworld

Field Value
Step ALL
Summary Template found, workspace created and verified.
Chat https://ai.coder.com/agents/6cc7db19-278b-468a-b70b-fa4ecea28ef9
Workspace ID bfa7d802-3f5e-4fad-99aa-c7f0c122f807
Workspace Status running
Workflow Run View logs

@github-actions

Copy link
Copy Markdown

Coder Agents Chat: agent finished or is awaiting input

Chat: https://ai.coder.com/agents/ddc24fb6-7ee9-4748-b677-c351c8257c47
Status: waiting

@github-actions

Copy link
Copy Markdown

Agent Validation PASSED for template universal-sandbox

Field Value
Step ALL
Summary Template found, workspace created and verified.
Chat https://ai.coder.com/agents/ddc24fb6-7ee9-4748-b677-c351c8257c47
Workspace ID 37c9d2bb-78aa-4413-b12f-63615c851ccb
Workspace Status running
Workflow Run View logs

@github-actions

Copy link
Copy Markdown

Coder Agents Chat: agent finished or is awaiting input

Chat: https://ai.coder.com/agents/ff2b8d2e-671d-4b4d-b512-6e64d621f913
Status: waiting

@github-actions

Copy link
Copy Markdown

Agent Validation PASSED for template envbox

Field Value
Step ALL
Summary Template found, workspace created and verified.
Chat https://ai.coder.com/agents/ff2b8d2e-671d-4b4d-b512-6e64d621f913
Workspace ID 16c2d590-880f-4596-88ff-a6d8085aa8ff
Workspace Status running
Workflow Run View logs

@github-actions

Copy link
Copy Markdown

Coder Agents Chat: agent finished or is awaiting input

Chat: https://ai.coder.com/agents/4f64108e-dd50-40f1-ac66-0b4c384ff4b9
Status: waiting

@github-actions

Copy link
Copy Markdown

Agent Validation PASSED for template datasci

Field Value
Step ALL
Summary Template found, workspace created and verified.
Chat https://ai.coder.com/agents/4f64108e-dd50-40f1-ac66-0b4c384ff4b9
Workspace ID afba7cb5-bb92-440b-8c14-aa2ea470fcf1
Workspace Status running
Workflow Run View logs

@nboyers
nboyers merged commit 7995315 into main Aug 17, 2026
8 checks passed
@nboyers
nboyers deleted the fix/normalize-workspace-pod-labels branch August 17, 2026 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant