Skip to content

cluster: return an error when edit-config rejects a topology file - #2762

Open
developer-Bushido wants to merge 1 commit into
pingcap:masterfrom
developer-Bushido:fix-edit-config-exit-code
Open

developer-Bushido wants to merge 1 commit into
pingcap:masterfrom
developer-Bushido:fix-edit-config-exit-code

Conversation

@developer-Bushido

@developer-Bushido developer-Bushido commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

tiup cluster edit-config <name> --topology-file <file> exits with 0 when the file is not applied. If the file cannot be parsed or changes an immutable field, it prints New topology could not be saved: ... and Nothing changed. and returns success, so a script or a CI job cannot tell that the topology was rejected. We had a CI job that looked green for weeks while the change was never applied.

With --format json the output of such a run is also not valid JSON, and it ends with {"exit_code":0}:

New topology could not be saved: {"level":"error","message":"immutable field changed: ..."}
{"level":"info","message":"Nothing changed."}
{"exit_code":0}

tiup dm edit-config uses the same code and behaves the same way.

What is changed and how it works?

  • With --topology-file, edit-config now returns the error when the file cannot be parsed or changes an immutable field, so the command exits with 1. In JSON mode the result is {"exit_code":1,"error":"..."}.
  • A parse failure is returned as ErrTopologyParseFailed, the same error that deploy, scale-out and check return for a broken topology file.
  • The interactive mode is not changed. It still prints the reason and asks whether to continue editing.
  • A file that is identical to the current topology is still not an error.

The behaviour changes only for a --topology-file run that was rejected: the exit code was 0 and is now 1, and the reason is printed as an error instead of New topology could not be saved: ... followed by Nothing changed..

Check List

Tests

  • Unit test

TestEditConfigTopologyFile runs EditConfig with a topology file that changes an immutable field, one with an unknown field, an unchanged one and one with an editable change. The first two cases fail without the fix.

Code changes

  • Has exported function/method change
  • Has exported variable/fields change
  • Has interface methods change
  • Has persistent data change

Side effects

  • Possible performance regression
  • Increased code complexity
  • Breaking backward compatibility

Related changes

  • Need to cherry-pick to the release branch
  • Need to update the documentation

Release notes:

Fix the issue that `edit-config --topology-file` exits with 0 when the topology file is rejected

Summary by CodeRabbit

  • Bug Fixes
    • Invalid topology files now return a clear error instead of being treated as unchanged.
    • Topology files containing unsupported changes are rejected without altering cluster metadata.
    • Valid files that make no changes continue to succeed, and supported server-configuration edits are saved.
    • Interactive topology editing continues to allow users to correct parse or validation issues and retry.

With --topology-file, edit-config printed "New topology could not be
saved" and "Nothing changed." and exited with 0 when the file could not
be parsed or changed an immutable field. A script or CI job could not
tell that the topology was not applied.

Return the error in this case. The interactive mode is not changed, it
still asks whether to continue editing.
@ti-chi-bot
ti-chi-bot Bot requested review from breezewish and kaaaaaaang December 4, 2026 13:24
@ti-chi-bot

ti-chi-bot Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign bb7133 for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot added contribution size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 4, 2026
@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

editTopo now returns errors when a supplied topology file fails to parse or fails spec-diff validation. Interactive editing retains its prompt and retry behavior. New tests cover failure, unchanged-topology, and successful configuration-edit outcomes.

Changes: Topology file edits

Layer / File(s) Summary
Handle and test topology file edits
pkg/cluster/manager/edit_config.go, pkg/cluster/manager/edit_config_test.go
editTopo returns errors for parse and validation failures when a topology file is supplied. Tests check that failure and unchanged-topology cases do not alter metadata, and that a TiDB server-config edit is saved.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: haiboumich, astroprofundis

Merge Risk: Minimal · up to d499a

The command now exits with an error when a supplied topology file is rejected, instead of reporting success. Interactive editing is unchanged. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: edit-config now returns an error when it rejects a topology file. The raw summary shows editTopo returning ErrTopologyParseFailed and an annotated error for ValidateSp…
Description check Passed The description follows the template. It states the problem and the fix in 'What is changed and how it works?', and it describes the change in detail. The Check List marks the unit test item and links…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: edit-config now returns an error when it rejects a topology file. The raw summary shows editTopo returning ErrTopologyParseFailed and an annotated error for ValidateSpecDiff rejections when a topology file is supplied, which matches the title. The title is concise and specific, and the 'cluster:' prefix follows the repository's convention.

Full details: Description check

Explanation

The description follows the template. It states the problem and the fix in 'What is changed and how it works?', and it describes the change in detail. The Check List marks the unit test item and links the new test, TestEditConfigTopologyFile. The release-note block is filled in. The template's 'close #xxx' line is absent, and no issue link is given. Also, the Code changes and Side effects items are left unmarked, which the author may have intended. These gaps are minor, so the description is mostly complete.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit reads the topology page,
And checks each field from root to edge.
Bad YAML gets an error clear,
Good settings save and stay right here.
The rabbit hops, pleased with the change.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9939523a-e944-4d38-b2dc-1f3aecc9cb2c
Commits

Reviewing files that changed from the base of the PR and between 2750ed6 and d499ac9.

Files selected for processing: 2

  • pkg/cluster/manager/edit_config.go
  • pkg/cluster/manager/edit_config_test.go

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@codecov-commenter

codecov-commenter commented Dec 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 43.64%. Comparing base (d9d2e87) to head (d499ac9).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
pkg/cluster/manager/edit_config.go 50.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2762      +/-   ##
==========================================
- Coverage   43.82%   43.64%   -0.19%     
==========================================
  Files         430      430              
  Lines       48094    48094              
==========================================
- Hits        21077    20988      -89     
- Misses      24262    24374     +112     
+ Partials     2755     2732      -23     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@developer-Bushido

Copy link
Copy Markdown
Contributor Author

The playground failure looks like the known flaky start check (connection refused on 127.0.0.1:9527), not related to this change. Could someone rerun it?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants