Skip to content

Commit

Permalink
etcdmain: fix the check in fallback-to-proxy case
Browse files Browse the repository at this point in the history
advertise-client-urls has to be set if listen-client-urls is set when
fallbacking to proxy, which breaks the behavior. Loosen the check to fix
it.
  • Loading branch information
yichengq committed Jun 25, 2015
1 parent 9fa4002 commit b12a52b
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
5 changes: 4 additions & 1 deletion etcdmain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,10 @@ func (cfg *config) Parse(arguments []string) error {
}

// when etcd runs in member mode user needs to set -advertise-client-urls if -listen-client-urls is set.
if cfg.proxy.String() != proxyFlagOn {
// TODO(yichengq): check this for joining through discovery service case
mayFallbackToProxy := flags.IsSet(cfg.FlagSet, "discovery") && cfg.fallback.String() == fallbackFlagProxy
mayBeProxy := cfg.proxy.String() != proxyFlagOff || mayFallbackToProxy
if !mayBeProxy {
if flags.IsSet(cfg.FlagSet, "listen-client-urls") && !flags.IsSet(cfg.FlagSet, "advertise-client-urls") {
return errUnsetAdvertiseClientURLsFlag
}
Expand Down
65 changes: 65 additions & 0 deletions etcdmain/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,71 @@ func TestConfigParsingConflictClusteringFlags(t *testing.T) {
}
}

func TestConfigParsingMissedAdvertiseClientURLsFlag(t *testing.T) {
tests := []struct {
args []string
werr error
}{
{
[]string{
"-initial-cluster=infra1=http://127.0.0.1:2380",
"-listen-client-urls=http://127.0.0.1:2379",
},
errUnsetAdvertiseClientURLsFlag,
},
{
[]string{
"-discovery-srv=example.com",
"-listen-client-urls=http://127.0.0.1:2379",
},
errUnsetAdvertiseClientURLsFlag,
},
{
[]string{
"-discovery=http://example.com/abc",
"-discovery-fallback=exit",
"-listen-client-urls=http://127.0.0.1:2379",
},
errUnsetAdvertiseClientURLsFlag,
},
{
[]string{
"-listen-client-urls=http://127.0.0.1:2379",
},
errUnsetAdvertiseClientURLsFlag,
},
{
[]string{
"-discovery=http://example.com/abc",
"-listen-client-urls=http://127.0.0.1:2379",
},
nil,
},
{
[]string{
"-proxy=on",
"-listen-client-urls=http://127.0.0.1:2379",
},
nil,
},
{
[]string{
"-proxy=readonly",
"-listen-client-urls=http://127.0.0.1:2379",
},
nil,
},
}

for i, tt := range tests {
cfg := NewConfig()
err := cfg.Parse(tt.args)
if err != tt.werr {
t.Errorf("%d: err = %v, want %v", i, err, tt.werr)
}
}
}

func TestConfigIsNewCluster(t *testing.T) {
tests := []struct {
state string
Expand Down

0 comments on commit b12a52b

Please sign in to comment.