fix(configuration): reject immutable parameter updates (main port of #10204)
Summary
Main-branch port of release-1.0 PR #10204. Rejects updates to parameters listed in ParametersDefinition.spec.immutableParameters, covering both update entry points:
- Structured
ParametersInFile.Parameterspath:filterImmutableParametersreturns an explicit error instead of silently filtering immutable keys. - Raw
ParametersInFile.Contentpath: newvalidateImmutableContentChangeshelper parses base and merged content via each file'sFileFormatConfig, rejects add / remove / modify of any immutable parameter, and ignores formatting-only changes.
The two-entry-point scope matches PR #10204 on release-1.0 so the behavior stays consistent across main and release-1.0. (The earlier split into separate PRs #10237 / #10242 was unintentional and is now folded into this single PR; #10242 will be closed.)
Architectural placement (post #10254)
PR #10254 (merged 2026-05-19) restructured the validation flow so that ClassifyComponentParameters and DoMerge are now invoked inside the ComponentParameter controller (controllers/parameters/componentparameter_controller_utils.go:122-141), processing ComponentParameter.Spec.Desired. The error path is intctrlutil.NewErrorf(intctrlutil.ErrorTypeFatal, ...) → CMergeFailedPhase.
This PR lifts both immutable-parameter rejections along the same call chain:
ComponentParameter controller
→ ClassifyComponentParameters
→ ValidateComponentParameterAssignments (schema check, from #10254)
→ DoMerge
→ mergeUpdatedParams
→ validateImmutableContentChanges (this PR, Content path) → error → ErrorTypeFatal → CMergeFailedPhase
→ MergeAndValidateConfigs
→ filterImmutableParameters (this PR, Parameters path) → error → ErrorTypeFatal → CMergeFailedPhase
All three checks (schema, content-level immutable, parameter-level immutable) sit at the layer that owns ComponentParameter.Spec.Desired state. Any future writer of Spec.Desired (Parameter CR, OpsRequest reconfigure, direct edit) goes through the same gate.
Evidence
- Observed scene: an immutable negative gate run had the OpsRequest reach
SucceededwhileComponentParameterdesired one value and the rendered pod configs stayed on the previous value. Reconfigure status reported "no config modified / skip reconfigure". - Static path matches the scene:
filterImmutableParameterssilently dropped immutable keys, producing a no-op patch that finished as Succeeded. The Content path had no immutable check at all, allowing the same bypass via raw file content.
What changed
pkg/parameters/config_util.go:filterImmutableParametersreturns(map[string]any, error)and rejects any immutable key withfmt.Errorf("immutable parameter %s cannot be modified", key). The single caller inMergeAndValidateConfigssurfaces the error.pkg/parameters/config_util_test.go: the rejection case now expectswantErr=truerather than a filtered map.pkg/parameters/patch_merger.go: invokevalidateImmutableContentChangesfrommergeUpdatedParamsafterMergeUpdatedConfig.pkg/parameters/patch_merger_test.go: 7 new cases covering modify / add / remove of immutable parameter on raw content, format-only changes (no false flag), mutable change with format noise, content on file without immutable candidate, and fail-safe when immutable declared but format missing.pkg/unstructured/viper_wrap.go: support nil-safe access forviperWrap.SubConfigso the new check does not panic when a patch removes an INI sub-section entirely (Leon's review comment on the earlier #10242 split).
Helper contract for validateImmutableContentChanges
- Only inspects files present in the current update set (no scan of unchanged files).
- Skips files whose
ParametersDefinitionhas no immutable-parameter contract, so benign content updates to ordinary files are not affected. - Parses base and merged content using each file's
FileFormatConfigand compares the parsed parameter map. Format-only changes (whitespace, comment order, blank lines,key=valuevskey = valuespacing) are not flagged. - Rejects add, remove, and modify of any immutable parameter.
- Fails safe when an immutable-parameter candidate is declared on the file but no parser is available (
FileFormatConfigmissing or parse error), so an unknown-format file cannot become a silent bypass.
Verification
go build ./pkg/parameters/...and./pkg/unstructured/...go test ./pkg/parameters -run 'Test_filterImmutableParameters|TestDoMerge' -count=1 -v(plain Go tests, 7 new content-path cases plus the existing structured-path case all PASS)go test ./pkg/unstructured -count=1PASSgit diff --check origin/main...HEADclean- Commit attribution scan clean
Diff stats
5 files changed, +351 / -14.
Relationship to #10204 and #10242
- PR #10204 (release-1.0, merged) is the equivalent release-1.0 PR. Same five files (under pre-#9846 paths), same two-entry-point scope.
- PR #10242 (main, to be closed) contained the Content-path subset before this fold-up; its three commits are now part of this PR's history. Closing #10242 preserves the review trail; this PR is the authoritative landing target.
Auto Cherry-pick Instructions
Usage:
- /nopick: Not auto cherry-pick when PR merged.
- /pick: release-x.x [release-x.x]: Auto cherry-pick to the specified branch when PR merged.
Example:
- /nopick
- /pick release-1.1
Codecov Report
:x: Patch coverage is 70.90909% with 32 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 54.19%. Comparing base (c1eb0c6) to head (4ee70fd).
:warning: Report is 15 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #10237 +/- ##
==========================================
+ Coverage 52.73% 54.19% +1.46%
==========================================
Files 534 536 +2
Lines 61231 65017 +3786
==========================================
+ Hits 32288 35238 +2950
- Misses 25691 26291 +600
- Partials 3252 3488 +236
| Flag | Coverage Δ | |
|---|---|---|
| unittests | 54.19% <70.90%> (+1.46%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
UnmanagedUpdates can still bypass the immutable-parameter guard. The new checks cover raw Content before MergeAndValidateConfigs and structured Parameters inside MergeAndValidateConfigs, but mergeUnmanagedUpdates runs afterwards and applies Set/Remove directly without checking immutableParameters. A user can still modify or remove an immutable key through ParametersInFile.UnmanagedUpdates / ComponentParameter.Spec.Desired.UnmanagedUpdates, for example setting gtid_mode in the same INI section. Please reject unmanaged updates that target immutable keys, or run the immutable diff check again after unmanaged updates are applied, and add a regression test for this path.
Addressed Leon's unmanaged-updates comment in head f20eb22c5.
What changed:
UnmanagedUpdatesnow rejects any requestedSetorRemovewhose key is declared inParametersDefinition.spec.immutableParametersfor that file.- After unmanaged updates are applied, the same parsed immutable-parameter diff guard runs again on the touched files, so any content-level immutable delta is still rejected.
- Added regression coverage for unmanaged
Setand unmanagedRemoveattempts againstgtid_mode, and kept the existing allowed unmanaged update path withgtid_modeunchanged.
Validation:
go generate ./pkg/testutil/k8s/mocks/...
go test ./pkg/parameters -run 'TestDoMerge|Test_filterImmutableParameters' -count=1
go test ./pkg/unstructured -count=1
go build ./pkg/parameters/...
go build ./pkg/unstructured/...
git diff --check
Addressed the new review comments in head 4ee70fda2.
Updates:
- P1 contract/doc mismatch: changed the API wording from "ignored" to the new rejection semantics, and synchronized the checked-in CRD YAML plus generated API reference text. The documented failure surface now says immutable changes are rejected during configuration merge and surface as a merge failure.
- P2 unmanaged section false positive: narrowed the direct unmanaged-update immutable key rejection to the managed INI section. A same-named key in another INI section is now allowed unless the post-merge parsed diff shows the managed immutable parameter changed.
- Added a regression test for updating
gtid_modein[client]while[mysqld]declaresgtid_modeimmutable.
Validation:
go test ./pkg/parameters -run 'TestDoMerge|Test_filterImmutableParameters' -count=1
go test ./pkg/unstructured -count=1
go build ./pkg/parameters/...
go build ./pkg/unstructured/...
git diff --check
Generation note: make manifests was attempted, but local controller-gen v0.14.0 cannot build on this machine's Go 1.26.3 toolchain, and Go 1.25.4 produced the same golang.org/x/tools/internal/tokeninternal compile failure. I manually synchronized the exact source-comment wording into the checked-in CRD YAML and API reference files so the PR diff contains the intended generated-text change.