Skip to content

CoderTemplateTest: test a template version like a Kubernetes Job #152

Closed

Description

@ThomasK33

Goal: a CRD that creates a throwaway workspace from a template version, waits until its agent is healthy, records Succeeded or Failed, and deletes the workspace.

Uses: gate template promotion in GitOps (Argo CD and Flux read the condition); nightly template checks.

First slice: provisioning and agent health only. Running a command inside the workspace is a later, separate security slice.

Open points: cleanup after controller crashes (finalizer plus labels), timeouts, which Coder user owns the test workspace, cost of leaked workspaces.

Acceptance: envtest for the state machine and cleanup; Kind dogfood with a passing and a failing template; docs.

Owner: maintainer desk.


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: medium

Activity

  1. self-assigned this
    on Oct 2, 2026
  2. 27 remaining items

  3. ThomasK33 commented on Oct 3, 2026

    @ThomasK33
    MemberAuthor

    Done: CoderTemplateTest

    CoderTemplateTest is active on main. A test creates a throwaway workspace from one template version, waits until every top-level agent is connected and ready, records Succeeded or Failed, and deletes the workspace. Argo CD and Flux can read the result through the health rules in config/gitops/.

    The acceptance criteria of this issue are met:

    • envtest covers the state machine and cleanup, including restart replay, namespace teardown, and a lost control plane.
    • Kind E2E runs a passing template and failing ones (agent failure, bad parameter), plus restart, immutability, dry run, TTL, tester key count, and namespace deletion while Coder is unreachable.
    • Docs: the how-to, the GitOps page, troubleshooting, the API reference, and a sample.

    Pull requests (all merged into main)

    PR Content
    #194, #195 Test-local stateful fake Coder
    #196 Dormant API types
    #197 Dormant reconciler skeleton
    #199 Owner, template, and version lookups
    #200 Create request behind a marker
    #201 Confirm an uncertain create with provenance
    #202 Workspace readiness
    #203 Cleanup decisions and finalizer release
    #204 Workspace delete
    #205 TTL after a finished test
    #206 Claimed prebuilds in provenance
    #207 Activation blockers
    #208 Kind E2E fixture with a real agent
    #210 Activation of the controller
    #211 Remaining Kind E2E phases
    #212 GitOps health rules and page
    #213 Complete how-to, troubleshooting, and sample

    Changes to the original plan

    1. Lost control plane. If the referenced CoderControlPlane is gone or being deleted, the controller releases the finalizer at once (ControlPlaneGone). Deleting a namespace never deadlocks on a test.
    2. Escape hatch. coder.com/deletion-policy: retain (Lifecycle policy annotations for controller-managed Coder objects #151) releases a stuck test without a Coder call. It works only when the control plane sets spec.templateTests.allowRetain: true, because any test creator can set the annotation. Without the opt-in, an admin removes the finalizer by hand.
    3. Uncertain creates. After the settle window, the controller releases a test as NotCreated only if no workspace exists and the operator user can see every workspace. A workspace without proof of ownership keeps the finalizer (OwnershipUnknown).
    4. 404 is not deletion. Only Coder's 410 proves that a workspace is deleted. A 404 can mean lost read access, so the test waits.
    5. Agents. An agent that disconnects after it was ready makes the test wait, not fail. Devcontainer sub-agents do not count.
    6. Dormant owners. Coder creates API users as dormant and refuses their agents, so the controller refuses a dormant owner (OwnerNotEligible).
    7. Tester keys. Keys do not accumulate. The Kind E2E counted 0 tester API keys before and after three tests.
    8. Scope cuts. CI does not run Argo CD or Flux. Unit tests run the Lua rule with gopher-lua and the Flux expressions with cel-go. The GitOps page lists what a promotion step must check, but has no runnable promotion example (docs: add a runnable promotion example for CoderTemplateTest GitOps gating #216).

    Known limits and follow-ups

    Closing as complete.


    Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementA proposed feature or improvement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions