Skip to content

feat(compute): write clusters and machines down once in compute.yaml - #1762

Merged
edenreich merged 1 commit into
mainfrom
feat/compute-context
Nov 8, 2026
Merged

edenreich merged 1 commit into
mainfrom
feat/compute-context

Conversation

@edenreich

@edenreich edenreich commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Refs #1761

Summary

A cluster exists whether or not a daemon uses it, but it could only be written down inside a daemon's workspace, once per workspace. Twelve agents on one cluster meant twelve copies of its context, namespace and gateway keys, and twelve Gateways, because every standard-mode workspace deployed its own.

~/.infer/compute.yaml now holds the clusters and standalone machines sessions run on, and a workspace names its compute with compute:

# ~/.infer/compute.yaml
clusters:
  - name: k3d-agents
    context: k3d-agents
    namespace: agents
    gateway_env:
      - ANTHROPIC_API_KEY
# ~/.infer/daemon.yaml
workspaces:
  - name: code-reviewer
    compute: k3d-agents
    image: ghcr.io/inference-gateway/cli:latest
  - name: release-manager
    compute: k3d-agents
    image: ghcr.io/inference-gateway/cli:latest

This is the first of two PRs for #1761. The second, stacked on this one, adds the internal/compute context and the infer compute commands.

Changes

  • config/compute.go:
    • ComputeConfig holds clusters (name, kubeconfig, context, namespace, mode, gateway_env) and machines (name, address, token, tls).
    • Validate requires unique names across both, a namespace on every cluster, an address on every machine, and a valid mode.
    • ResolveCompute fills every workspace that names its compute with that compute's kind and connection. A workspace that sets its own kind, repeats a key its compute sets, or names compute that is not defined fails at startup. The gateway_env slice is copied, so workspaces on one cluster never share it.
  • cmd/runtime: compute.yaml is a home-only sidecar, and loadConfig validates it and resolves the workspaces before the full validation. Startup and the in-chat reload both run it on a freshly decoded config.
  • config/daemon.go: WorkspaceEntry gains compute, and the mode check is shared with clusters.
  • internal/agent/infrastructure/kubernetes:
    • A workspace on a cluster calls that cluster's Gateway, so every workspace there shares one Gateway and one credentials Secret. They are labelled inference-gateway.com/compute instead of with one workspace's name.
    • A workspace without compute keeps the Gateway name it always had, so existing Gateways are untouched.
  • infer daemon workspaces gains a COMPUTE column, from a new compute field on the workspace status.
  • Docs: a Compute section in docs/daemon.md, and compute.yaml in the configuration reference and the directory structure.

Verification

  • Table tests cover validation and resolution for a cluster, a machine and a workspace with its own connection, plus every refusal.
  • A hermetic load test reads compute.yaml from home, ignores a project one, and resolves a workspace through loadConfig.
  • A fake-cluster test runs two workspaces on one cluster through ensureGateway and finds one Gateway with both sessions as owners and the cluster label. A workspace named like the cluster but with its own connection keeps its own Gateway.
  • go test ./... passes, the new packages pass under -race, and the pre-commit hook passes.
  • task test:e2e passes on the stacked branch, which contains this commit.

Docs follow-up: inference-gateway/docs#1131.

A cluster exists whether or not a daemon uses it, but it could only be written down inside a daemon's workspace, once per workspace. compute.yaml, read from home only, now holds the clusters and standalone machines sessions run on, and a workspace names its compute with `compute`.

Loading resolves each such workspace with its compute's kind and connection: a cluster's kubeconfig, context, namespace, mode and gateway_env, or a machine's address, token and tls. A workspace that repeats a key its compute sets, sets its own kind, or names compute that is not defined fails at startup. Workspaces that carry their own connection work as before.

Every workspace on one standard-mode cluster now shares that cluster's Gateway and credentials Secret, labelled with the cluster, instead of deploying one each. A workspace without compute keeps the Gateway it always had. infer daemon workspaces shows the compute each workspace runs on.

Refs #1761
@edenreich
edenreich requested a review from a team as a code owner November 8, 2026 16:25
@github-project-automation github-project-automation Bot moved this to Todo in 2026 Nov 8, 2026
@edenreich
edenreich merged commit 6d741ae into main Nov 8, 2026
1 check passed
@edenreich
edenreich deleted the feat/compute-context branch November 8, 2026 16:47
edenreich added a commit that referenced this pull request Nov 8, 2026
…1763)

