From d66fd98d4a8f43b290d19ba7e46cf2d1f669db82 Mon Sep 17 00:00:00 2001 From: Nick Cabatoff Date: Thu, 21 Oct 2021 10:10:48 -0400 Subject: [PATCH] Add support for go-sockaddr templated addresses in config. (#9109) --- changelog/9109.txt | 3 ++ command/server/config.go | 11 ++++++ command/server/config_test.go | 4 ++ command/server/config_test_helpers.go | 37 +++++++++++++++++++ internalshared/configutil/listener.go | 30 +++++++++++++++ .../docs/configuration/listener/tcp.mdx | 8 +++- 6 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 changelog/9109.txt diff --git a/changelog/9109.txt b/changelog/9109.txt new file mode 100644 index 000000000..c85db60b0 --- /dev/null +++ b/changelog/9109.txt @@ -0,0 +1,3 @@ +```release-note:improvement +core: Add support for go-sockaddr templated addresses in config. +``` diff --git a/command/server/config.go b/command/server/config.go index df6938755..c478906a7 100644 --- a/command/server/config.go +++ b/command/server/config.go @@ -392,6 +392,17 @@ func ParseConfig(d, source string) (*Config, error) { return nil, err } + if rendered, err := configutil.ParseSingleIPTemplate(result.APIAddr); err != nil { + return nil, err + } else { + result.APIAddr = rendered + } + if rendered, err := configutil.ParseSingleIPTemplate(result.ClusterAddr); err != nil { + return nil, err + } else { + result.ClusterAddr = rendered + } + sharedConfig, err := configutil.ParseConfig(d) if err != nil { return nil, err diff --git a/command/server/config_test.go b/command/server/config_test.go index db6364c83..8ba8d260d 100644 --- a/command/server/config_test.go +++ b/command/server/config_test.go @@ -36,6 +36,10 @@ func TestParseListeners(t *testing.T) { testParseListeners(t) } +func TestParseSockaddrTemplate(t *testing.T) { + testParseSockaddrTemplate(t) +} + func TestConfigRaftRetryJoin(t *testing.T) { testConfigRaftRetryJoin(t) } diff --git a/command/server/config_test_helpers.go b/command/server/config_test_helpers.go index 8936a0244..d6c728340 100644 --- a/command/server/config_test_helpers.go +++ b/command/server/config_test_helpers.go @@ -843,6 +843,43 @@ listener "tcp" { } } +func testParseSockaddrTemplate(t *testing.T) { + config, err := ParseConfig(` +api_addr = <