refactor(validation): make DGD validation structural - #11090
Conversation
WalkthroughThe PR rewrites ChangesDGD Webhook Validator Rewrite
Estimated code review effort🎯 5 (Critical) | ⏱️ ~120 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
deploy/operator/internal/webhook/validation/dynamographdeployment_handler.go (1)
125-133: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winPreserve stateless warnings on the update error path.
validator.Validate()can already return admission warnings. IfValidateUpdate()then rejects the object, returning onlyupdateWarningsdrops those earlier warnings from the response.Suggested fix
updateWarnings, err := validator.ValidateUpdate(ctx, oldDeployment, newDeployment, userInfo, h.operatorPrincipal) if err != nil { username := "<unknown>" if userInfo != nil { username = userInfo.Username } logger.Info("validation failed", "error", err.Error(), "user", username) - return updateWarnings, err + return append(warnings, updateWarnings...), err }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@deploy/operator/internal/webhook/validation/dynamographdeployment_handler.go` around lines 125 - 133, Preserve warnings returned by validator.Validate() when the update is rejected in dynamographdeployment_handler.go: ValidateUpdate currently returns only updateWarnings on the error path, which can drop stateless admission warnings from the earlier Validate call. Update the ValidateUpdate flow in the relevant handler so it carries forward any existing warnings from the initial validation and combines them with updateWarnings before returning an error, using the ValidateUpdate/Validate symbols to locate the code.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@deploy/operator/internal/webhook/validation/dynamographdeployment_handler_test.go`:
- Around line 107-125: The ValidateUpdate test cases in
dynamographdeployment_handler_test should assert the handler’s typed
invalid-error contract instead of only matching err.Error(). Update the
“stateless validation failure” and “stateful validation failure” subtests to use
the package’s typed-error helper or inspect the returned StatusError directly
from ValidateUpdate, verifying the expected StatusError.ErrStatus.Details.Causes
and exact field paths. Ensure the assertions cover the invalid component path
and backendFramework path so the test fails if the handler returns the wrong
field path or omits causes.
In `@deploy/operator/internal/webhook/validation/dynamographdeployment_test.go`:
- Around line 1955-1969: The helper in dynamographdeployment_test.go is only
checking that StatusError has some non-empty Causes and that the rendered error
string contains wantErr; tighten it to validate the exact typed field path in
Details.Causes for the expected error, using the existing statusErr and
cause.Field checks in the test helper. Keep the string match separate or
secondary, but do not rely on strings.Contains(err.Error(), wantErr) as the
primary assertion, since the goal is to assert the specific Cause.Field produced
by the validation path.
In `@deploy/operator/internal/webhook/validation/dynamographdeployment.go`:
- Around line 419-424: The live topology lookup in validation is being skipped
whenever topologyErrs is non-empty, which can hide independent errors from
spec.TopologyConstraint.ClusterTopologyName or bad pack-domain references.
Update the logic around readGroveClusterTopology in dynamographdeployment
validation so the lookup still runs when ClusterTopologyName is set and
opts.generation/opts.grovePathway allow it, and only gate it on conditions that
truly depend on earlier topology validation. Keep topologyErrs aggregation
intact so all independent errors are reported.
- Around line 1022-1027: The replica validation in ValidateUpdate can be
bypassed when ScalingAdapter is removed in the same request because the guard
only checks newComponent.ScalingAdapter. Update the replica protection logic in
dynamographdeployment.go so it also blocks replica changes whenever the old
component had a scaling adapter identity and the replica value changes, even if
the new component clears ScalingAdapter. Use the existing ValidateUpdate flow
and the newComponent/oldComponent checks to ensure direct replica edits are
forbidden during scaling-adapter transitions.
In `@deploy/operator/internal/webhook/validation/shared_v1alpha1.go`:
- Line 223: The validation path in the shared v1alpha1 webhook is bypassing the
helper’s empty-path handling by always concatenating v.fieldPath with
".annotations", which turns an empty field path into a malformed ".annotations"
string. Update the call site in the validator around
vllmDistributedExecutorBackendAnnotationError so it preserves the empty-string
case and only appends ".annotations" when v.fieldPath is non-empty, allowing the
helper’s fieldPath == "" branch to work as intended.
---
Outside diff comments:
In
`@deploy/operator/internal/webhook/validation/dynamographdeployment_handler.go`:
- Around line 125-133: Preserve warnings returned by validator.Validate() when
the update is rejected in dynamographdeployment_handler.go: ValidateUpdate
currently returns only updateWarnings on the error path, which can drop
stateless admission warnings from the earlier Validate call. Update the
ValidateUpdate flow in the relevant handler so it carries forward any existing
warnings from the initial validation and combines them with updateWarnings
before returning an error, using the ValidateUpdate/Validate symbols to locate
the code.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: c6a5daa8-b0d4-4236-bea1-ad8b04dc4f97
📒 Files selected for processing (8)
deploy/operator/internal/webhook/validation/AGENTS.mddeploy/operator/internal/webhook/validation/dynamographdeployment.godeploy/operator/internal/webhook/validation/dynamographdeployment_handler.godeploy/operator/internal/webhook/validation/dynamographdeployment_handler_test.godeploy/operator/internal/webhook/validation/dynamographdeployment_helpers.godeploy/operator/internal/webhook/validation/dynamographdeployment_test.godeploy/operator/internal/webhook/validation/shared_v1alpha1.godeploy/operator/internal/webhook/validation/shared_v1beta1.go
💤 Files with no reviewable changes (1)
- deploy/operator/internal/webhook/validation/shared_v1beta1.go
|
/ok to test 539931d |
julienmancuso
left a comment
There was a problem hiding this comment.
I found four remaining validation-boundary concerns on the current head. The structural direction looks sound, and the previously open review findings appear addressed.
9cbe6f7 to
c2cd839
Compare
8033ebb to
46f4853
Compare
46f4853 to
ac972d6
Compare
Signed-off-by: Dr. Stefan Schimanski <sschimanski@nvidia.com>
Signed-off-by: Dr. Stefan Schimanski <sschimanski@nvidia.com>
Signed-off-by: Dr. Stefan Schimanski <sschimanski@nvidia.com>
Signed-off-by: Dr. Stefan Schimanski <sschimanski@nvidia.com>
ac972d6 to
78ad643
Compare
|
/ok to test 78ad643 |
Dependency
Depends on #11216, which owns the admission-chain test prefactor. Until that PR merges, GitHub includes its test-only commits in this PR's aggregate diff. The structural-only stacked diff is available at sttts/dynamo@sttts-dgd-admission-test-prefactor...sttts-structural-validation.
Overview
Refactor DynamoGraphDeployment validation into a structural recursion that systematically follows the Go API type tree.
Details
Where should the reviewer start?
Start with
deploy/operator/internal/webhook/validation/AGENTS.md, then follow the root validation recursion indynamographdeployment.go.Related Issues
Summary
Validation
make checkmake testmake lint