fix(validator): harden Trainer controller toleration handling - #2460
fix(validator): harden Trainer controller toleration handling#2460mikecook wants to merge 1 commit into
Conversation
- TestApplyControllerTolerations_Isolation was a false green: unstructured.NestedSlice deep-copies its result, so mutating it never reached the live Deployment object or the shared controllerTolerateAll global. Switch to NestedFieldNoCopy, which returns the same map reference podSpec["tolerations"] actually holds, so the guard can observe aliasing. Verified by temporarily reverting cloneControllerTolerateAll to alias the shared slice: the fixed test fails, confirming it now catches that regression. - Moved a doc comment that described TestApplyControllerTolerations but sat above the unrelated TestApplyControllerTolerations_Isolation, leaving the former undocumented. - decodeTrainerObjects's seenControllers warn-loop recorded any Kind=="Deployment" as "seen" regardless of API group, while applyControllerTolerations gates the actual toleration stamp on Group=="apps" too. A Deployment-kind resource in a non-apps group named like a controller would mark that name seen and suppress the warning without the controller ever receiving the toleration - the exact silent-miss the warning exists to catch. Gated the seenControllers write the same way, and extracted the now thrice-repeated "apps" literal into an apiGroupApps const (goconst). Signed-off-by: Mike Cook <micook@nvidia.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Enterprise Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 12 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe performance validator adds a shared Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This PR hardens controller toleration handling and its regression coverage without changing public interfaces; no actionable merge-blocking risk remains after normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
TestApplyControllerTolerations_Isolation was a false green: unstructured.NestedSlice deep-copies its result, so mutating it never reached the live Deployment object or the shared controllerTolerateAll global. Switch to NestedFieldNoCopy, which returns the same map reference podSpec["tolerations"] actually holds, so the guard can observe aliasing. Verified by temporarily reverting cloneControllerTolerateAll to alias the shared slice: the fixed test fails, confirming it now catches that regression.
Moved a doc comment that described TestApplyControllerTolerations but sat above the unrelated TestApplyControllerTolerations_Isolation, leaving the former undocumented.
decodeTrainerObjects's seenControllers warn-loop recorded any Kind=="Deployment" as "seen" regardless of API group, while applyControllerTolerations gates the actual toleration stamp on Group=="apps" too. A Deployment-kind resource in a non-apps group named like a controller would mark that name seen and suppress the warning without the controller ever receiving the toleration - the exact silent-miss the warning exists to catch. Gated the seenControllers write the same way, and extracted the now thrice-repeated "apps" literal into an apiGroupApps const (goconst).
Summary
Harden the Trainer/JobSet controller toleration handling introduced in #2445: fix a false-green isolation test, correct a misplaced doc comment, and close a gap where the controller-missing warning could be silently suppressed.
Motivation / Context
A follow-up look at the toleration-handling code in
validators/performance/trainer_lifecycle.goturned up three issues worth fixing before they bite:TestApplyControllerTolerations_Isolationread tolerations back viaunstructured.NestedSlice, which deep-copies its result. Mutating that copy can never reach the live Deployment object or the sharedcontrollerTolerateAllglobal, so the test could not actually detect an aliasing regression — it was a false green.TestApplyControllerTolerationswas misplaced above the unrelatedTestApplyControllerTolerations_Isolation, leaving the former undocumented.decodeTrainerObjects'sseenControllerstracking (used to warn when an expected controller Deployment is missing) matched onKind=="Deployment"alone, whileapplyControllerTolerationsadditionally gates onGroup=="apps". A Deployment-kind resource in a non-apps group named like a controller would mark that name "seen" and suppress the warning, even though it never received the toleration — the exact silent-miss the warning exists to catch.Fixes: N/A
Related: N/A
Type of Change
Component(s) Affected
cmd/aicr,pkg/cli)cmd/aicrd,pkg/server)pkg/recipe)pkg/bundler,pkg/component/*)pkg/collector,pkg/snapshotter)pkg/validator)pkg/errors,pkg/k8s)docs/,examples/)Implementation Notes
Switched the isolation test from
unstructured.NestedSlicetounstructured.NestedFieldNoCopy, which returns the same map referencepodSpec["tolerations"]actually holds, so mutating it in place can observe aliasing. Verified this closes the gap by temporarily revertingcloneControllerTolerateAllto alias the shared slice: the fixed test failed as expected, confirming it now catches the regression it's meant to guard, then restored the correct code.Gated the
seenControllerswrite indecodeTrainerObjectsonGroup=="apps"in addition toKind=="Deployment", matchingapplyControllerTolerations's existing gate. This pushed the"apps"string literal to a third non-test occurrence, trippinggolangci-lint'sgoconstthreshold, so extracted it into anapiGroupAppsconstant inconsts.goand reused it at all three call sites.Testing
make qualifypassed clean:make test-coverage: all packages pass with-racemake lint(golangci-lint + yamllint): clean, 0 issuesmake tuning-check: cleanmake e2e(chainsaw,--no-cluster): 24/24 passed, 0 failed, 0 skippedmake scan(grype): no new vulnerabilities introduced by this changemake license-check: cleanmake api-diff: no incompatible SDK facade / transparent-alias changes since v0.20.0Also manually verified the isolation-test fix by temporarily reintroducing the aliasing bug it guards against (reverting
cloneControllerTolerateAllto return the shared slice) and confirmingTestApplyControllerTolerations_Isolationfails, then restored the fix.Risk Assessment
Rollout notes: N/A — test-only and internal-validator-logic changes; no recipe/API/CLI surface change.
Checklist
make testwith-race)make lint)git commit -S) — GPG signing info