Repository navigation
feat(pod): add sidecar containers and volumes to spec.pod - #317
Conversation
Co-authored-by: Eden Reich <[email protected]>
|
@claude CI is failing, can you fix this and make the PR ready for a review? use /ponytail:ponytail /go /go-concurrency |
|
Claude finished @edenreich's task in 3m 26s —— View job CI fix pushed
What was failing
Exactly the size problem the PR body predicts, one step earlier than expected: a client-side The fixServer-side apply everywhere a manifest from this repo is applied - no Go or manifest changes:
One note for the review
Skipped: I could not run |
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]>
## [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))
|
🎉 This PR is included in version 0.32.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
… 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`
Summary
spec.podnow takescontainers,initContainersandvolumesonGateway,AgentandMCP, 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
PodSpecand its singleApplyTocall, so the fields are added once inapi/v1alpha1/pod_types.go:ApplyToappends 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.ValidatePodTemplateNamesrejects a duplicate container, init container or volume name in the built pod template - onlyspec.podcan create one, by reusing a name the operator owns. EachreconcileDeploymentcalls it before writing the Deployment, so the reconcile fails withspec.pod.containers: "inference-gateway" is already used by the operatorinstead of an opaque API-server update error.AgentReconciler.reconcileDeploymentnow returns justerror- its*Deploymentresult was never used, andunparamflagged it once a test called the function.Tests
internal/controller/pod_spec_test.gocovers all three workloads: the three new fields applied to the pod template (including that container[0]is byte-identical to the one built withoutspec.pod), the fields absent whenspec.podis unset, and a container-name and volume-name collision rejected per CRD.task lintandtask testpass (controller coverage 71.6%).Note on manifest size
Embedding
corev1.Container/corev1.Volumeschemas three times grows the CRDs a lot: the Gateway CRD goes from 196 KB to 542 KB andmanifests/install.yamlfrom 505 KB to 1.5 MB. Still under the 1.5 MB per-object etcd limit per CRD, but a client-sidekubectl applystores a second copy inlast-applied-configuration, sokubectl apply --server-sideis the safe way to install from now on. The alternative - a schemaless, unvalidated field - was not worth losing all validation.Downstream
spec.podsidecars and recommend a server-side apply for the bigger manifests.kubernetes-session-teleport-headscaleexample can drop its standalone tailscale proxy pod once an operator release carries this.Closes #316