Repository navigation
fix(backend): don't stamp rossoctl.io/type on Shipwright-finalized workloads (#2489) - #2507
Conversation
…rkloads Selecting Workload Type "Deployment" for an agent import made finalize_shipwright_build create a raw Deployment carrying the rossoctl.io/type label (copied from the Build's labels). The agent-label-protection ValidatingAdmissionPolicy only lets the rossoctl-operator set that label (via AgentRuntime reconciliation), so the create was rejected with a 403 and no workload, pod, or AgentRuntime was produced. The failure was silent in the UI. Add _carryover_workload_labels(), which copies every rossoctl.io/* label from the Build except rossoctl.io/type, and use it in the Deployment, StatefulSet, and Job branches of finalize_shipwright_build. This mirrors _build_common_labels, which already omits the label for the same reason. The operator stamps rossoctl.io/type afterwards from the AgentRuntime CR that finalize creates, so the running workload ends up correctly labeled. The Sandbox and Service paths are unchanged (a Sandbox is an operator-owned CR the policy does not match; the Service is not covered). Also fix the silent-failure UX: the build-progress auto-finalize effect re-fired on every poll tick after a finalize error (the phase stays "Succeeded"), hammering the backend and preventing the error Alert from stabilizing. Gate it behind a hasAutoFinalized latch (shouldAutoFinalize helper) so it fires at most once per build; the user re-runs finalize via the existing Retry button. Applied to both the agent and tool build-progress pages. Fixes #2489 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Mariusz Sabath <[email protected]>
…quest finalize_shipwright_build reads request.contexts unconditionally, but the router-split refactor added the k8sResourceLimits/k8sResourceRequests mirror fields to FinalizeShipwrightBuildRequest and missed contexts. Every Deployment/StatefulSet/Job finalize therefore raised AttributeError: 'FinalizeShipwrightBuildRequest' object has no attribute 'contexts' before any workload was created, returning 500 (and looping in the build reconciler). This blocked the Deployment import path independently of the rossoctl.io/type label 403 -- both had to be fixed for #2489. Mirror CreateAgentRequest.contexts on the finalize model (Optional, default None) so the access is valid and the stored-config fallback applies. Verified on Kind: with both fixes, an agent imported as Workload Type "Deployment" finalizes cleanly -- Deployment, Service, and AgentRuntime are created, the operator stamps rossoctl.io/type=agent, and the pod runs 1/1. Refs #2489 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Mariusz Sabath <[email protected]>
CI lint (ruff 0.15.12) collapses the dict comprehension in the new _carryover_workload_labels helper onto a single line. Whitespace only; no behavior change. Fixes the failing lint (3.11)/(3.12) checks on #2507. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Mariusz Sabath <[email protected]>
esnible
left a comment
There was a problem hiding this comment.
Summary
Fixes two independent, verified bugs blocking the Deployment/StatefulSet/Job finalize path (#2489): a 403 from carrying rossoctl.io/type onto raw workloads (violates the agent-label-protection admission policy), and a missing contexts field on FinalizeShipwrightBuildRequest causing an AttributeError → 500. Also fixes a UI retrigger loop where auto-finalize hammered the backend after a finalize error. Both backend claims were independently verified against origin/main (the label-omission pattern already used in _build_common_labels, and the unconditional request.contexts access in finalize_shipwright_build) and hold up. New tests cover the regression on both backend (pytest) and frontend (vitest).
Author: mrsabath (MEMBER — maintainer)
Areas reviewed: Python (backend routers/models/tests), Frontend (TSX pages, new util + test)
Agent/IDE config (.claude/.vscode): none
Commits: 4 commits (3 substantive + 1 merge), all substantive commits signed-off: yes
CI status: passing (E2E HyperShift and Deploy & Test are pending manual /run-e2e trigger — not blocking; all required checks green)
No blocking issues. Clean, well-scoped fix with good regression coverage.
Summary
Fixes #2489 — importing an agent with Workload Type:
Deploymentsucceeded at build time but silently created no Deployment, pod, or AgentRuntime. E2E on Kind uncovered two independent bugs on the Deployment finalize path; both are fixed here.Bug 1 —
rossoctl.io/typelabel 403 (the reported symptom)finalize_shipwright_buildre-applied allrossoctl.io/*labels from the Shipwright Build onto the raw workload, includingrossoctl.io/type. Theagent-label-protectionValidatingAdmissionPolicy only lets the operator SA set that label (viaAgentRuntimereconciliation), so the create was rejected with 403.Fix: new pure helper
_carryover_workload_labels()(agents_manifests.py) carries everyrossoctl.io/*label exceptrossoctl.io/type— mirroring_build_common_labels, which already omits it. Used in the Deployment / StatefulSet / Job branches offinalize_shipwright_build. The operator stampsrossoctl.io/typeafterwards from the AgentRuntime CR. Sandbox and Service paths unchanged.Bug 2 —
AttributeError: contexts→ 500 (found during E2E)With bug 1 fixed, finalize still 500'd:
finalize_shipwright_buildreadsrequest.contextsunconditionally, but the router-split refactor added thek8sResourceLimits/k8sResourceRequestsmirror fields toFinalizeShipwrightBuildRequestand missedcontexts. Every Deployment/StatefulSet/Job finalize raisedAttributeErrorbefore any workload was created (and looped in the build reconciler).Fix: mirror
CreateAgentRequest.contextsonFinalizeShipwrightBuildRequest(Optional, defaultNone).UI — silent-failure UX
The build-progress auto-finalize
useEffectre-fired on every poll tick after a finalize error (phase staysSucceeded), hammering the backend and preventing the error Alert from stabilizing — matching the issue's "build re-triggers, consuming resources." NewshouldAutoFinalize()helper + ahasAutoFinalizedlatch make it fire at most once per build; the user re-runs via the existing Retry button. Applied toBuildProgressPage.tsxandToolBuildProgressPage.tsx.Testing
test_shipwright_finalize_labels.py(label-strip +contextsfield regression); full suite 782 passed; ruff clean. (Pre-existing unrelatedtest_migration.pycollection error not touched.)buildFinalize.test.ts(fire-once / no-retrigger); all 93 vitest pass;tsc -b+ build pass; eslint clean.Deploymentfinalizes cleanly. Backend log:type=agentREADY, pod Running 1/1, noagent-label-protection403, noAttributeError.Assisted-By: Claude Code