unlock unlimited code runs for $79, limited time →
NOSSLETTER.techLIVE
back to OSSpedia
backwards-compatibilityconfiguration-managementrefactoring

Remove flag --max-snapshots and --v2-deprecation

Project: etcd-io/etcd | Language: Go | Concepts: backwards-compatibility, configuration-management, refactoring | Difficulty: mid
Link: https://github.com/etcd-io/etcd/pull/22306

The problem

etcd had two configuration flags, --max-snapshots and --v2-deprecation, that were deprecated and no longer relevant after the removal of the v2store code. Their continued presence added confusion and unnecessary maintenance burden.

Why it's non-trivial

Simply deleting the flags is not enough:

  • They appeared in multiple locations (code, config files, tests, docs).
  • They were referenced through types and logic that needed to be fully cleaned up.
  • Removing them risked breaking backward compatibility or causing unclear errors for users who might still be using the old flags.

The approach

The PR removes all code, config, and tests related to the two flags.

1. Remove from config files and documentation:

-# Maximum number of snapshot files to retain (0 is unlimited).
-max-snapshots: 5

Removes the max-snapshots option from the sample configuration file, making it clear to users that this option is no longer available.

2. Remove from configuration structs:

-type ServerConfig struct {
-    ...
-    MaxSnapFiles uint
-    MaxWALFiles  uint
+    MaxWALFiles uint

Deletes the MaxSnapFiles field from the main server config struct, so it cannot be set or used anywhere.

3. Remove the entire v2 deprecation enum and logic:

-diff --git a/server/config/v2_deprecation.go b/server/config/v2_deprecation.go
-deleted file mode 100644

Deletes the file that defined the V2DeprecationEnum type and its logic, fully removing the concept from the codebase.

4. Remove command-line flag registration and parsing:

-fs.UintVar(&cfg.MaxSnapFiles, "max-snapshots", cfg.MaxSnapFiles, "Maximum number of snapshot files to retain (0 is unlimited). Deprecated in v3.6 and will be decommissioned in v3.8.")
-fs.Var(cfg.cf.v2deprecation, "v2-deprecation", ...)

Removes the flag definitions so users cannot set these options from the CLI anymore.

5. Remove related test code:

-diff --git a/server/config/v2_deprecation_test.go b/server/config/v2_deprecation_test.go
-deleted file mode 100644

Deletes tests that only existed to validate the now-removed v2 deprecation logic.

6. Remove all code paths that set, check, or log these flags:

-    // `V2Deprecation` (--v2-deprecation) is deprecated and scheduled for removal in v3.8. The default value is enforced, ignoring user input.
-    cfg.ec.V2Deprecation = cconfig.V2DeprDefault;

Ensures there are no leftover assignments or defaulting logic for the removed flags.

From the review thread

No notable review discussion on this PR.

Takeaways

  • Remove all references when deprecating a feature: When eliminating a deprecated flag or config, search for and remove all related code, documentation, and tests to avoid confusion and dead code.
  • Coordinate config and code changes: Ensure that configuration files, CLI flags, and internal structs are updated in sync to prevent mismatches or runtime errors.
  • Be mindful of user experience: Removing options that users may still try to use requires clear communication (e.g., via release notes) and careful handling to avoid silent failures.