|
1 | 1 | # coder-k8s |
2 | 2 |
|
| 3 | +[](https://github.com/coder/coder-k8s/actions/workflows/ci.yaml) |
| 4 | +[](./go.mod) |
| 5 | +[](./LICENSE) |
| 6 | + |
3 | 7 | > [!WARNING] |
4 | 8 | > **Highly Experimental / Alpha Software** |
5 | 9 | > This repository is a **hackathon contribution** and remains a **highly experimental, alpha-stage** project. |
6 | 10 | > **Do not use this in production or expose it to end users.** |
7 | | -> |
8 | | -## Project description |
9 | 11 |
|
10 | | -`coder-k8s` is a Go-based Kubernetes control-plane project with two app modes: |
| 12 | +`coder-k8s` is a Kubernetes control-plane project for managing Coder-related resources with native Kubernetes APIs. |
| 13 | + |
| 14 | +## What this project provides |
| 15 | + |
| 16 | +- A controller-runtime operator for `coder.com/v1alpha1` resources: |
| 17 | + - `CoderControlPlane` |
| 18 | + - `CoderProvisioner` |
| 19 | + - `CoderWorkspaceProxy` |
| 20 | +- An aggregated API server for `aggregation.coder.com/v1alpha1` resources: |
| 21 | + - `CoderWorkspace` |
| 22 | + - `CoderTemplate` |
| 23 | +- An MCP HTTP server for operational tooling. |
| 24 | +- A single binary that can run in all-in-one mode or split app modes. |
11 | 25 |
|
12 | | -- A `controller-runtime` operator for managing `CoderControlPlane` and |
13 | | - `CoderWorkspaceProxy` resources (`coder.com/v1alpha1`). |
14 | | -- An aggregated API server for `CoderWorkspace` and `CoderTemplate` resources |
15 | | - (`aggregation.coder.com/v1alpha1`). |
| 26 | +## Application modes |
| 27 | + |
| 28 | +| Mode | Description | Typical usage | |
| 29 | +| --- | --- | --- | |
| 30 | +| `all` (default) | Runs controller + aggregated API + MCP HTTP together | Local dev, demos, simple cluster deployment | |
| 31 | +| `controller` | Runs only Kubernetes reconcilers | Controller-focused debugging and e2e smoke flows | |
| 32 | +| `aggregated-apiserver` | Runs only aggregated API server | Split deployments with explicit Coder backend flags | |
| 33 | +| `mcp-http` | Runs only MCP HTTP server | MCP-focused integrations | |
16 | 34 |
|
17 | 35 | ## Prerequisites |
18 | 36 |
|
19 | 37 | - Go 1.25+ (`go.mod` currently declares Go 1.25.7) |
20 | | -- A Kubernetes cluster (OrbStack is recommended for local development; any cluster works) |
21 | | -- `kubectl` configured to point at your cluster context |
| 38 | +- A Kubernetes cluster (OrbStack, KIND, or any conformant cluster) |
| 39 | +- `kubectl` configured for your target cluster |
22 | 40 |
|
23 | | -## Quick start / Local development (OrbStack) |
| 41 | +## Quick start (local controller run) |
24 | 42 |
|
25 | 43 | ```bash |
26 | | -# Generate CRD and RBAC manifests |
| 44 | +# Generate and apply CRDs |
27 | 45 | make manifests |
28 | | - |
29 | | -# Apply CRDs to your cluster |
30 | 46 | kubectl apply -f config/crd/bases/ |
31 | 47 |
|
32 | | -# Run the controller locally (uses your kubeconfig context) |
| 48 | +# Run controller locally against your kubeconfig context |
33 | 49 | GOFLAGS=-mod=vendor go run . --app=controller |
34 | 50 |
|
35 | | -# In another terminal: apply the sample CR |
| 51 | +# In another terminal, apply a sample control plane |
36 | 52 | kubectl apply -f config/samples/coder_v1alpha1_codercontrolplane.yaml |
37 | 53 |
|
38 | | -# Verify |
| 54 | +# Verify resource creation |
39 | 55 | kubectl get codercontrolplanes -A |
40 | 56 | ``` |
41 | 57 |
|
42 | | -## Examples |
43 | | - |
44 | | -- [`examples/cloudnativepg/`](examples/cloudnativepg/) - Deploy a `CoderControlPlane` with a CloudNativePG-managed PostgreSQL backend. |
45 | | - |
46 | | -## KIND development cluster (for k9s demos) |
47 | | - |
48 | | -Bootstrap a KIND cluster and install CRDs/RBAC (**this also switches your current kubectl context**): |
| 58 | +## Documentation |
49 | 59 |
|
50 | | -```bash |
51 | | -make kind-dev-up |
52 | | -``` |
| 60 | +The project docs follow Diátaxis and live in `docs/`. |
53 | 61 |
|
54 | | -> Tip: override defaults when needed: |
55 | | -> |
56 | | -> - Use `CLUSTER_NAME` to run multiple clusters in parallel. |
57 | | -> - Use `KIND_NODE_IMAGE` to pin the node image (default: `kindest/node:v1.34.0`). |
58 | | -> |
59 | | -> ```bash |
60 | | -> CLUSTER_NAME=my-cluster make kind-dev-up |
61 | | -> KIND_NODE_IMAGE=kindest/node:v1.32.0 make kind-dev-up |
62 | | -> ``` |
| 62 | +- Home: [`docs/index.md`](docs/index.md) |
| 63 | +- Tutorial: [`docs/tutorials/getting-started.md`](docs/tutorials/getting-started.md) |
| 64 | +- How-to guides: [`docs/how-to/`](docs/how-to/) |
| 65 | +- Architecture: [`docs/explanation/architecture.md`](docs/explanation/architecture.md) |
| 66 | +- API reference: [`docs/reference/api/`](docs/reference/api/) |
63 | 67 |
|
64 | | -> If the cluster already exists and you change `KIND_NODE_IMAGE`, run `make kind-dev-down` first so the new image can be applied. |
65 | | -> |
66 | | -If you need to switch your kubectl context later: |
| 68 | +Serve docs locally: |
67 | 69 |
|
68 | 70 | ```bash |
69 | | -make kind-dev-ctx |
70 | | -# or: CLUSTER_NAME=my-cluster make kind-dev-ctx |
| 71 | +make docs-serve |
71 | 72 | ``` |
72 | 73 |
|
73 | | -Start the controller (pick one): |
74 | | - |
75 | | -- Out-of-cluster (fast iteration): |
76 | | - |
77 | | - ```bash |
78 | | - GOFLAGS=-mod=vendor go run . --app=controller |
79 | | - ``` |
| 74 | +## Examples |
80 | 75 |
|
81 | | -- In-cluster (closer to CI): |
| 76 | +- [`examples/cloudnativepg/`](examples/cloudnativepg/) — Deploy a `CoderControlPlane` with a CloudNativePG-managed PostgreSQL backend. |
82 | 77 |
|
83 | | - ```bash |
84 | | - make kind-dev-load-image |
85 | | - kubectl apply -f config/e2e/deployment.yaml |
86 | | - kubectl -n coder-system wait --for=condition=Available deploy/coder-k8s --timeout=120s |
87 | | - ``` |
| 78 | +## KIND development cluster (k9s demos) |
88 | 79 |
|
89 | | -Demo: |
| 80 | +Bootstrap a KIND cluster and install CRDs/RBAC (**this switches current kubectl context**): |
90 | 81 |
|
91 | 82 | ```bash |
92 | | -make kind-dev-k9s |
| 83 | +make kind-dev-up |
93 | 84 | ``` |
94 | 85 |
|
95 | | -Cleanup: |
| 86 | +Useful helpers: |
96 | 87 |
|
97 | 88 | ```bash |
| 89 | +make kind-dev-status |
| 90 | +make kind-dev-ctx |
| 91 | +make kind-dev-load-image |
| 92 | +make kind-dev-k9s |
98 | 93 | make kind-dev-down |
99 | 94 | ``` |
100 | 95 |
|
101 | | -Mux users: there is an optional agent skill (`kind-dev`) under `.mux/skills/` with agent-oriented instructions for running per-workspace KIND clusters. |
102 | | - |
103 | 96 | ## Essential commands |
104 | 97 |
|
105 | 98 | | Command | Description | |
106 | 99 | | --- | --- | |
107 | | -| `make build` | Build the project | |
108 | | -| `make test` | Run tests | |
109 | | -| `make manifests` | Generate CRD/RBAC manifests | |
110 | | -| `make codegen` | Run deepcopy code generation | |
111 | | -| `make verify-vendor` | Verify vendor consistency | |
112 | | -| `make lint` | Run linter (requires `golangci-lint`) | |
113 | | -| `make vuln` | Run vulnerability check (requires `govulncheck`) | |
114 | | -| `make docs-serve` | Serve the documentation site locally (requires `mkdocs`) | |
| 100 | +| `make build` | Build all packages | |
| 101 | +| `make test` | Run unit + integration tests | |
| 102 | +| `make test-integration` | Run focused controller integration tests | |
| 103 | +| `make manifests` | Generate CRD and RBAC manifests | |
| 104 | +| `make codegen` | Run deepcopy generation | |
| 105 | +| `make docs-reference` | Regenerate API reference docs from Go types | |
115 | 106 | | `make docs-check` | Build docs in strict mode (CI-equivalent) | |
| 107 | +| `make verify-vendor` | Verify vendored dependency consistency | |
| 108 | +| `make lint` | Run linter + formatting checks | |
| 109 | +| `make vuln` | Run vulnerability scan | |
116 | 110 |
|
117 | | -## Testing strategy |
| 111 | +## Repository layout |
118 | 112 |
|
119 | | -- **Unit tests**: `make test` runs all tests, including unit tests in `main_test.go`. |
120 | | -- **Integration tests**: Use `envtest` to exercise reconciliation against a lightweight API server (no real cluster needed). Run them via `make test` (included in the full suite) or `make test-integration` (focused on controller tests only). |
121 | | -- **E2E smoke tests**: Recommended CI smoke coverage uses a Kind-based flow that deploys the controller image and verifies pod health. |
| 113 | +- `api/v1alpha1/` — CRD API types (`coder.com/v1alpha1`) |
| 114 | +- `api/aggregation/v1alpha1/` — aggregated API types (`aggregation.coder.com/v1alpha1`) |
| 115 | +- `internal/app/` — app mode entrypoints (`allapp`, `controllerapp`, `apiserverapp`, `mcpapp`) |
| 116 | +- `internal/controller/` — controller reconcilers |
| 117 | +- `internal/aggregated/` — aggregated storage + Coder client/provider logic |
| 118 | +- `config/` — generated CRDs, RBAC, samples |
| 119 | +- `deploy/` — deployable manifests for all-in-one, APIService, and MCP service |
| 120 | +- `docs/` — user-facing documentation site content |
| 121 | +- `hack/` — code generation and maintenance scripts |
122 | 122 |
|
123 | | -## Project structure |
| 123 | +## Contributing |
124 | 124 |
|
125 | | -- `api/v1alpha1/` — CRD types and generated deepcopy code |
126 | | -- `internal/controller/` — Reconciliation logic |
127 | | -- `config/crd/bases/` — Generated CRD manifests |
128 | | -- `config/rbac/` — RBAC manifests (generated role + deployment bindings) |
129 | | -- `config/samples/` — Sample custom resources |
130 | | -- `hack/` — Code generation and maintenance scripts |
| 125 | +Before opening a PR, run at least: |
| 126 | + |
| 127 | +```bash |
| 128 | +make verify-vendor |
| 129 | +make test |
| 130 | +make build |
| 131 | +make lint |
| 132 | +make docs-check |
| 133 | +``` |
131 | 134 |
|
132 | 135 | ## License |
133 | 136 |
|
|
0 commit comments