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 <syed.mansoor_a@nokia.com>
  • Loading branch information
mansoor17syed committed Jan 9, 2025
1 parent 9077115 commit 8f3d5f6
Showing 1 changed file with 14 additions and 59 deletions.
73 changes: 14 additions & 59 deletions server/etcdmain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,20 @@ func (cfg *config) parse(arguments []string) error {
return perr
}

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)
}
}
}

// now logger is set up
return err
}
Expand Down Expand Up @@ -274,21 +288,6 @@ 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 @@ -299,50 +298,6 @@ 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 8f3d5f6

Please sign in to comment.