diff --git a/changelog/9109.txt b/changelog/9109.txt new file mode 100644 index 0000000000000..c85db60b0fd53 --- /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 df69387553946..c478906a7928a 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 db6364c83e527..8ba8d260d2213 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 e40f6c8368a6e..3bbd122c491da 100644 --- a/command/server/config_test_helpers.go +++ b/command/server/config_test_helpers.go @@ -486,7 +486,7 @@ func testUnknownFieldValidation(t *testing.T) { for _, er1 := range errors { found := false if strings.Contains(er1.String(), "sentinel") { - //This happens on OSS, and is fine + // This happens on OSS, and is fine continue } for _, ex := range expected { @@ -828,6 +828,43 @@ listener "tcp" { } } +func testParseSockaddrTemplate(t *testing.T) { + config, err := ParseConfig(` +api_addr = <