From 748ab8c3989886c2145eea06703d2981a224024f Mon Sep 17 00:00:00 2001 From: Gyuho Lee Date: Fri, 2 Mar 2018 10:26:49 -0800 Subject: [PATCH] pkg/flags: fatal on conflicting environment variable Signed-off-by: Gyuho Lee --- pkg/flags/flag.go | 4 +--- pkg/flags/flag_test.go | 7 ------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/pkg/flags/flag.go b/pkg/flags/flag.go index 69c46411854..3a8f050af8c 100644 --- a/pkg/flags/flag.go +++ b/pkg/flags/flag.go @@ -119,9 +119,7 @@ func verifyEnv(prefix string, usedEnvKey, alreadySet map[string]bool) { continue } if alreadySet[kv[0]] { - // TODO: exit with error in v3.4 - plog.Warningf("recognized environment variable %s, but unused: shadowed by corresponding flag", kv[0]) - continue + plog.Fatalf("conflicting environment variable %q is shadowed by corresponding command-line flag (either unset environment variable or disable flag)", kv[0]) } if strings.HasPrefix(env, prefix+"_") { plog.Warningf("unrecognized environment variable %s", env) diff --git a/pkg/flags/flag_test.go b/pkg/flags/flag_test.go index db157c9bef4..07914e68599 100644 --- a/pkg/flags/flag_test.go +++ b/pkg/flags/flag_test.go @@ -34,17 +34,11 @@ func TestSetFlagsFromEnv(t *testing.T) { if err := fs.Set("b", "bar"); err != nil { t.Fatal(err) } - // command-line flags take precedence over env vars - os.Setenv("ETCD_C", "woof") - if err := fs.Set("c", "quack"); err != nil { - t.Fatal(err) - } // first verify that flags are as expected before reading the env for f, want := range map[string]string{ "a": "", "b": "bar", - "c": "quack", } { if got := fs.Lookup(f).Value.String(); got != want { t.Fatalf("flag %q=%q, want %q", f, got, want) @@ -59,7 +53,6 @@ func TestSetFlagsFromEnv(t *testing.T) { for f, want := range map[string]string{ "a": "foo", "b": "bar", - "c": "quack", } { if got := fs.Lookup(f).Value.String(); got != want { t.Errorf("flag %q=%q, want %q", f, got, want)