Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/flags: fatal on conflicting environment variable #9382

Merged
merged 1 commit into from
Mar 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions pkg/flags/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 0 additions & 7 deletions pkg/flags/flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down