diff --git a/pkg/cmd/server/config.go b/pkg/cmd/server/config.go index 12bb564d7494..30655b207efc 100644 --- a/pkg/cmd/server/config.go +++ b/pkg/cmd/server/config.go @@ -144,6 +144,11 @@ func (cfg Config) GetMasterPublicAddress() (*url.URL, error) { return cfg.GetMasterAddress() } +func (cfg Config) GetEtcdBindAddress() string { + // Derive the etcd bind address by using the bind address and the default etcd port + return net.JoinHostPort(cfg.BindAddr.Host, strconv.Itoa(cfg.EtcdAddr.DefaultPort)) +} + func (cfg Config) GetEtcdAddress() (*url.URL, error) { if cfg.EtcdAddr.Provided { return cfg.EtcdAddr.URL, nil diff --git a/pkg/cmd/server/config_test.go b/pkg/cmd/server/config_test.go index 6167f58b3ac3..677bd17185d1 100644 --- a/pkg/cmd/server/config_test.go +++ b/pkg/cmd/server/config_test.go @@ -166,6 +166,28 @@ func TestEtcdAddressExplicit(t *testing.T) { } } +func TestEtcdBindAddressDefault(t *testing.T) { + expected := "0.0.0.0:4001" + + cfg := NewDefaultConfig() + actual := cfg.GetEtcdBindAddress() + if expected != actual { + t.Errorf("expected %v, got %v", expected, actual) + } +} + +func TestEtcdBindAddressDefaultToBind(t *testing.T) { + expected := "1.2.3.4:4001" + + cfg := NewDefaultConfig() + cfg.BindAddr.Set("https://1.2.3.4:8080") + + actual := cfg.GetEtcdBindAddress() + if expected != actual { + t.Errorf("expected %v, got %v", expected, actual) + } +} + func TestMasterAddressDefaultingToBindValues(t *testing.T) { defaultIP, err := util.DefaultLocalIP4() if err != nil { diff --git a/pkg/cmd/server/start.go b/pkg/cmd/server/start.go index 6b64298f8fa0..a26cfbbf0969 100644 --- a/pkg/cmd/server/start.go +++ b/pkg/cmd/server/start.go @@ -196,8 +196,8 @@ func (cfg Config) RunEtcd() error { } etcdConfig := &etcd.Config{ - BindAddr: cfg.BindAddr.Host, - PeerBindAddr: cfg.BindAddr.Host, + BindAddr: cfg.GetEtcdBindAddress(), + PeerBindAddr: cfg.GetEtcdBindAddress(), MasterAddr: etcdAddr.Host, EtcdDir: cfg.EtcdDir, }