Skip to content

Commit

Permalink
fix for etcd-io#19066 Print warnings when deprecated options are conf…
Browse files Browse the repository at this point in the history
…igured in config file

Signed-off-by: mansoora <[email protected]>
  • Loading branch information
mansoor17syed committed Jan 9, 2025
1 parent b1422ee commit a8c4d2c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 32 deletions.
32 changes: 0 additions & 32 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,6 @@ type ServerConfig struct {
// VerifyBootstrap sanity-checks the initial config for bootstrap case
// and returns an error for things that should never happen.
func (c *ServerConfig) VerifyBootstrap() error {
// Print deprecation warnings first
if warnings := c.checkDeprecatedOptions(); len(warnings) > 0 {
for _, warning := range warnings {
c.Logger.Warn(warning)
}
}

if err := c.hasLocalMember(); err != nil {
return err
}
Expand All @@ -241,13 +234,6 @@ func (c *ServerConfig) VerifyBootstrap() error {
// VerifyJoinExisting sanity-checks the initial config for join existing cluster
// case and returns an error for things that should never happen.
func (c *ServerConfig) VerifyJoinExisting() error {
// Print deprecation warnings first
if warnings := c.checkDeprecatedOptions(); len(warnings) > 0 {
for _, warning := range warnings {
c.Logger.Warn(warning)
}
}

if err := c.hasLocalMember(); err != nil {
return err
}
Expand Down Expand Up @@ -377,21 +363,3 @@ func (c *ServerConfig) BackendPath() string { return datadir.ToBackendFileName(c
func (c *ServerConfig) MaxRequestBytesWithOverhead() uint {
return c.MaxRequestBytes + grpcOverheadBytes
}

// Add this new function to check deprecated options
func (c *ServerConfig) checkDeprecatedOptions() []string {
var warnings []string

// Check for deprecated configurations
if c.ForceNewCluster {
warnings = append(warnings, "WARNING: 'force-new-cluster' option is deprecated and will be removed in future versions")
}

if c.V2Deprecation == "" {
warnings = append(warnings, "WARNING: v2 API is deprecated and will be decommissioned in etcd v3.6")
}

// Add more deprecated option checks as needed

return warnings
}
59 changes: 59 additions & 0 deletions server/etcdmain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,21 @@ func (cfg *config) configFromCmdLine() error {
return err
}

// Check for deprecated command line flags
var warningsForDeprecatedFlags []string
cfg.cf.flagSet.Visit(func(f *flag.Flag) {
if msg, ok := deprecatedFlags[f.Name]; ok {
warningsForDeprecatedFlags = append(warningsForDeprecatedFlags, msg)
}
})
if len(warningsForDeprecatedFlags) > 0 {
if lg := cfg.ec.GetLogger(); lg != nil {
for _, msg := range warningsForDeprecatedFlags {
lg.Warn(msg)
}
}
}

return cfg.validate()
}

Expand All @@ -298,6 +313,50 @@ func (cfg *config) configFromFile(path string) error {
}
cfg.ec = *eCfg

// Check for deprecated options in config file
var warningsForDeprecatedOpts []string

// Check snapshot-count
if cfg.ec.SnapshotCount != 0 {
warningsForDeprecatedOpts = append(warningsForDeprecatedOpts,
deprecatedFlags["snapshot-count"])
}

// Check max-snapshots
if cfg.ec.MaxSnapFiles != 0 {
warningsForDeprecatedOpts = append(warningsForDeprecatedOpts,
deprecatedFlags["max-snapshots"])
}

// Check v2-deprecation
if cfg.ec.V2Deprecation != "" {
warningsForDeprecatedOpts = append(warningsForDeprecatedOpts,
deprecatedFlags["v2-deprecation"])
}

// Check experimental flags
if cfg.ec.ExperimentalCompactHashCheckEnabled {
warningsForDeprecatedOpts = append(warningsForDeprecatedOpts,
deprecatedFlags["experimental-compact-hash-check-enabled"])
}
if cfg.ec.ExperimentalCompactHashCheckTime != 0 {
warningsForDeprecatedOpts = append(warningsForDeprecatedOpts,
deprecatedFlags["experimental-compact-hash-check-time"])
}
if cfg.ec.ExperimentalTxnModeWriteWithSharedBuffer {
warningsForDeprecatedOpts = append(warningsForDeprecatedOpts,
deprecatedFlags["experimental-txn-mode-write-with-shared-buffer"])
}

// Log warnings if any deprecated options were found
if len(warningsForDeprecatedOpts) > 0 {
if lg := cfg.ec.GetLogger(); lg != nil {
for _, msg := range warningsForDeprecatedOpts {
lg.Warn(msg)
}
}
}

return nil
}

Expand Down

0 comments on commit a8c4d2c

Please sign in to comment.