From e1acb4d94745c74aefa7222fd8e0858e9600c593 Mon Sep 17 00:00:00 2001 From: mansoora Date: Thu, 9 Jan 2025 20:40:03 +0530 Subject: [PATCH] fix for #19066 Print warnings when deprecated options are configured in config file Signed-off-by: mansoora --- server/config/config.go | 32 --------------------- server/etcdmain/config.go | 59 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 32 deletions(-) diff --git a/server/config/config.go b/server/config/config.go index 8cb3c7869f3..80553ed792b 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -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 } @@ -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 } @@ -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 -} diff --git a/server/etcdmain/config.go b/server/etcdmain/config.go index ca651e1669c..82ea97a939d 100644 --- a/server/etcdmain/config.go +++ b/server/etcdmain/config.go @@ -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() } @@ -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 }