Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions deploy/helm/scope/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ steps, see the [README](./README.md).
Port-forward the Portal if it isn't already running (see README "Verify"):

```bash
kubectl -n scope port-forward svc/scope-portal 5100:80
# Use global.namespace from your values file (scope unless customized).
NAMESPACE=scope
kubectl -n "$NAMESPACE" port-forward svc/scope-portal 5100:80
```

Then, at <http://localhost:5100>:
Expand Down Expand Up @@ -48,6 +50,35 @@ workers use this (they pull from ACR, not GHCR), as does `jobs.dbMigrate`
(which needs a separate `:builder`-tagged image — see
`templates/jobs/db-migrate.yaml`).

`image.digest`, when set for a service image, takes precedence over its tag
and `global.imageTag`. The MCP sidecars use this to pin the verified
`0.4.7-stdio` multi-architecture image. To change their release, update the
digest too; changing only `image.tag` leaves the pinned image unchanged.

## Namespace and workload identity

All chart resources use `global.namespace`. It must match both Bicep
federated-identity subjects:

- `workloadIdentityServiceAccountNamespace` for the backend identity.
- `workerWorkloadIdentityServiceAccountNamespace` for the worker identity,
when provisioned.

For example, to deploy into `scope-benchmarks`, provision **both** Bicep
namespace parameters as `scope-benchmarks` and keep the generated
`global.namespace: "scope-benchmarks"`. Use `--namespace scope-benchmarks`
with Helm and `scripts/bootstrap-workers.sh`, and `-n scope-benchmarks`
with `kubectl`. Always pass the same values file to worker bootstrap.
Changing only Helm's release namespace does not change `global.namespace`
or reconfigure Azure federation.

The generator requires the backend namespace output. Worker identity
outputs may all be absent for a backend-only deployment; if any are
present, the client ID, service-account name, and namespace must all be
present and their namespace must equal the backend's. Older deployments
missing namespace outputs must be re-deployed with the updated Bicep
outputs before generating values.

## Image registry strategy

By default, the six core services (api, portal, judge, token-manager,
Expand All @@ -59,7 +90,8 @@ No registry build step is required for these.
If you publish your own fork's images, override the registry:

```bash
helm install scope deploy/helm/scope -n scope \
NAMESPACE=scope # Must match global.namespace in my-values.yaml.
helm install scope deploy/helm/scope -n "$NAMESPACE" \
-f my-values.yaml \
--set global.imageRegistry=ghcr.io/<your-fork-owner>
```
Expand Down
40 changes: 35 additions & 5 deletions deploy/helm/scope/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ This README covers phases 2 and 3.
Provider CSI driver + workload identity, Key Vault, Storage, Cosmos DB,
Redis, ACR).
- `helm` and `kubectl`, configured against the target cluster.
- ACP workers require the Kubernetes `SidecarContainers` feature (enabled
by default since 1.29, stable since 1.33).

## Phase 2: Deploy the core app

Expand All @@ -28,11 +30,25 @@ This README covers phases 2 and 3.

Otherwise, hand-author `my-values.yaml` — see [Configuration](./CONFIGURATION.md).

The generated `global.namespace` comes from
`workloadIdentityServiceAccountNamespace`. If worker identity outputs are
present, their namespace must match: this chart uses a single namespace.
Missing required namespace outputs or mismatched identities stop generation
before the values file is written. Re-deploy the Bicep template with
matching namespace parameters rather than guessing a namespace.

**2. Install the chart:**

Use the **same namespace** for `global.namespace`, the Helm release, and
all later `kubectl`/worker-bootstrap commands. `--create-namespace` creates
the Helm release namespace, not a different `global.namespace`.

```bash
# Replace scope with global.namespace from my-values.yaml if customized.
NAMESPACE=scope

helm upgrade --install scope deploy/helm/scope \
--namespace scope --create-namespace \
--namespace "$NAMESPACE" --create-namespace \
-f my-values.yaml \
--wait --timeout 5m
```
Expand All @@ -46,7 +62,8 @@ Bicep doesn't provision — see
ACP coding-agent workers are disabled by default:

