Skip to content

feat(pod): add sidecar containers and volumes to spec.pod - #317

Merged
edenreich merged 2 commits into
mainfrom
feat/issue-316-20261101-2010
Nov 1, 2026
Merged

edenreich merged 2 commits into
mainfrom
feat/issue-316-20261101-2010

Conversation

@inference-gateway-maintainer

@inference-gateway-maintainer inference-gateway-maintainer Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

spec.pod now takes containers, initContainers and volumes on Gateway, Agent and MCP, so a sidecar that has no injector (a Tailscale node against a Headscale control plane, any VPN or proxy) can live in the pod the operator creates.

All three CRDs already share PodSpec and its single ApplyTo call, so the fields are added once in api/v1alpha1/pod_types.go:

  • ApplyTo appends the user's containers after the operator's own container, its init containers before it, and its volumes to the pod - the operator's container stays first and untouched, and its volumes keep their names.
  • ValidatePodTemplateNames rejects a duplicate container, init container or volume name in the built pod template - only spec.pod can create one, by reusing a name the operator owns. Each reconcileDeployment calls it before writing the Deployment, so the reconcile fails with spec.pod.containers: "inference-gateway" is already used by the operator instead of an opaque API-server update error.
  • Rolling and removal come for free: all three controllers replace the whole pod template when it differs from the live one.

AgentReconciler.reconcileDeployment now returns just error - its *Deployment result was never used, and unparam flagged it once a test called the function.

Tests

internal/controller/pod_spec_test.go covers all three workloads: the three new fields applied to the pod template (including that container [0] is byte-identical to the one built without spec.pod), the fields absent when spec.pod is unset, and a container-name and volume-name collision rejected per CRD.

task lint and task test pass (controller coverage 71.6%).

Note on manifest size

Embedding corev1.Container/corev1.Volume schemas three times grows the CRDs a lot: the Gateway CRD goes from 196 KB to 542 KB and manifests/install.yaml from 505 KB to 1.5 MB. Still under the 1.5 MB per-object etcd limit per CRD, but a client-side kubectl apply stores a second copy in last-applied-configuration, so kubectl apply --server-side is the safe way to install from now on. The alternative - a schemaless, unvalidated field - was not worth losing all validation.

Downstream

Closes #316

@edenreich

Copy link
Copy Markdown
Contributor

@claude CI is failing, can you fix this and make the PR ready for a review? use /ponytail:ponytail /go /go-concurrency

@inference-gateway-maintainer

inference-gateway-maintainer Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Claude finished @edenreich's task in 3m 26s —— View job


CI fix pushed

  • Check CI status - only E2E Tests failed (CI, Tests green)
  • Read the job log
  • Fix the root cause
  • Verify Taskfile parses, confirm prettier failures on the touched files are pre-existing on main
  • Commit (2732067)

What was failing

task deploy in BeforeSuite:

The CustomResourceDefinition "gateways.core.inference-gateway.com" is invalid: metadata.annotations: Too long: may not be more than 262144 bytes

Exactly the size problem the PR body predicts, one step earlier than expected: a client-side kubectl apply writes the whole object into kubectl.kubernetes.io/last-applied-configuration, and with the embedded corev1.Container/corev1.Volume schemas the Gateway CRD (542 KB) no longer fits in the 256 KB annotation limit. Nothing wrong with the Go code - the CRD itself is valid and well under the etcd per-object limit.

The fix

Server-side apply everywhere a manifest from this repo is applied - no Go or manifest changes:

  • Taskfile.yaml: install and deploy use kubectl apply --server-side --force-conflicts -f - (the force flag takes ownership from an earlier client-side install, which is what the e2e cluster and existing users have). manifests-for-namespace prints the server-side command.
  • README.md: every install.yaml/crds.yaml/manifests/... apply gets --server-side, ServerSideApply=true is added to both ArgoCD examples, and a note under 📦 Installation says why and when to add --force-conflicts.
  • .releaserc.yaml: the same for the generated release-notes install snippets, so released instructions aren't broken on day one.

