Repository navigation
Give long-named pods a hostname that fits a DNS label - #85
josephschorr wants to merge 14 commits into
Conversation
A pod may be named with up to 253 bytes, but a hostname is one DNS label of at most 63. With spec.hostname unset the kubelet derives the hostname from the pod name and truncates it, so a long-named pod boots with a hostname that is not its own name. Pod names are composed from the session name plus a per-pod suffix, and a delegated child's session name embeds its parent's, so a child's sidecar pod crosses 63 bytes with ordinary names. A workload that builds an identity from its hostname then produces one that other systems refuse, and the sidecar fails only when it runs under a delegation. Set an explicit hostname on the runner, sidecar, sandbox and detector pods when the pod name is over the limit. Names that fit leave the hostname unset, so those pods are built exactly as before; longer ones keep their readable prefix plus a hash of the full name, so distinct pods stay distinct and a restarted pod keeps the same hostname. Co-Authored-By: Claude <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
samkim
left a comment
There was a problem hiding this comment.
This PR sets spec.hostname to a bounded, hash-suffixed DNS label when a pod name is longer than 63 bytes, for the runner, sidecar, sandbox and detector pod builders. Names that fit are untouched. The helper itself is sound: valid label, deterministic, collision-resistant, and I found no caller that breaks. go test on the two touched packages passes.
Verdict: ready after the inline fixes (one decision needed on the sandbox pre-warm behavior).
Issues:
- Important: long-named sandbox sessions can no longer adopt a pre-warmed pool sandbox.
podspec.Buildnow sets a Hostname thatBuildClassSpeclacks, so the DeepEqual eligibility check intryAdoptfails and the session cold-starts. See inline onpkg/platform/podspec/builder.go. - Nit:
cosidecar.BuildPodspells the pod name twice. See inline.
Questions for the author:
- For the pre-warm regression: should long-named sessions stay eligible for adoption (exempt Hostname from the
tryAdoptcomparison, since an adopted pod keeps the pool pod's own short name), or is a cold start acceptable here? Either is valid; it is your call. - Is leaving short dotted pod names (for example
team.demo-agent-runner) to the kubelet deliberate? That behavior predates this PR, but the doc comment's rationale ("a hostname is not a subdomain") would apply to them too. - What does the downstream system prefix onto the hostname, and is 63 the right ceiling for it? Nothing in the repo ties 63 to that consumer, so the motivating case is untested.
- The PR says the full unit, integration and e2e suites were not run. The ship gate requires all three before merge; please run them and report the result.
- Are the probe pods (
sidecartoolbox/probe.go,workshopprobe/podbuild.go) deliberately excluded? Their names derive from the CR name, not a session name, so I believe so.
This review was drafted by an automated pipeline and its findings were checked against the code before submission.
A session whose pod name passes 63 bytes is now rendered with an explicit hostname, which a pool sandbox, built from the class spec alone, never has. The adoption check compared the two specs whole, so every such session, a delegated child above all, cold-started even with a warm pool for its class. The hostname is derived from the session's own pod name, and an adopted sandbox never takes that name: its pod keeps the name the pool generated, which the API server bounds to 63 bytes. podspec now names the fields that identify one pod rather than describe its shape (applyPodIdentity) and offers WithoutPodIdentity to strip them, and the adoption check compares the session's spec without them. Everything else a session adds to its class still forces a cold start.
samkim
left a comment
There was a problem hiding this comment.
Round 2 review
Checked commits 0001454 and 7caa39b (since 706790b) against the two round-1 threads. Earlier issues verified: 2 of 2 (one comes with a follow-up problem, below).
Verdict: ready after the inline fix. One design decision is needed.
Still open
- Important: a long-named session that gets a warm-pool claim while the pool has no ready sandbox is cold-started by the upstream claim controller under the name
<session>-pod, with no hostname, so it gets the truncated hostname this PR is meant to prevent. The 7caa39b fix for adoption rests on "an adopted sandbox never takes that name", which only holds when the pool has a sandbox to hand over. See inline on prewarm.go:311. The round-1 review suggested this approach on the same premise, so the gap is ours as much as the PR's. On main these sessions also adopted with no hostname, so this is not a regression against main. It is a path the PR does not yet fix.
Questions for the author
- For the empty-pool case above, do you prefer (a) long-named sessions skip adoption and cold-start directly (the direct path already sets the bounded hostname), or (b) keep adopting but give the SandboxClaim a DNS-label-sized name (this changes the name that Ensure, Teardown and Status look up)? Option (a) gives up warm starts for long names; option (b) touches the lookup-order invariant at runtime.go:115-119.
- Is leaving short pod names that contain dots to the kubelet deliberate? (Unanswered from round 1.)
- What does the downstream system prefix onto the hostname, and is 63 the right ceiling? (Unanswered.)
- Will the full
mage test:unit,test:integrationandtest:e2eruns be completed before merge, per the repo's ship gate? The PR body still says they were not run. (Unanswered.) - Are the probe pods (
pkg/controllers/sidecartoolbox/probe.go,pkg/controllers/workshopprobe/podbuild.go) deliberately left out? (Unanswered.)
This review was drafted by an automated pipeline and checked before submission.
The two probe pod builders were left out of the hostname change on the assumption that a name derived from a CR could not reach the limit. Both can. A WorkshopProbe's pod is "<name>-probe", past 63 bytes from a 58-byte name, and a SidecarToolbox's is "probe-<name>-<timestamp>", past it from a 42-byte name; each CR's name is also a label value on its pod, so 63 bytes is the most either can carry, which puts the pods at up to 69 and 85. A probe boots the same image a session later runs as a sidecar, so it is the same truncated hostname. Both builders now set podspec.HostnameFor of the pod's own name, which is empty for a name that fits.
… holds Leaving the hostname out of the adoption check kept a long-named session eligible for a pre-warmed sandbox, on the premise that an adopted sandbox keeps its pool-generated name. That holds only when the pool has a sandbox to hand over. When it has none, the agent-sandbox claim controller cold-starts one itself: the Sandbox is named after the claim, its pod after the Sandbox, and it is built from the pool's class-only template. A claim can add labels, annotations and env but no pod spec field, so that pod is named "<session>-pod" with no hostname and the kubelet truncates it. A session now claims only when the claim's name is itself a usable hostname. One whose pod name passes 63 bytes takes the direct Sandbox, which carries the bounded hostname, and gives up a warm start. Whether the pool has a sandbox ready cannot be read before the claim is written without racing other claims, so the rule depends on the name alone and answers the same for an empty pool and a full one. Sessions whose pod name fits claim exactly as before. WithoutPodIdentity and applyPodIdentity existed only for the comparison this replaces and are removed. The sandbox conformance suite gains a backend-neutral rule, that a session's pod boots under a hostname that fits a DNS label, for a short name, a long name, and a long name whose class has a pre-warmed pool with nothing ready. Both Kubernetes backends are held to it.
|
Answers to the open review-body questions, from what the code shows:
|
…them A session's name does not stay on the session. It is stamped as a label value, 63 bytes at most, on the runner and sidecar pods, the workspace claims, the network policies that select those pods, the bundle sessions and the delegated children, and several readers take that value back as the session's name. It is also one token of the session's message subjects and part of its authorization object id, neither of which admits a dot. The API server allows 253 bytes and dots, so such a session was accepted and then never ran: its pods were refused on every reconcile. The AgentSession CRD now refuses a name over 63 bytes or containing a dot at creation, with a message that states the rule. The platform's own composers are bounded so they are never the ones refused: - A delegation's SubagentRequest is named from its parent, and the child session and its inbox channel from the request. The parent's name is now included whole only while that chain still fits, and otherwise as a readable prefix plus a hash. A parent of 45 bytes or more used to have its child refused at creation. - Restart, continuation and takeover children carried up to 244 bytes of their parent, sized for an object name. Each generation adds 9 bytes, so a channel-minted name was past 63 by its second restart. They now carry 54, shortened with a hash of the whole parent instead of a plain cut, which two parents sharing a prefix could collide on. - A session minted for a channel whose name has dots gets dashes instead. Names that fit are computed exactly as before. A child whose name no longer spells its parent out is still tied to it by spec.parent or spec.forkedFrom, which carry the parent's full name. The shortening lives in one new leaf package, pkg/x/boundedname.
… to its pod Bounding a pod's hostname left two things open. Other values derived from a name had the same 63-byte limit and no bound: - A sandbox pod was labelled with its session's name. A bundle's session is named "<agent session>-<bundle>", up to 96 bytes, so the API server refused the pod and the sandbox never started. The label now carries the name when it fits and its shortened form otherwise, and the sandbox NetworkPolicy selects on the same derivation. The class label is bounded the same way. - A cascaded SessionHold was labelled with the originating hold's name, which embeds a session name and passes the limit for a session of about 38 bytes. The cascade was refused and the descendants of a held session kept running. - The workspace overlay Job's name passed the 63 bytes a Job allows for a session of 43 bytes or more, and was refused on every reconcile. - Both probe pods were labelled with their resource's name. And a shortened hostname is a prefix plus a hash, so the pod could no longer be read off it. Every builder now sets the hostname through podspec.ApplyHostname, which also stamps the hostname as a label (agentprimitives.authzed.com/hostname), so the pod can be selected by the hostname a log line shows, and the full pod name as an annotation (agentprimitives.authzed.com/hostname-source). Both are set only when a hostname is, so a pod that never needed one is built exactly as before. On the agent-sandbox backend they ride the Sandbox's pod template onto the pod. podspec.HostnameFor now shortens through pkg/x/boundedname, with identical output. The sandbox conformance rule widens from the hostname to the pod: at the longest session name there is, every label is one the API server accepts, the hostname fits, and selecting on the hostname label finds exactly that pod.
|
Correction to my earlier comment on probe pods: the maximum pod-name lengths I gave (69 and 85 bytes) assumed the probe CR name was capped at 63 by its pod label. As of 6f42bb0 those labels are bounded, so a longer CR name is accepted and the pod name can be longer than that; the probe pods' hostnames are bounded either way. This push also widens the PR beyond hostnames: a session name longer than 63 characters or containing a dot is now refused at creation, and names the platform composes itself (delegated children, restarts and continuations, channel-started sessions) are kept within the limit. The description has the details. |
samkim
left a comment
There was a problem hiding this comment.
Round 3 re-review (changes since 7caa39b2: four commits, a7a9f9c8 through 6f42bb05).
The PR started as a hostname fix for long pod names. Since round 2 it has widened well beyond hostnames: it now adds a CRD admission rule on AgentSession names (63 bytes, no dots), bounds the names it composes for delegated children, restarts and continuations, bounds label values on holds, probes and network policies, and adds a shared pkg/x/boundedname helper. That is a larger surface than the title says, and it changes a CRD, so the repo's full ship gate matters more than it did in round 2.
Earlier issues: 3 of 3 earlier threads verified. The one open thread (warm-pool claim with an empty pool booting a truncated hostname) is fixed: long-named sessions no longer claim from the pool at all and take the direct Sandbox that carries the bounded hostname. The tests cover both an empty and a ready pool. The cost is that those sessions get no warm start.
Verdict: ready after the inline fix for the first issue below. The nits can ride along or follow.
Issues, highest impact first:
- Important: the new AgentSession name rules run on every update, not only on create. A session created before the upgrade with a name over 63 bytes or containing a dot (both were admitted before) will, after the new CRD is applied, fail every status write, label write and finalizer removal. Deleting it leaves it stuck in Terminating. I reproduced this against a real API server with the repo's CRDs, and also confirmed that making the rules create-only keeps new bad names refused while letting old objects be updated and deleted. See inline on
agentsession_types.go. - Nit: the new doc on
AgentSessionNameMaxLengthsays every place the platform composes a session name stays within the limit, butbrowsersession.NewSessionName,oap chatandoap agent rundo not. See inline. - Nit: skipping warm-pool adoption for long names is silent, and it covers most bundle sandboxes (a 10-byte bundle name on a channel-minted session is enough). See inline.
- Nit:
OverlayCutJobNamestill uses the older hand-rolled Job-name bounding rather thanboundedname. See inline.
Not anchored to the delta (comments only, unchanged lines): pkg/controllers/sessionhold/cascade.go:113 still says the cascade label equals originating.Name, and pkg/controllers/sidecartoolbox/probe.go:501 says the label value is the CR name. Both are now boundedname.LabelValue(name), so a reader following the comment would write a selector that stops matching past 63 bytes.
Questions for the author (still open):
- Is 63 the right ceiling for whatever downstream consumer prefixes the hostname in the original delegated-child failure? The repo does not show that consumer, so this is untested.
- Will
mage test:unit,test:integrationandtest:e2ebe run in full before merge? Only touched packages and the sandbox conformance suites were run locally, and the PR now changes a CRD andinstall.yaml.
Answered since round 2: option (a) for warm-pool claims, short dotted pod names left to the kubelet on purpose, probe pods now covered.
This review was drafted by an automated pipeline and checked against the code before submission.
| // +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase" | ||
| // +kubebuilder:printcolumn:name="Turns",type="integer",JSONPath=".status.progress.turnCount" | ||
| // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" | ||
| // +kubebuilder:validation:XValidation:rule="self.metadata.name.size() <= 63",message="metadata.name must be at most 63 characters: a session's name is stamped as a label on its pods, claims and network policies, and a label value cannot be longer" |
There was a problem hiding this comment.
[important] The name rules run on every UPDATE, so pre-existing long or dotted AgentSessions cannot be cleaned up after upgrade
Problem: both XValidation rules (lines 16-17) sit on the object root with no oldSelf guard, so the API server evaluates them on every update, including status and finalizer writes. An AgentSession admitted before this PR with a name over 63 bytes (old maxParentLen 244) or containing a dot (old makeSessionName kept dots) has the finalizer FinalizerAgentSession stamped by the controller (pkg/controllers/agentsession/controller.go:1308). After oap install applies the new CRD, every status write, label write and the finalizer removal at controller.go:3502 is rejected with the name-rule message, so Delete leaves the object in Terminating forever. Reproduced against a real kube-apiserver with this repo's CRDs: with the current rules, status update, label update and finalizer removal on a 70-byte-named session all fail. With the rules rewritten as oldSelf.hasValue() || (<rule>) and optionalOldSelf: true, a new 64+ byte create is still refused and the update, finalizer removal and delete all succeed.
Fix: make both rules create-only. Change the markers to +kubebuilder:validation:XValidation:rule="oldSelf.hasValue() || self.metadata.name.size() <= 63",optionalOldSelf=true,message=... and ...rule="oldSelf.hasValue() || !self.metadata.name.contains('.')",optionalOldSelf=true,message=... (keep the existing messages; optionalOldSelf is supported by controller-tools v0.20.1). Then run mage gen:api && mage manifests so config/crds/agentprimitives.authzed.com_agentsessions.yaml and pkg/platform/manifests/install.yaml are regenerated. Do not hand-edit those files.
Test: extend TestAgentSessionNameCEL in pkg/apis/v1alpha1/agentsession_validation_test.go. Add a case that creates a long-named session (with a finalizer) while the rules are absent from the installed CRD (patch the rules out, create, restore them), then asserts a status update, a label update and a finalizer-removal update succeed, and that creating a fresh 64-byte or dotted name is still refused. Run go test ./pkg/apis/v1alpha1/ -run TestAgentSessionNameCEL and go test ./pkg/platform/manifests/.
Constraints: CLAUDE.md "Manifest regeneration": run mage gen:api then mage manifests; never edit install.yaml by hand.
There was a problem hiding this comment.
Both name rules are create-only as of dd19e9d: oldSelf.hasValue() || <rule> with optionalOldSelf=true, CRD and install bundle regenerated. TestAgentSessionNameCEL now takes a session that predates the rules (one long-named, one dotted, each with the finalizer) through a status update, a label update and the finalizer coming off, and still refuses a new 64-byte or dotted name. optionalOldSelf needs Kubernetes 1.30+, which is what envtest is pinned to and what the bundled ValidatingAdmissionPolicy already requires.
There was a problem hiding this comment.
Verified at b9a72bc5: both rules are oldSelf.hasValue() || <rule> with optionalOldSelf=true (agentsession_types.go:16-17), CRD and install bundle regenerated. TestAgentSessionNameCEL ("a session that predates the rules") ran against envtest and passes: status update, label update and finalizer removal succeed, while new 64-byte, dotted and re-created long names are still refused.
| // ran: its pods were refused one reconcile after another. | ||
| // | ||
| // The CRD refuses such a name at admission instead (the XValidation rules on | ||
| // AgentSession), and every place the platform composes a session name itself |
There was a problem hiding this comment.
[nit] Doc says every place the platform composes a session name stays within the limit; three composers do not
Problem: lines 19-22 claim every platform-composed session name keeps within the limit. browsersession.NewSessionName (pkg/web/browsersession/browsersession.go:364), oap chat (cmd/oap/internal/chatcmd/chat.go:215) and oap agent run (cmd/oap/internal/agentcmd/run.go:92) all build <agentClass>-<8hex> with no bound and keep dots in the class name. A class name of 55+ bytes or with a dot produces a session the new CRD rule refuses at create. These sessions could not run before this PR either (label value, SpiceDB id), so this is a doc-accuracy and fail-early issue, not a regression.
Fix: preferred, route those three through one helper in pkg/apis/v1alpha1 that uses boundedname.Shorten(class, 63-9) plus -<8hex> (dots become dashes), and call it from all three. Minimum, narrow the comment to name only the composers that are bounded (SubagentRequestGenerateName, the channelsd fork/continuation/takeover names, the channel-minted roots).
Test: if you add the helper, add a case in pkg/apis/v1alpha1/agentsession_name_test.go with a 100-byte dotted class name asserting the result is at most 63 bytes, has no dot, and is deterministic in its prefix. Run go test ./pkg/apis/v1alpha1/ ./pkg/web/browsersession/.
There was a problem hiding this comment.
All three now go through one helper, v1alpha1.NewClassSessionName (11fc30b), and the comment lists it. It keeps 49 bytes of the class name rather than 54, because oap chat and the browser stamp <session>-chan back on the session as a label, and it turns the dots of a class name that fits into dashes too. The test covers a 100-byte dotted class: at most 63 bytes, no dot, deterministic prefix.
There was a problem hiding this comment.
Verified at b9a72bc5: NewClassSessionName (agentsession_name.go:68) is used by oap chat, oap agent run and the browser session composer, and TestNewClassSessionName covers 49/50/100-dotted/253-byte classes. Keeping 49 bytes for the -chan label is the right call.
| // hostname is not in the class spec), but only as a side effect of how the | ||
| // hostname happens to be carried. This states the rule on the name it is | ||
| // actually about. | ||
| if podspec.HostnameFor(claimName) != "" { |
There was a problem hiding this comment.
[nit] Skipping warm-pool adoption for long names is silent
Problem: when podspec.HostnameFor(claimName) != "", tryAdopt returns false, nil with no log or condition. A bundle's pod is <agent session>-<bundle>-pod, and a channel-minted agent session is already up to 49 bytes, so a bundle name of about 10 bytes pushes it past 63 and the session never warm-starts. An operator who provisioned a SandboxWarmPool has no way to see why those sessions cold-start.
Fix: before returning false here, log at INFO via r.deps.Logger (already used at prewarm.go:508) with session name, class, pod name length and the reason "hostname needs bounding, skipping warm pool". Keep the return value as is.
Test: in TestEnsure_SessionClaimsOnlyUnderANameThatFitsAHostname (pkg/tools/sandboxkinds/agentsandbox/runtime_test.go:647), capture the logger (a logr/testr or funcr sink) and assert the skip message is emitted for the 64-byte case and not for the 63-byte case. Run go test ./pkg/tools/sandboxkinds/agentsandbox/.
Constraints: CLAUDE.md "Never silently drop errors": a decision that changes what an operator sees should leave at least an INFO log.
There was a problem hiding this comment.
The skip is logged at INFO as of 57ccc1b, with the session, class, pod name and its length. The test asserts the line appears once for the 64-byte name and not at all for the 63-byte one.
There was a problem hiding this comment.
Verified at b9a72bc5: the skip is logged at INFO with session, class, pod name and length (prewarm.go:313-318), and TestEnsure_SessionClaimsOnlyUnderANameThatFitsAHostname asserts it for the 64-byte name and not for the fitting ones.
One small follow-up (nit, can ride along): the log fires before the SandboxWarmPool lookup (prewarm.go:346-355), so with the prewarm CRDs installed, a long-named session of a class that has no pool logs "not claiming a pre-warmed sandbox", which points an operator at a pool that does not exist.
Fix: do the pool Get (it does not depend on classSpec) before the hostname gate and return early on IsNotFound, so the gate only logs when a pool exists. Do not move the gate after the equality.Semantic.DeepEqual(p.Spec, classSpec) check: Build's hostname makes that check reject long names first, so the log would never fire.
Test: in TestEnsure_SessionClaimsOnlyUnderANameThatFitsAHostname (runtime_test.go) add a case with a 64-byte name and no SandboxWarmPool, asserting no skip line is logged. Run go test ./pkg/tools/sandboxkinds/agentsandbox/.
| // so the bare concatenation passes the 63 bytes a Job name may have for a | ||
| // session named with 43 or more, and the API server then refuses the Job on | ||
| // every reconcile with nothing reported on the session. | ||
| func OverlayCutJobName(dst PVCRef) string { return boundedJobName("ws-overlay-" + dst.Name) } |
There was a problem hiding this comment.
[nit] A second 63-byte name bounder now coexists with boundedname
Problem: OverlayCutJobName calls boundedJobName (pkg/platform/workspace/cpbypod.go:165), a hand-rolled sha256 truncate, while this PR adds pkg/x/boundedname.Shorten and a pkg/x/README.md:20 entry saying to use it instead of cutting a name by hand. Two implementations of the same rule will drift.
Fix: have boundedJobName delegate to boundedname.Shorten(name, validation.LabelValueMaxLength) and drop the local hashing and jobNameHashHexLen. First check that it does not rename Jobs that already exist: Shorten also turns dots into dashes and collapses dash runs, which the old helper did not. If any existing snapshot or overlay Job name could differ, keep the old helper and note why in its doc instead.
Test: in pkg/platform/workspace/overlay_test.go and the snapshot Job name test, assert the name for a 70-byte input is unchanged from the current output (pin the literal) and still at most 63 bytes. Run go test ./pkg/platform/workspace/ ./pkg/x/boundedname/.
Constraints: CLAUDE.md "Prefer a library over a hand-rolled utility"; do not rewrite if it renames existing objects.
There was a problem hiding this comment.
Split in 8fbc242: OverlayCutJobName now calls boundedname.Shorten, since an overlay Job over 63 bytes was never creatable before this PR and there is no existing name to keep. boundedJobName stays for the snapshot, restore and GC Jobs, which already ship: the two schemes differ when the kept prefix holds a -- run (a fork qualifier is the child session name), and those Jobs are found again by recomputing the name. Both are pinned with literals, including a 70-byte overlay input and the one case where the schemes part.
There was a problem hiding this comment.
Verified at b9a72bc5 (fixed differently): OverlayCutJobName uses boundedname.Shorten (overlay.go:33), which returns any name of 63 bytes or less unchanged, so no existing overlay Job is renamed. Keeping boundedJobName for the already-shipped snapshot, restore and GC Jobs is reasonable given the -- divergence, and TestBoundedJobName pins both schemes with literals.
oap chat, oap agent run and the browser each named a new session <class>-<8 hex> with nothing holding the class part to a length, so a class named with more than 54 bytes, or with a dot, produced a name the session CRD now refuses. All three go through one helper that keeps the class name whole while it fits and otherwise as a readable prefix plus a hash, and that leaves room for the -chan Channel name stamped back on the session as a label.
Both rules ran on every write, so a session admitted before they existed under a long or dotted name could no longer have its status or labels updated, or its finalizer removed, and would sit terminating forever once deleted. Each rule is now skipped when the object already exists, so such a session can finish and be cleaned up while a new one is still refused.
The skip turns on the session's name alone, so nothing about the class or its pool told an operator why such a session started cold.
…schemes No overlay Job over 63 bytes was ever creatable, so its name can move to the shared helper, which also stays valid when the cut lands on a dot. The snapshot, restore and GC Jobs keep their own helper: it differs from the shared one when the kept prefix holds a run of dashes, and those Jobs are found again by recomputing a name that is already in use.
The existing tests sample long names. This one sweeps every length a pod name can have, in the shapes that move where the cut lands, and requires the hostname the pod boots with to be at most 63 bytes and, when shortened, a valid DNS label.
|
Answers to the two questions from the round 3 review:
|
samkim
left a comment
There was a problem hiding this comment.
Round 4 (commits 11fc30b to b9a72bc, after a clean merge of main). All four open threads are verified fixed, so 4 of 4 open earlier issues are closed (the three resolved threads are unchanged).
Verdict: ready. Two small nits can ride along; nothing blocks merge.
What was checked: the AgentSession name rules are now create-only (optionalOldSelf), and TestAgentSessionNameCEL ran against envtest with sessions that predate the rules. Session names composed from a class name are bounded through one helper. The warm-pool skip is logged. The overlay Job name uses boundedname, and the existing snapshot/restore/GC Job names are kept and pinned. Unit tests for the touched packages and the envtest name-rule test pass locally; CI (unit, integration and e2e) is green on the head commit b9a72bc.
Still open (nits):
- Test cleanup:
createBeforeNameRulescan leave the shared envtest CRD without its name rules if it fails midway (see inline). - Skip log placement in
prewarm.go:313(see thread reply): it fires for classes that have no warm pool.
Questions: none outstanding. Both round-3 questions are answered.
This review was drafted by an automated pipeline and checked before submission.
| return env.Client.Create(ctx, probe, client.DryRunAll) == nil | ||
| } | ||
|
|
||
| shipped := setRootRules(nil) |
There was a problem hiding this comment.
[nit] Name rules are restored only on the success path, so a failure leaves the shared envtest CRD without them
Problem: createBeforeNameRules strips both name rules from the shared AgentSession CRD at this line and puts them back at line 225, with nothing in between that runs on failure. If the 30s eventually (line 216) times out on a loaded box, or a require.NoError in the create loop fires, the function exits with the rules still removed. Every later test in the package then runs against a CRD that admits long and dotted names, and fails for a misleading reason.
Fix: right after line 215 add t.Cleanup(func() { setRootRules(shipped) }). Keep the explicit restore and wait at lines 225-226 so the happy path still returns only once the rules are enforced again; the second restore is idempotent.
Test: no new test. Run go test -tags=integration -run TestAgentSessionNameCEL ./pkg/apis/v1alpha1/ and confirm it still passes.
| // +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase" | ||
| // +kubebuilder:printcolumn:name="Turns",type="integer",JSONPath=".status.progress.turnCount" | ||
| // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" | ||
| // +kubebuilder:validation:XValidation:rule="self.metadata.name.size() <= 63",message="metadata.name must be at most 63 characters: a session's name is stamped as a label on its pods, claims and network policies, and a label value cannot be longer" |
There was a problem hiding this comment.
Verified at b9a72bc5: both rules are oldSelf.hasValue() || <rule> with optionalOldSelf=true (agentsession_types.go:16-17), CRD and install bundle regenerated. TestAgentSessionNameCEL ("a session that predates the rules") ran against envtest and passes: status update, label update and finalizer removal succeed, while new 64-byte, dotted and re-created long names are still refused.
| // ran: its pods were refused one reconcile after another. | ||
| // | ||
| // The CRD refuses such a name at admission instead (the XValidation rules on | ||
| // AgentSession), and every place the platform composes a session name itself |
There was a problem hiding this comment.
Verified at b9a72bc5: NewClassSessionName (agentsession_name.go:68) is used by oap chat, oap agent run and the browser session composer, and TestNewClassSessionName covers 49/50/100-dotted/253-byte classes. Keeping 49 bytes for the -chan label is the right call.
| // hostname is not in the class spec), but only as a side effect of how the | ||
| // hostname happens to be carried. This states the rule on the name it is | ||
| // actually about. | ||
| if podspec.HostnameFor(claimName) != "" { |
There was a problem hiding this comment.
Verified at b9a72bc5: the skip is logged at INFO with session, class, pod name and length (prewarm.go:313-318), and TestEnsure_SessionClaimsOnlyUnderANameThatFitsAHostname asserts it for the 64-byte name and not for the fitting ones.
One small follow-up (nit, can ride along): the log fires before the SandboxWarmPool lookup (prewarm.go:346-355), so with the prewarm CRDs installed, a long-named session of a class that has no pool logs "not claiming a pre-warmed sandbox", which points an operator at a pool that does not exist.
Fix: do the pool Get (it does not depend on classSpec) before the hostname gate and return early on IsNotFound, so the gate only logs when a pool exists. Do not move the gate after the equality.Semantic.DeepEqual(p.Spec, classSpec) check: Build's hostname makes that check reject long names first, so the log would never fire.
Test: in TestEnsure_SessionClaimsOnlyUnderANameThatFitsAHostname (runtime_test.go) add a case with a 64-byte name and no SandboxWarmPool, asserting no skip line is logged. Run go test ./pkg/tools/sandboxkinds/agentsandbox/.
| // so the bare concatenation passes the 63 bytes a Job name may have for a | ||
| // session named with 43 or more, and the API server then refuses the Job on | ||
| // every reconcile with nothing reported on the session. | ||
| func OverlayCutJobName(dst PVCRef) string { return boundedJobName("ws-overlay-" + dst.Name) } |
There was a problem hiding this comment.
Verified at b9a72bc5 (fixed differently): OverlayCutJobName uses boundedname.Shorten (overlay.go:33), which returns any name of 63 bytes or less unchanged, so no existing overlay Job is renamed. Keeping boundedJobName for the already-shipped snapshot, restore and GC Jobs is reasonable given the -- divergence, and TestBoundedJobName pins both schemes with literals.
Problem
A pod can be named with up to 253 bytes, but a hostname is a single DNS label of at most 63. None of the session pod builders set
spec.hostname, so the kubelet derives it from the pod name and silently truncates it. A long-named pod boots with a hostname that is no longer its own name.Pod names are composed from the session name plus a per-pod suffix, and a delegated child's session name embeds its parent's (
subreq-<parent session>-<suffix>-child). So a child's sidecar pod (<session>-sidecar-<ref>) crosses 63 bytes with quite ordinary names. A sidecar that derives an identity from its hostname, for example by prefixing it and registering it with another system, then builds a name that system refuses. The visible symptom is a sidecar toolbox that works in a direct session and fails every data call when the same class runs as a delegated child.Fix
podspec.HostnameFor(podName)returns an explicit hostname for a pod named past 63 bytes, and""otherwise. It is applied to the four session pod builders (runner, sidecar toolbox, sandbox and detector) and to the two probe pod builders (workshop probe and sidecar toolbox probe), whose names can pass 63 bytes as well.spec.hostnameunset, so every pod that already had a usable hostname is built exactly as before.Long names beyond the hostname
The hostname was one of several values derived from a name that has a shorter limit than the name itself. This PR audits the rest and closes the ones that failed late or silently.
oap chat,oap agent runand the browser) are named after the class and are bounded the same way, so a long or dotted class name no longer produces a session that is refused.Tracing a shortened hostname
A shortened hostname is a prefix plus a hash, so the pod can no longer be read off it. A pod that gets one now also carries:
agentprimitives.authzed.com/hostname, set to the hostname, sokubectl get pods -A -l agentprimitives.authzed.com/hostname=<hostname>finds the pod from a log line or an external registration;agentprimitives.authzed.com/hostname-source, set to the pod's full name.Pods whose name already fits carry neither and are built exactly as before. From the pod, its owner reference and session label lead to the session; a delegated or restarted child's
spec.parent/spec.forkedFromcarry its parent's full name even when the child's own name no longer spells it out.Testing
Written test-first; each test was run and seen to fail before the change.
TestHostnameFor_*: short names keep the default, a long name becomes a valid DNS label (pinned as a literal), names sharing a truncated prefix stay distinct, and a cut never leaves an invalid label. One test sweeps every length a pod name can have and requires the hostname to stay within 63 bytes at each.BuildSidecarPod,BuildRunnerPod,podspec.Build,cosidecar.BuildPod, and both probe pod builders.The touched packages pass, including both backends' conformance tests under the
integrationtag and the delegation scenarios under thee2etag, and they vet cleanly under theintegrationande2ebuild tags. The full unit, integration and e2e suites have not been run locally; they run in CI.