```bash
./scripts/bootstrap-workers.sh --acr <acrName>
./scripts/bootstrap-workers.sh --acr <acrName> \
--namespace "$NAMESPACE" --values-file my-values.yaml
```

Builds + pushes both worker images, enables their Deployments, and
Expand All @@ -57,17 +74,30 @@ API key they need yourself via the Portal's **Secrets** tab (or
## Verify

```bash
kubectl get pods -n scope
kubectl get pods -n "$NAMESPACE"

# No ingress yet — reach services via port-forward.
kubectl -n scope port-forward svc/api 18080:80 &
kubectl -n scope port-forward svc/scope-portal 5100:80 &
kubectl -n "$NAMESPACE" port-forward svc/api 18080:80 &
kubectl -n "$NAMESPACE" port-forward svc/scope-portal 5100:80 &

scope agent list --url http://localhost:18080 # or open http://localhost:5100
```

Then try an end-to-end run — see [Run a sample scenario](./SAMPLE-SCENARIO.md).

## Chart regression checks

With Helm 3 and `jq` on `PATH`, run:

```bash
pnpm exec vitest run scripts/helm-scope.test.ts scripts/generate-values-from-bicep.test.ts
```

These render the actual chart and run the generator against mocked Azure
outputs, including custom and mismatched namespaces. No cluster or Azure
credentials are used. The rendering suite is explicitly skipped when
Helm is not installed.

## Learn more

- [Configuration reference](./CONFIGURATION.md) — values.yaml conventions,
Expand Down
4 changes: 3 additions & 1 deletion deploy/helm/scope/SAMPLE-SCENARIO.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ projects — so run it yourself, once.
## Steps

