Support old recursor config for backwards compatibility

This commit is contained in:
Armon Dadgar 2014-11-03 11:28:21 -08:00
parent 2c16fec0cc
commit 982b177e69
4 changed files with 19 additions and 2 deletions

View File

@ -97,6 +97,11 @@ type Config struct {
// DataDir is the directory to store our state in
DataDir string `mapstructure:"data_dir"`
// DNSRecursors can be set to allow the DNS servers to recursively
// resolve non-consul domains. It is deprecated, and merges into the
// recursors array.
DNSRecursor string `mapstructure:"recursor"`
// DNSRecursors can be set to allow the DNS servers to recursively
// resolve non-consul domains
DNSRecursors []string `mapstructure:"recursors"`
@ -500,6 +505,11 @@ func DecodeConfig(r io.Reader) (*Config, error) {
result.RetryInterval = dur
}
// Merge the single recursor
if result.DNSRecursor != "" {
result.DNSRecursors = append(result.DNSRecursors, result.DNSRecursor)
}
return &result, nil
}

View File

@ -109,7 +109,7 @@ func TestDecodeConfig(t *testing.T) {
}
// DNS setup
input = `{"ports": {"dns": 8500}, "recursor": ["8.8.8.8","8.8.4.4"], "domain": "foobar"}`
input = `{"ports": {"dns": 8500}, "recursors": ["8.8.8.8","8.8.4.4"], "recursor":"127.0.0.1", "domain": "foobar"}`
config, err = DecodeConfig(bytes.NewReader([]byte(input)))
if err != nil {
t.Fatalf("err: %s", err)
@ -119,7 +119,7 @@ func TestDecodeConfig(t *testing.T) {
t.Fatalf("bad: %#v", config)
}
if len(config.DNSRecursors) != 2 {
if len(config.DNSRecursors) != 3 {
t.Fatalf("bad: %#v", config)
}
if config.DNSRecursors[0] != "8.8.8.8" {
@ -128,6 +128,9 @@ func TestDecodeConfig(t *testing.T) {
if config.DNSRecursors[1] != "8.8.4.4" {
t.Fatalf("bad: %#v", config)
}
if config.DNSRecursors[2] != "127.0.0.1" {
t.Fatalf("bad: %#v", config)
}
if config.Domain != "foobar" {
t.Fatalf("bad: %#v", config)

View File

@ -333,6 +333,7 @@ It returns a JSON body like this:
"Server": true,
"Datacenter": "dc1",
"DataDir": "/tmp/consul",
"DNSRecursor": "",
"DNSRecursors": [],
"Domain": "consul.",
"LogLevel": "INFO",

View File

@ -321,6 +321,9 @@ definitions support being updated during a reload.
* `protocol` - Equivalent to the `-protocol` command-line flag.
* `recursor` - Provides a single recursor address. This has been deprecated, and
the value is appended to the `recursors` list for backwards compatibility.
* `recursors` - This flag provides addresses of upstream DNS servers that are used to
recursively resolve queries if they are not inside the service domain for consul. For example,
a node can use Consul directly as a DNS server, and if the record is outside of the "consul." domain,