undeploy/uninstall are kubectl delete and need no change. Upgrade path for existing users: --force-conflicts once, after which the stale annotation is irrelevant.

One note for the review

ValidatePodTemplateNames reports every duplicate as "x" is already used by the operator, which is also what a user sees if they pass two sidecars with the same name among themselves. Accurate in the case that matters, slightly off in that one - left alone because the message is quoted in the README and tests, flagging it rather than widening this commit.

Skipped: I could not run task test:e2e here (no k3d cluster, no docker build in this runner), so the server-side apply is verified by reading, not by a green suite - the re-run will confirm it. task lint/task test were already green and I touched no Go. Risk: server-side apply also stores a field-set copy in managedFields, so if a future CRD grows several times again the per-object etcd limit, not the annotation, becomes the next wall.
| Branch

The embedded container/volume schemas push each CRD past the 262144-byte
last-applied-configuration annotation limit, so a client-side apply fails
with "metadata.annotations: Too long". task install/deploy and every
documented install path now use kubectl apply --server-side.

Co-authored-by: Eden Reich <[email protected]>
@edenreich
edenreich merged commit 5f2f658 into main Nov 1, 2026
1 check passed
@edenreich
edenreich deleted the feat/issue-316-20261101-2010 branch November 1, 2026 21:07
inference-gateway-releaser Bot added a commit that referenced this pull request Nov 1, 2026
## [0.32.0](v0.31.0...v0.32.0) (2026-11-01)

### ✨ Features