```bash
kubectl -n scope port-forward svc/api 18080:80 &
# Use the same global.namespace as the Helm release and worker bootstrap.
NAMESPACE=scope
kubectl -n "$NAMESPACE" port-forward svc/api 18080:80 &

# Find the project to seed into: the "Initial Project" created by
# db-migrate on first install, or one of your own.
Expand Down
50 changes: 41 additions & 9 deletions deploy/helm/scope/WORKERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ templated yet (see
the intended production pattern). Bring them online with one command:

```bash
./scripts/bootstrap-workers.sh --acr <acrName>
# Use global.namespace from the original install's values file.
NAMESPACE=scope
./scripts/bootstrap-workers.sh --acr <acrName> \
--namespace "$NAMESPACE" --values-file my-values.yaml
```

This:
Expand All @@ -30,6 +33,12 @@ Run `./scripts/bootstrap-workers.sh --help` for all flags, including
`--skip-agent-registration`, and custom
`--namespace`/`--release`/`--chart`/`--image-tag`.

`--namespace` must match both the Helm release namespace and
`global.namespace` in your values file. For a custom namespace, provision
both backend and worker Bicep namespace parameters to that same value
before generating values; the chart cannot deploy the identities into
different namespaces.

> Pass `--values-file <path>` so the upgrade re-merges your original values
> override file against the chart's current defaults, instead of freezing a
> historical `--reuse-values` snapshot (which silently drops any default key
Expand Down Expand Up @@ -76,18 +85,37 @@ sidecar (`workers.<name>.mcpGateway`, enabled by default) that aggregates
MCP servers for the worker, mirroring docker-compose's
`mcp-gateway-copilot`/`mcp-gateway-claude-code` services:

- Uses the **0.4.7 stdio image pinned by multi-architecture digest** in
`values.yaml`, retaining Node.js/`npx`, `uvx`, and remote HTTP/SSE MCP
support. That release's
[`start --host` flag](https://github.com/mcpjungle/MCPJungle/blob/974e2fabe4694d3b613d281e6e4e8d2fa3f6da74/cmd/start.go)
binds the listener to `127.0.0.1:8080`. Development-mode registration is
unauthenticated, so it must not listen on the Pod IP; omitting a Service
does not prevent other pods from reaching a Pod IP.
- Templated as a **native sidecar** (`initContainers` entry with
`restartPolicy: Always`, GA since Kubernetes 1.29) rather than a regular
container, so kubelet starts it first and holds the Pod at `NotReady`
until its `/health` readiness probe passes — the worker's first task
never races a gateway that isn't listening yet.
`restartPolicy: Always`; stable since Kubernetes 1.33, enabled by default
since 1.29). Its **startup probe** gates the initial start of the worker
queue consumer until `/health` succeeds, retrying every two seconds for
up to approximately two minutes before restarting the sidecar.
A readiness probe alone only controls Pod readiness, not worker startup.
See the [Kubernetes lifecycle contract](https://kubernetes.io/docs/concepts/workloads/pods/sidecar-containers/#sidecar-containers-and-pod-lifecycle).
- Both probes execute the image's `curl` inside the container against
`http://127.0.0.1:8080/health`, with a two-second request timeout.
Kubelet HTTP probes use the Pod IP and cannot reach this loopback-only
listener.
- Shares an `emptyDir` volume mounted at `/workspace` with the worker
container (compose's `copilot_workspace`/`claude_workspace` volumes).
- The worker reaches it at `http://localhost:8080` (same Pod — no
- The worker reaches it at `http://127.0.0.1:8080` (same Pod — no
`Service` object needed).

Set `workers.<name>.mcpGateway.enabled: false` only if your scenarios never
configure MCP servers.
configure MCP servers. If overriding the image, update its `digest` as
well as its `tag` (`digest` takes precedence), and verify that the image
supports the binding flags, `curl` probes, and your MCP transports.

Loopback binding excludes other pods, not containers or benchmark code
inside this worker Pod. It does not resolve the trusted-processor versus
untrusted-executor limitation described below.

## Worker identity isolation

Expand All @@ -104,8 +132,12 @@ need their own mount to receive it.

`scripts/generate-values-from-bicep.sh` picks up the worker identity's
outputs automatically if your Bicep deployment provisioned one; otherwise
those two values stay blank and are only required once you set
`workers.<name>.enabled: true`.
worker identity defaults remain unchanged and a client ID is only required
once you set `workers.<name>.enabled: true`. A provisioned worker identity
must expose its client ID, service-account name, and namespace together.
Its namespace must equal the backend identity's namespace, which the
generator writes as `global.namespace`; missing or incompatible namespace
outputs are errors, not a fallback to `scope`.

**Known limitation**: full isolation needs worker code changes this chart
can't make alone. `coder-acp-copilot`/`coder-acp-claude-code` are a single
Expand Down
9 changes: 7 additions & 2 deletions deploy/helm/scope/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,19 @@ GHCR) wins; otherwise falls back to `global.imageRegistry` (the default
distribution point for the core app services, conventionally
ghcr.io/<owner>/scope). Falls back to `global.imageTag` when `.image.tag`
is unset, and to a bare (unregistered) name when no registry applies at all.
An optional `.image.digest` takes precedence over tags.
*/}}
{{- define "scope.image" -}}
{{- $tag := .image.tag | default .context.Values.global.imageTag -}}
{{- $version := printf ":%s" $tag -}}
{{- if .image.digest -}}
{{- $version = printf "@%s" .image.digest -}}
{{- end -}}
{{- $registry := .image.registry | default .context.Values.global.imageRegistry -}}
{{- if $registry -}}
{{- printf "%s/%s:%s" $registry .image.repository $tag -}}
{{- printf "%s/%s%s" $registry .image.repository $version -}}
{{- else -}}
{{- printf "%s:%s" .image.repository $tag -}}
{{- printf "%s%s" .image.repository $version -}}
{{- end -}}
{{- end -}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,34 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.workers.coderAcpClaudeCode.mcpGateway.enabled }}
# Native sidecar (GA since K8s 1.29): kubelet starts this before the
# main container and holds the Pod at NotReady until its readiness
# probe passes, so the worker's first task never races an MCP-gateway
# that isn't listening yet. Mirrors compose's
# mcp-gateway-claude-code `depends_on: service_healthy`.
# Native sidecar (stable in K8s 1.33, enabled by default since 1.29).
# Its startup probe gates the queue consumer, not just Pod readiness.
# The unauthenticated registry must only listen on pod loopback.
initContainers:
- name: mcp-gateway
restartPolicy: Always
image: {{ include "scope.image" (dict "image" .Values.workers.coderAcpClaudeCode.mcpGateway.image "context" .) }}
imagePullPolicy: {{ .Values.global.imagePullPolicy }}
# Suppress MCPJungle's ASCII-art banner (written to stderr).
command: ["/bin/sh", "-c"]
args: ["/mcpjungle start 2>&1 | grep --line-buffered -v '[█═╗╚║╔╝]' >&2"]
command: ["/mcpjungle"]
args: ["start", "--host", "127.0.0.1", "--port", "8080"]
env:
- name: SESSION_IDLE_TIMEOUT_SEC
value: "0"
volumeMounts:
- name: workspace
mountPath: /workspace
startupProbe:
exec:
command: ["curl", "--fail", "--silent", "--show-error", "--max-time", "2", "http://127.0.0.1:8080/health"]
timeoutSeconds: 3
periodSeconds: 2
failureThreshold: 60
readinessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 10
periodSeconds: 60
exec:
command: ["curl", "--fail", "--silent", "--show-error", "--max-time", "2", "http://127.0.0.1:8080/health"]
timeoutSeconds: 3
periodSeconds: 10
failureThreshold: 3
resources:
{{- toYaml .Values.workers.coderAcpClaudeCode.mcpGateway.resources | nindent 12 }}
{{- end }}
Expand Down Expand Up @@ -100,7 +103,7 @@ spec:
# Same Pod, so the sidecar is reachable over loopback — no
# Service object needed.
- name: MCP_GATEWAY_URL
value: http://localhost:8080
value: http://127.0.0.1:8080
{{- end }}
{{- if .Values.workers.coderAcpClaudeCode.mcpGateway.enabled }}
volumeMounts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,34 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.workers.coderAcpCopilot.mcpGateway.enabled }}
# Native sidecar (GA since K8s 1.29): kubelet starts this before the
# main container and holds the Pod at NotReady until its readiness
# probe passes, so the worker's first task never races an MCP-gateway
# that isn't listening yet. Mirrors compose's
# mcp-gateway-copilot `depends_on: service_healthy`.
# Native sidecar (stable in K8s 1.33, enabled by default since 1.29).
# Its startup probe gates the queue consumer, not just Pod readiness.
# The unauthenticated registry must only listen on pod loopback.
initContainers:
- name: mcp-gateway
restartPolicy: Always
image: {{ include "scope.image" (dict "image" .Values.workers.coderAcpCopilot.mcpGateway.image "context" .) }}
imagePullPolicy: {{ .Values.global.imagePullPolicy }}
# Suppress MCPJungle's ASCII-art banner (written to stderr).
command: ["/bin/sh", "-c"]
args: ["/mcpjungle start 2>&1 | grep --line-buffered -v '[█═╗╚║╔╝]' >&2"]
command: ["/mcpjungle"]
args: ["start", "--host", "127.0.0.1", "--port", "8080"]
env:
- name: SESSION_IDLE_TIMEOUT_SEC
value: "0"
volumeMounts:
- name: workspace
mountPath: /workspace
startupProbe:
exec:
command: ["curl", "--fail", "--silent", "--show-error", "--max-time", "2", "http://127.0.0.1:8080/health"]
timeoutSeconds: 3
periodSeconds: 2
failureThreshold: 60
readinessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 10
periodSeconds: 60
exec:
command: ["curl", "--fail", "--silent", "--show-error", "--max-time", "2", "http://127.0.0.1:8080/health"]
timeoutSeconds: 3
periodSeconds: 10
failureThreshold: 3
resources:
{{- toYaml .Values.workers.coderAcpCopilot.mcpGateway.resources | nindent 12 }}
{{- end }}
Expand Down Expand Up @@ -99,7 +102,7 @@ spec:
# Same Pod, so the sidecar is reachable over loopback — no
# Service object needed.
- name: MCP_GATEWAY_URL
value: http://localhost:8080
value: http://127.0.0.1:8080
{{- end }}
{{- if .Values.workers.coderAcpCopilot.mcpGateway.enabled }}
volumeMounts:
Expand Down
Loading
Loading