Skip to content

feat(orchestrator): link a Gateway and park it while suspended - #307

Merged
edenreich merged 3 commits into
mainfrom
feat/issue-305-20261031-1958
Oct 31, 2026
Merged

edenreich merged 3 commits into
mainfrom
feat/issue-305-20261031-1958

Conversation

@inference-gateway-maintainer

Copy link
Copy Markdown
Contributor

Summary

Orchestrator.spec.gateway now takes ref - the name of a Gateway in the same namespace - as an alternative to url (one or the other, enforced by CEL). The link does two things:

  • The operator derives the daemon's INFER_GATEWAY_URL from that Gateway's Service (scheme from spec.server.tls, port from spec.service.port / spec.server.port), so nobody hard-codes the gateway's port. The Orchestrator stored in the cluster keeps its spec - the address is resolved per reconcile.
  • The Gateway's Deployment runs with zero replicas while every Orchestrator referencing it is suspended (spec.sandbox.operatingMode: Suspended), and goes back to spec.replicas as soon as one resumes. The Gateway controller now watches Orchestrators, so the same event that resumes a Sandbox scales the Gateway back up.

A parked Gateway also has no HPA for as long as it is parked, since an HPA would scale the parked Deployment straight back up - reconcileHPA treats parked as disabled and recreates the HPA when the Gateway is unparked. Nothing is deleted: Deployment, Service and Secrets stay. A Gateway that no Orchestrator references is never parked, so its spec.replicas and HPA behave exactly as before. An Orchestrator whose ref names no Gateway reports Ready=False with reason GatewayNotFound.

While there, the Deployment update path stopped recomputing the replica count from the spec and now follows the count the builder put on the desired Deployment, which keeps one rule for parked / HPA / spec.replicas instead of two copies.

Acceptance criteria

  • A Gateway whose Orchestrators are all suspended has no running pod, and its Deployment and Secret stay - replicas 0, nothing deleted.
  • Resuming one of them scales the Gateway back up: the Orchestrator watch enqueues the Gateway on the same spec change that resumes the Sandbox, so the scale-up starts while the daemon's pod is still coming up. The operator does not block the Orchestrator's Ready on the Gateway's readiness - see the risk note below.
  • A Gateway no Orchestrator references keeps its spec.replicas and HPA behavior unchanged (covered by a test).
  • Docs and samples: a new "Link the daemon to a Gateway" section in the README, a pointer from the Sandbox operatingMode bullet, and config/samples/core_v1alpha1_orchestrator_sandbox.yaml switched to ref.

Tests

task test (envtest, 227+ specs) and task lint are green. New specs cover parking across suspended/running/unreferenced Orchestrators, the replica count for parked + HPA combinations, the HPA being removed while parked, the Orchestrator-to-Gateway mapper, and the URL derived from ref (including the missing-Gateway error).

What I skipped

  • No ownerReference-based variant: the explicit ref is the issue's primary shape, and it does not tie the Gateway's lifetime to one session.
  • No new status field on the Gateway saying why it is parked - kubectl get orch already shows which Orchestrators are suspended.
  • Risk: the resume ordering is concurrent, not sequenced. The Gateway scale-up is triggered by the same event as the resume, but the operator does not hold the Orchestrator back from Ready until the Gateway has an available replica, so a daemon that calls the gateway in its first instant could still race a cold gateway pod. Say the word and I will gate the Orchestrator's readiness on the linked Gateway's status.availableReplicas.

Downstream impact

  • inference-gateway/cli: the infer CLI can drop the hard-coded INFER_GATEWAY_URL port and set spec.gateway.ref on the Orchestrators it creates per workspace session - that is what turns the scale-to-zero on.
  • inference-gateway/docs: [DOCS] issue filed for the Orchestrator page.

Closes #305

@edenreich
edenreich merged commit b03c9bd into main Oct 31, 2026
1 check passed
@edenreich
edenreich deleted the feat/issue-305-20261031-1958 branch October 31, 2026 20:38
inference-gateway-releaser Bot added a commit that referenced this pull request Oct 31, 2026
## [0.29.0](v0.28.1...v0.29.0) (2026-10-31)