* **pod:** add sidecar containers and volumes to spec.pod ([#317](#317)) ([5f2f658](5f2f658))
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.32.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 Nov 1, 2026
edenreich added a commit to inference-gateway/cli that referenced this pull request Nov 1, 2026
… over a self-hosted Headscale tailnet (#1674)

## Summary

Adds `examples/kubernetes-session-teleport-headscale`, the Headscale
twin of `examples/kubernetes-session-teleport-netbird`. It runs the same
chain and the same checks on a self-hosted
[Headscale](https://github.com/juanfont/headscale) tailnet:

```text
infer-local ──mTLS :52789──▶ infer-k8s ──mTLS :8443──▶ gateway (tokenless, or the Inference Gateway via task gateway:real)
```

- **Tailnet.** Headscale v0.29.7 in the cluster, serving HTTPS from the
cert-manager demo CA, with its embedded DERP relay and STUN as the only
relays (`derp.urls: []`), so nothing leaves the cluster. MagicDNS names
live under `tailnet.internal`.
- **Nodes.** Each node joins with a tagged, ephemeral, reusable pre-auth
key. `infer-k8s`, the gateway and the attacker run a
`tailscale/tailscale` v1.104.4 sidecar in kernel mode, and `infer-local`
runs one beside the cluster in compose. The sidecar rewrites the pod's
shared `resolv.conf`, and `override_local_dns: false` keeps cluster
names resolving.
- **Policy.** `headscale/policy.hujson` holds two ACLs, `tag:infer-local
→ tag:infer-k8s:52789` and `tag:infer-k8s → tag:gateway:8443`. The
attacker's tag gets none.
- **Gateway node.** tokenless carries the sidecar in its Deployment, and
the operator's `Gateway` carries it through `spec.pod.containers` and
`spec.pod.volumes` (operator v0.32.0, inference-gateway/operator#317).
The NetworkPolicy `gateway-wireguard-only` admits only WireGuard to the
gateway's pods, so port 8443 is reachable over the tailnet alone. `task
gateway:real` removes the earlier gateway and its offline node before it
creates the `Gateway`, so the new pod gets the name `gateway`. The
operator installs with `kubectl apply --server-side`, because the
v0.32.0 CRDs are too large for a client-side apply. `gateway:real` and
`local:up` return only once infer-local reaches `infer-k8s:52789`.
- **TLS.** The daemons terminate TLS themselves (`binding.tls.mode:
files`, ECDSA P-256), which keeps mutual TLS and `forward_env`.
Headscale v0.29 cannot provision `tailscale serve` certificates
(juanfont/headscale#3554 is on its main branch only). The README covers
`tailscale serve` as the Tailscale-only option without `forward_env`.
- **Tailscale.** `task up TAILNET=tailscale` runs the same chain on your
own Tailscale account, with your machine as infer-local on its Tailscale
app. The choice is recorded in `.state/`, so later tasks need no flag.
What changes:
- Each cluster node gets its own auth key, minted through the Tailscale
API from an OAuth client: tagged, ephemeral, reusable and pre-approved.
The client carries only `tag:infer-demo`, which owns the node tags,
because a client holding several tags is refused a key with just one of
them.
- Names become `<node>.<tailnet>.ts.net`, read from the Tailscale app.
The manifests are rendered with `sed`, and the Headscale default is the
identity.
- infer-local is `infer` built from this checkout, with `HOME` under
`.state/` and its binding on loopback 52790, so your own `~/.infer` and
daemon stay untouched. `local:up` starts its daemon and waits until
infer-k8s is reachable.
- `gateway:real` and `cleanup` remove the demo's old nodes through the
API, and `cleanup` revokes the keys. They only touch ephemeral devices
named `infer-k8s`, `gateway` or `attacker` that carry nothing but the
demo's tags.
- The tasks never write your policy file. `task tailscale:policy` prints
`tailscale/policy.hujson` with your login filled in.
- **x509 on the local hop too.** infer-local's own binding serves
`binding.tls.mode: ca`, so its CLI commands authenticate with a client
certificate from the daemon's CA. Loopback alone would let any local
process or web page drive the daemon.
- **Shared changes.** The canary is now a UDP datagram from a throwaway
container beside the cluster, since Tailscale mode has no Headscale
metrics port. `attack` reads tailnet addresses from each pod's own
sidecar. The tokenless reply says "reached over the tailnet".

The docs changes:

- `docs/examples.md` lists the example.
- `docs/daemon.md` "Daemons on other machines" links it, and mentions
the Tailscale mode.

Closes #1665
Closes #1675

## Test plan

- [x] Headscale, from scratch: `task up workspaces sniff:start demo
secret:check sniff:report attack tailnet:status teleport:back cleanup`
- tokenless answered over both mTLS hops, and `DEMO_SECRET` hashes match
with the value in no pod spec.
- The capture holds only WireGuard (495 packets on UDP 41641): 0 on
52789 and 8443, no secret and no reply, but the canary is there.
- The attacker gets NXDOMAIN for both names, a timeout on the tailnet
addresses, a refused connection on the pod addresses, and no peers.
- Both hops fail with `certificate required` without the client
certificate, and infer-local cannot resolve the gateway.
- `infer-k8s` reaches both neighbours `direct`, the gateway at its own
pod address, and the teleport back works.
- [x] Tailscale, from scratch on a free-plan tailnet: `task up
TAILNET=tailscale workspaces sniff:start demo secret:check sniff:report
attack tailnet:status teleport:back cleanup`
- Three auth keys minted through the API, and `infer-k8s`, `gateway` and
`attacker` online in the tailnet with their tags.
- The Mac's daemon reaches `infer-k8s.<tailnet>.ts.net` directly, the
turn goes through the gateway, and the `DEMO_SECRET` hashes match.
- The capture holds 642 WireGuard packets, 0 on 52789 and 8443, no
secret, no reply.
- The attacker gets the same results as with Headscale. That tailnet's
own grant lets the Mac reach the gateway, and mTLS refuses it.
- `cleanup` leaves no demo node in the tailnet, no cluster, no
containers, no daemon and no `.state/`.
- [x] `task gateway:real PROVIDER=ollama_cloud
MODEL=ollama_cloud/glm-5.3-flash` on Headscale (twice) and on Tailscale
- The `Gateway` pod joins as `gateway` through its `spec.pod.containers`
sidecar, also after the earlier one is deleted.
  - `task demo` gets a real answer each time.
- The provider key, the OAuth client secret and any `tskey-` appear 0
times in the task output.
- [x] `task precommit:run`
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] Sidecar containers and volumes in spec.pod for Gateway, Agent and MCP workloads

1 participant