Closes #1761

Follows #1762, which is merged. This branch is rebased onto `main` with
only its own two commits.

## Summary

Compute gets its own bounded context, and the CLI gets commands for it.

- `internal/compute` holds the GPU model and its rules in `domain/`.
`infrastructure/runpod` translates RunPod's API into that domain, and
`infrastructure/kubernetes` connects to a cluster and checks it.
- `infer compute clusters` and `infer compute machines` add, list, check
and remove what is in `compute.yaml`.
- `infer gpu` becomes `infer compute gpus`, and the old name stays as a
hidden, deprecated alias.

```text
infer compute clusters  add | list | status | remove
infer compute machines  add | list | status | remove
infer compute gpus      provision | list | status | destroy
```

## Changes

- **GPUs**
- `internal/provisioner` moves to
`internal/compute/infrastructure/runpod`. RunPod's JSON stays in private
wire structs, and every method returns domain values: GPU types,
instances and provision requests.
- `internal/compute/domain` has the GPU rules: the hourly price
(community, else secure), the spending cap, and uptime and spend so far.
`infer gpu` repeated the price rule in two places, and both now use the
domain's.
- The RunPod API key is `RUNPOD_API_KEY` in the environment or
`~/.infer/auth.yaml`, and a key asked for on first use is saved there by
the new `config.SetAuthKey`, which keeps the other entries and the file
at `0600`. GPU defaults and `max_hourly` move under `gpus` in
`compute.yaml`.
- The old `provisioner` block and key in `config.yaml`, or
`INFER_PROVISIONER_RUNPOD_API_KEY`, still work with a warning that
points at the new place.
- The commands print through the command instead of `fmt.Printf`, so
tests can capture their output.
- **Clusters and machines**
- `internal/compute/infrastructure/kubernetes` builds a cluster's
clients, checks it runs the operator, reads its Kubernetes version and
reports its status. The agent's Kubernetes workspace now connects and
checks through it, and its errors read word for word as before.
- Each session's Orchestrator is labelled with its cluster, so `infer
compute clusters status` counts the sessions of every workspace on it.
- `add` and `remove` edit `compute.yaml` as written, through a loader
that does not expand `${VAR}`, so a reference is saved back as a
reference and never as the secret. `remove` refuses compute a workspace
in `daemon.yaml` still runs on.
- `status` checks every cluster or machine at once, each with its own
timeout and its own result slot. A machine is probed the way the daemon
probes a daemon-kind workspace. `machines list` never prints a token.
- A cluster name must be a Kubernetes label value, because it labels the
Gateway and the sessions.
- **Wiring**
- The depguard rule for client-go also allows compute's Kubernetes
adapter.
  - `infer --help` lists compute under a Platform group.
  - AGENTS.md lists the compute context and the `computedomain` alias.
- **Docs:** the commands reference, the configuration reference and the
`gpu-provisioning` example move to `infer compute`.

## Verification

- An in-memory test drives `infer compute` through a fresh state and
`SetArgs`. It adds a cluster and a machine, refuses a duplicate name and
a missing namespace, keeps a `${VAR}` token as written and out of
`machines list`, refuses to remove a cluster a workspace uses, and
removes a machine.
- Unit tests cover the domain rules, the RunPod adapter, RunPod key
precedence, GPU settings with the legacy fallback, `SetAuthKey`, cluster
status against a fake cluster with and without the operator, the compute
label on Orchestrators, and concurrent checks keeping their order.
- A smoke run against a throwaway home added, listed and removed
compute, and reported an unreachable cluster and machine as rows.
- `go test ./...` passes, the new packages pass under `-race`, the
pre-commit hook passes, and `task test:e2e` passes.

## Not done here

- `examples/gpu-provisioning/.env.example` still names
`INFER_PROVISIONER_RUNPOD_API_KEY`, which works with a warning. My
permissions do not allow reading files named `.env*`, so renaming it to
`RUNPOD_API_KEY` is left to a follow-up.
- The desktop still writes each workspace's connection itself.
inference-gateway/desktop#474 moves its Compute tab onto `compute.yaml`.

Docs follow-up: inference-gateway/docs#1131.
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.249.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Nov 8, 2026
@edenreich edenreich moved this from Todo to Done in 2026 Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant