Skip to content

Commit

Permalink
Print warning message for deprecated flags if set
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Wang <[email protected]>
  • Loading branch information
ahrtr committed Dec 3, 2024
1 parent 8f6c30d commit 28a19f7
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 8 deletions.
41 changes: 34 additions & 7 deletions server/etcdmain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import (
"sigs.k8s.io/yaml"
)

const deprecatedWarningMessage = "--%s is deprecated in 3.5 and will be decommissioned in 3.6."

var (
proxyFlagOff = "off"
proxyFlagReadonly = "readonly"
Expand All @@ -62,6 +64,17 @@ var (
"test.coverprofile",
"test.outputdir",
}

deprecatedFlags = map[string]struct{}{
"enable-v2": struct{}{},
"experimental-enable-v2v3": struct{}{},
"proxy": struct{}{},
"proxy-failure-wait": struct{}{},
"proxy-refresh-interval": struct{}{},
"proxy-dial-timeout": struct{}{},
"proxy-write-timeout": struct{}{},
"proxy-read-timeout": struct{}{},
}
)

type configProxy struct {
Expand Down Expand Up @@ -207,17 +220,17 @@ func newConfig() *config {

fs.BoolVar(&cfg.ec.PreVote, "pre-vote", cfg.ec.PreVote, "Enable to run an additional Raft election phase.")

fs.BoolVar(&cfg.ec.EnableV2, "enable-v2", cfg.ec.EnableV2, "Accept etcd V2 client requests. Deprecated in v3.5. Will be decommission in v3.6.")
fs.StringVar(&cfg.ec.ExperimentalEnableV2V3, "experimental-enable-v2v3", cfg.ec.ExperimentalEnableV2V3, "v3 prefix for serving emulated v2 state. Deprecated in 3.5. Will be decomissioned in 3.6.")
fs.BoolVar(&cfg.ec.EnableV2, "enable-v2", cfg.ec.EnableV2, "Accept etcd V2 client requests. Deprecated in v3.5 and will be decommissioned in v3.6.")
fs.StringVar(&cfg.ec.ExperimentalEnableV2V3, "experimental-enable-v2v3", cfg.ec.ExperimentalEnableV2V3, "v3 prefix for serving emulated v2 state. Deprecated in 3.5 and will be decommissioned in 3.6.")
fs.Var(cfg.cf.v2deprecation, "v2-deprecation", fmt.Sprintf("v2store deprecation stage: %q. ", cfg.cf.proxy.Valids()))

// proxy
fs.Var(cfg.cf.proxy, "proxy", fmt.Sprintf("Valid values include %q", cfg.cf.proxy.Valids()))
fs.UintVar(&cfg.cp.ProxyFailureWaitMs, "proxy-failure-wait", cfg.cp.ProxyFailureWaitMs, "Time (in milliseconds) an endpoint will be held in a failed state.")
fs.UintVar(&cfg.cp.ProxyRefreshIntervalMs, "proxy-refresh-interval", cfg.cp.ProxyRefreshIntervalMs, "Time (in milliseconds) of the endpoints refresh interval.")
fs.UintVar(&cfg.cp.ProxyDialTimeoutMs, "proxy-dial-timeout", cfg.cp.ProxyDialTimeoutMs, "Time (in milliseconds) for a dial to timeout.")
fs.UintVar(&cfg.cp.ProxyWriteTimeoutMs, "proxy-write-timeout", cfg.cp.ProxyWriteTimeoutMs, "Time (in milliseconds) for a write to timeout.")
fs.UintVar(&cfg.cp.ProxyReadTimeoutMs, "proxy-read-timeout", cfg.cp.ProxyReadTimeoutMs, "Time (in milliseconds) for a read to timeout.")
fs.UintVar(&cfg.cp.ProxyFailureWaitMs, "proxy-failure-wait", cfg.cp.ProxyFailureWaitMs, "Time (in milliseconds) an endpoint will be held in a failed state. Deprecated in 3.5 and will be decommissioned in 3.6.")
fs.UintVar(&cfg.cp.ProxyRefreshIntervalMs, "proxy-refresh-interval", cfg.cp.ProxyRefreshIntervalMs, "Time (in milliseconds) of the endpoints refresh interval. Deprecated in 3.5 and will be decommissioned in 3.6.")
fs.UintVar(&cfg.cp.ProxyDialTimeoutMs, "proxy-dial-timeout", cfg.cp.ProxyDialTimeoutMs, "Time (in milliseconds) for a dial to timeout. Deprecated in 3.5 and will be decommissioned in 3.6.")
fs.UintVar(&cfg.cp.ProxyWriteTimeoutMs, "proxy-write-timeout", cfg.cp.ProxyWriteTimeoutMs, "Time (in milliseconds) for a write to timeout. Deprecated in 3.5 and will be decommissioned in 3.6.")
fs.UintVar(&cfg.cp.ProxyReadTimeoutMs, "proxy-read-timeout", cfg.cp.ProxyReadTimeoutMs, "Time (in milliseconds) for a read to timeout. Deprecated in 3.5 and will be decommissioned in 3.6.")

// security
fs.StringVar(&cfg.ec.ClientTLSInfo.CertFile, "cert-file", "", "Path to the client server TLS cert file.")
Expand Down Expand Up @@ -364,6 +377,20 @@ func (cfg *config) parse(arguments []string) error {
cfg.ec.V2Deprecation = cconfig.V2_DEPR_DEFAULT
}

var warningsForDeprecatedFlags []string
cfg.cf.flagSet.Visit(func(f *flag.Flag) {
if _, ok := deprecatedFlags[f.Name]; ok {
warningsForDeprecatedFlags = append(warningsForDeprecatedFlags, fmt.Sprintf(deprecatedWarningMessage, f.Name))
}
})
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
2 changes: 1 addition & 1 deletion server/etcdmain/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ Experimental distributed tracing:
--experimental-distributed-tracing-sampling-rate '0'
Number of samples to collect per million spans for distributed tracing. Disabled by default.
v2 Proxy (to be deprecated in v3.6):
v2 Proxy (Deprecated and to be decommissioned in v3.6):
--proxy 'off'
Proxy mode setting ('off', 'readonly' or 'on').
--proxy-failure-wait 5000
Expand Down
69 changes: 69 additions & 0 deletions tests/e2e/etcd_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,5 +549,74 @@ func TestEtcdTLSVersion(t *testing.T) {
assert.NoError(t, err)
assert.NoError(t, e2e.WaitReadyExpectProc(proc, e2e.EtcdServerReadyLines), "did not receive expected output from etcd process")
assert.NoError(t, proc.Stop())
}

// TestEtcdDeprecatedFlags checks that etcd will print warning messages if deprecated flags are set.
func TestEtcdDeprecatedFlags(t *testing.T) {
e2e.SkipInShortMode(t)

commonArgs := []string{
e2e.BinDir + "/etcd",
"--name", "e1",
}

deprecatedWarningMessage := "--%s is deprecated in 3.5 and will be decommissioned in 3.6."

testCases := []struct {
name string
args []string
expectedMsg string
}{
{
name: "enable-v2",
args: append(commonArgs, "--enable-v2"),
expectedMsg: fmt.Sprintf(deprecatedWarningMessage, "enable-v2"),
},
{
name: "experimental-enable-v2v3",
args: append(commonArgs, "--experimental-enable-v2v3", "v3prefix"),
expectedMsg: fmt.Sprintf(deprecatedWarningMessage, "experimental-enable-v2v3"),
},
{
name: "proxy",
args: append(commonArgs, "--proxy", "off"),
expectedMsg: fmt.Sprintf(deprecatedWarningMessage, "proxy"),
},
{
name: "proxy-failure-wait",
args: append(commonArgs, "--proxy-failure-wait", "10"),
expectedMsg: fmt.Sprintf(deprecatedWarningMessage, "proxy-failure-wait"),
},
{
name: "proxy-refresh-interval",
args: append(commonArgs, "--proxy-refresh-interval", "10"),
expectedMsg: fmt.Sprintf(deprecatedWarningMessage, "proxy-refresh-interval"),
},
{
name: "proxy-dial-timeout",
args: append(commonArgs, "--proxy-dial-timeout", "10"),
expectedMsg: fmt.Sprintf(deprecatedWarningMessage, "proxy-dial-timeout"),
},
{
name: "proxy-write-timeout",
args: append(commonArgs, "--proxy-write-timeout", "10"),
expectedMsg: fmt.Sprintf(deprecatedWarningMessage, "proxy-write-timeout"),
},
{
name: "proxy-read-timeout",
args: append(commonArgs, "--proxy-read-timeout", "10"),
expectedMsg: fmt.Sprintf(deprecatedWarningMessage, "proxy-read-timeout"),
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
proc, err := e2e.SpawnCmd(
tc.args, nil,
)
require.NoError(t, err)
require.NoError(t, e2e.WaitReadyExpectProc(proc, []string{tc.expectedMsg}))
require.NoError(t, proc.Stop())
})
}
}

0 comments on commit 28a19f7

Please sign in to comment.