fix(etcd): Transform DISCOVERY_URL to DISCOVERY
This commit is contained in:
parent
818bcd4b59
commit
01542ecec7
@ -87,7 +87,7 @@ For example, the following cloud-config document...
|
||||
coreos:
|
||||
etcd:
|
||||
name: node001
|
||||
discovery-url: https://discovery.etcd.io/3445fa65423d8b04df07f59fb40218f8
|
||||
discovery: https://discovery.etcd.io/3445fa65423d8b04df07f59fb40218f8
|
||||
bind-addr: $public_ipv4:4001
|
||||
peer-bind-addr: $private_ipv4:7001
|
||||
```
|
||||
@ -97,7 +97,7 @@ coreos:
|
||||
```
|
||||
[Service]
|
||||
Environment="ETCD_NAME=node001""
|
||||
Environment="ETCD_DISCOVERY_URL=https://discovery.etcd.io/3445fa65423d8b04df07f59fb40218f8"
|
||||
Environment="ETCD_DISCOVERY=https://discovery.etcd.io/3445fa65423d8b04df07f59fb40218f8"
|
||||
Environment="ETCD_BIND_ADDR=203.0.113.29:4001"
|
||||
Environment="ETCD_PEER_BIND_ADDR=192.0.2.13:7001"
|
||||
```
|
||||
@ -136,7 +136,7 @@ echo 'Hello, world!'
|
||||
|
||||
coreos:
|
||||
etcd:
|
||||
discovery_url: https://discovery.etcd.io/827c73219eeb2fa5530027c37bf18877
|
||||
discovery: https://discovery.etcd.io/827c73219eeb2fa5530027c37bf18877
|
||||
fleet:
|
||||
autostart: yes
|
||||
ssh_authorized_keys:
|
||||
|
@ -35,7 +35,7 @@ func TestCloudConfig(t *testing.T) {
|
||||
contents := []byte(`
|
||||
coreos:
|
||||
etcd:
|
||||
discovery_url: "https://discovery.etcd.io/827c73219eeb2fa5530027c37bf18877"
|
||||
discovery: "https://discovery.etcd.io/827c73219eeb2fa5530027c37bf18877"
|
||||
fleet:
|
||||
autostart: Yes
|
||||
units:
|
||||
|
@ -12,16 +12,32 @@ import (
|
||||
|
||||
type EtcdEnvironment map[string]string
|
||||
|
||||
func (ec EtcdEnvironment) normalized() map[string]string {
|
||||
out := make(map[string]string, len(ec))
|
||||
for key, val := range ec {
|
||||
key = strings.ToUpper(key)
|
||||
key = strings.Replace(key, "-", "_", -1)
|
||||
out[key] = val
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (ec EtcdEnvironment) String() (out string) {
|
||||
norm := ec.normalized()
|
||||
|
||||
if val, ok := norm["DISCOVERY_URL"]; ok {
|
||||
delete(norm, "DISCOVERY_URL")
|
||||
if _, ok := norm["DISCOVERY"]; !ok {
|
||||
norm["DISCOVERY"] = val
|
||||
}
|
||||
}
|
||||
|
||||
public := os.Getenv("COREOS_PUBLIC_IPV4")
|
||||
private := os.Getenv("COREOS_PRIVATE_IPV4")
|
||||
|
||||
out += "[Service]\n"
|
||||
|
||||
for key, val := range ec {
|
||||
key = strings.ToUpper(key)
|
||||
key = strings.Replace(key, "-", "_", -1)
|
||||
|
||||
for key, val := range norm {
|
||||
if public != "" {
|
||||
val = strings.Replace(val, "$public_ipv4", public, -1)
|
||||
}
|
||||
|
@ -10,13 +10,46 @@ import (
|
||||
)
|
||||
|
||||
func TestEtcdEnvironment(t *testing.T) {
|
||||
cfg := make(EtcdEnvironment, 0)
|
||||
cfg["discovery"] = "http://disco.example.com/foobar"
|
||||
cfg["peer-bind-addr"] = "127.0.0.1:7002"
|
||||
|
||||
env := cfg.String()
|
||||
expect := `[Service]
|
||||
Environment="ETCD_DISCOVERY=http://disco.example.com/foobar"
|
||||
Environment="ETCD_PEER_BIND_ADDR=127.0.0.1:7002"
|
||||
`
|
||||
|
||||
if env != expect {
|
||||
t.Errorf("Generated environment:\n%s\nExpected environment:\n%s", env, expect)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEtcdEnvironmentDiscoveryURLTranslated(t *testing.T) {
|
||||
cfg := make(EtcdEnvironment, 0)
|
||||
cfg["discovery_url"] = "http://disco.example.com/foobar"
|
||||
cfg["peer-bind-addr"] = "127.0.0.1:7002"
|
||||
|
||||
env := cfg.String()
|
||||
expect := `[Service]
|
||||
Environment="ETCD_DISCOVERY_URL=http://disco.example.com/foobar"
|
||||
Environment="ETCD_DISCOVERY=http://disco.example.com/foobar"
|
||||
Environment="ETCD_PEER_BIND_ADDR=127.0.0.1:7002"
|
||||
`
|
||||
|
||||
if env != expect {
|
||||
t.Errorf("Generated environment:\n%s\nExpected environment:\n%s", env, expect)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEtcdEnvironmentDiscoveryOverridesDiscoveryURL(t *testing.T) {
|
||||
cfg := make(EtcdEnvironment, 0)
|
||||
cfg["discovery_url"] = "ping"
|
||||
cfg["discovery"] = "pong"
|
||||
cfg["peer-bind-addr"] = "127.0.0.1:7002"
|
||||
|
||||
env := cfg.String()
|
||||
expect := `[Service]
|
||||
Environment="ETCD_DISCOVERY=pong"
|
||||
Environment="ETCD_PEER_BIND_ADDR=127.0.0.1:7002"
|
||||
`
|
||||
|
||||
@ -47,7 +80,7 @@ Environment="ETCD_PEER_BIND_ADDR=192.0.2.13:7001"
|
||||
func TestEtcdEnvironmentWrittenToDisk(t *testing.T) {
|
||||
ec := EtcdEnvironment{
|
||||
"name": "node001",
|
||||
"discovery_url": "http://disco.example.com/foobar",
|
||||
"discovery": "http://disco.example.com/foobar",
|
||||
"peer-bind-addr": "127.0.0.1:7002",
|
||||
}
|
||||
dir, err := ioutil.TempDir(os.TempDir(), "coreos-cloudinit-")
|
||||
@ -78,7 +111,7 @@ func TestEtcdEnvironmentWrittenToDisk(t *testing.T) {
|
||||
|
||||
expect := `[Service]
|
||||
Environment="ETCD_NAME=node001"
|
||||
Environment="ETCD_DISCOVERY_URL=http://disco.example.com/foobar"
|
||||
Environment="ETCD_DISCOVERY=http://disco.example.com/foobar"
|
||||
Environment="ETCD_PEER_BIND_ADDR=127.0.0.1:7002"
|
||||
`
|
||||
if string(contents) != expect {
|
||||
|
Loading…
Reference in New Issue
Block a user