### ✨ Features

* **orchestrator:** link a Gateway and park it while suspended ([#307](#307)) ([b03c9bd](b03c9bd))

### 🐛 Bug Fixes

* **gateway:** default spec.server and name the service port in status.url ([#306](#306)) ([d7b1792](d7b1792))
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.29.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Oct 31, 2026
edenreich added a commit to inference-gateway/cli that referenced this pull request Oct 31, 2026
…y ref (#1670)

## Summary

A `standard` Kubernetes workspace now links every session Orchestrator
to its Gateway with `spec.gateway.ref` instead of a `spec.gateway.url`
with a hard-coded port. The operator derives the daemon's
`INFER_GATEWAY_URL` from the Gateway's Service, and it runs the Gateway
with no pod while every Orchestrator referencing it is suspended. An
idle workspace now keeps no gateway pod, while its Gateway, Deployment
and credentials Secret stay.

Requires operator v0.29.0 or later (inference-gateway/operator#307).

Closes #1669

## Changes

- `internal/agent/infrastructure/kubernetes/gateway.go`
- `orchestratorGateway` returns `{ref: <workspace gateway>}` in
`standard` mode with `gateway_env`, and `{url: http://127.0.0.1:8080}`
in `all-in-one` mode, unchanged. `gatewayURL`, `gatewayPort` and the
ponytail note about idle gateway cost are gone.
- The Gateway spec no longer sets `server.port`. The operator's default
(8080) applies, and it addresses the Service on that port.
- `internal/agent/infrastructure/kubernetes/workspace.go`
- `reach` waits for the workspace gateway on every reach, not only on
create. A turn or a teleport home that resumes a parked session waits
for the gateway, because the operator scales it up at the same time as
the resume but does not hold the Orchestrator's `Ready` for it.
- `minOperatorVersion` is `v0.29.0`. Strict field validation makes an
older operator refuse `spec.gateway.ref`, and the error now says the
operator may predate that version.
- Docs: `docs/daemon.md` (operator requirement and parking), the
session-teleport README's cloud section, and the example's
`OPERATOR_VERSION`.

## Out of scope

- Orchestrators that rc.9 created with `spec.gateway.url` keep it. The
operator does not count them as referencing the Gateway, so a mix of old
and new sessions on one workspace could park the Gateway under a running
old session. Stop those sessions or delete their Orchestrators by hand.
- `task chat` in the example sets
`INFER_AGENT_MODEL=mock/openai/gpt-4o`, so reattaching a `k8s-cloud`
session with it fails with `model ... not available`. This predates the
change. Set `INFER_AGENT_MODEL` to the workspace's model to chat there.

## Test plan

- [x] `go test -race` for `internal/agent/...`, `internal/sessions/...`
and `cmd/daemon/...`
- [x] `TestReachWaitsForAParkedGateway` fails (nil TLS provider panic
after skipping the wait) with the old `create &&` guard and passes with
the change
- [x] `task precommit:run`
- [x] k3d `infer-workspaces` with operator v0.29.0: teleport to
`k8s-cloud`. The Orchestrator has `spec.gateway: {ref:
infer-gateway-ad2f918bfc2f}`, and the pod's `INFER_GATEWAY_URL` is
`http://infer-gateway-ad2f918bfc2f.infer-workspaces.svc.cluster.local:8080`
with no provider key in its env
- [x] Suspending the session's Orchestrator (the same `operatingMode:
Suspended` change the operator makes once the pod idles out) scales the
gateway Deployment to `0/0` with no pod. The Gateway and its credentials
Secret stay
- [x] Reattaching the session from `infer chat --daemon --session-id`
resumes the Orchestrator, the gateway comes back to `1/1`, and a turn on
`ollama_cloud/glm-5.3-flash` answers from the pod through it
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

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Scale a Gateway to zero while every Orchestrator using it is suspended

1 participant