fix(operations): two-pass reconfigure validation to prevent partial CP pollution - #10438
fix(operations): two-pass reconfigure validation to prevent partial CP pollution#10438weicao wants to merge 3 commits into
Conversation
…P pollution Separate Action() into validate-all then apply-all so that an invalid parameter in a later Reconfigure entry cannot leave dirty CP desired from an earlier entry. Also resolve each shard actual CompDef for schema validation instead of using only the sharding template default. Fixes: PR #10415 P1 review comments Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ion tests Cover both P1 review scenarios: - Multi-entry: valid first entry + invalid second entry verifies neither CP desired gets patched (two-pass invariant) - Sharding: validates against actual shard ComponentDefinition, not just template default Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…actual CompDef Use templateCompDef (no schema) for the sharding template and actualShardCompDef (strict schema) for the real shard Component. If the code regressed to checking only the template default, validation would pass; only the ListShardingComponents path rejects unknown_param. Also add CP desired no-dirty assertion. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Auto Cherry-pick Instructions CLA Recheck Instructions |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #10438 +/- ##
==========================================
- Coverage 62.04% 62.02% -0.02%
==========================================
Files 533 533
Lines 63625 63673 +48
==========================================
+ Hits 39473 39493 +20
- Misses 20550 20579 +29
+ Partials 3602 3601 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| if len(reconfigure.Parameters) == 0 { | ||
| return intctrlutil.NewErrorf(intctrlutil.ErrorTypeFatal, "invalid reconfigure request for component %s: no parameters", reconfigure.ComponentName) | ||
| } | ||
| if err := r.validateReconfigureParameters(reqCtx, cli, resource.Cluster, reconfigure); err != nil { |
There was a problem hiding this comment.
This two-pass prevalidation needs stronger justification. Parameter schema validation belongs to the ComponentParameter/parameters controller path; Ops should trigger the desired update, not duplicate the schema validation responsibility. If the partial-write concern is about multiple entries targeting the same ComponentParameter, the safer fix is to coalesce those changes and patch that CP once. If the entries target different components, there has not been cross-component transaction semantics, so making one component invalid parameter block unrelated components adds a new all-or-nothing behavior that the API does not currently promise. Please keep schema validation in the parameters controller path, or explain the strong API-level reason for introducing this cross-component preflight semantics.
|
Closing per reviewer direction: parameter schema validation belongs to the ComponentParameter/parameters controller path, not the Ops reconfigure action. The Ops action should only trigger desired updates and let the parameters controller handle validation. This applies to both this PR and the original #10415. |
Summary
Action()into validate-all then apply-all (two-pass) so that an invalid parameter in a later Reconfigure entry cannot leave dirtyComponentParameter.spec.desiredfrom an earlier entry.ComponentDefinitionviaListShardingComponentsfor schema validation, instead of using only the sharding template default.Problem
The original PR #10415 had two P1 issues identified by @leon-ape:
Solution
Pass 1 iterates all
Reconfigureentries and callsvalidateReconfigureParameters()which resolves the actual ComponentDefinition(s), loads theirParametersDefinitionJSON schema, and validates parameter assignments. Any failure returns a fatal error immediately — no CP is touched.Pass 2 only runs after all validations pass, applying patches via
applyReconfigureToParameters().For sharding,
resolveCompDefNames()callssharding.ListShardingComponents()to get the realComponentobjects and theirSpec.CompDef, collecting unique CompDef names for validation.Test plan
rejects unknown parameter before patching CP desired— single invalid param rejected, CP desired cleanmulti-entry: invalid second entry blocks valid first entry from patching CP— two components, first valid + second invalid, neither CP patchedsharding: validates against actual shard ComponentDefinition, not template default— template CompDef has no schema, actual shard CompDef has strict schema; only the ListShardingComponents path rejects unknown_paramTest Reconfigure OpsRequestandpropagates ComponentParameter merge failurestill passgo build,go vet,git diff --checkcleanSupersedes #10415 (addresses P1 review comments).