diff --git a/go/cmd/vtgate/vtgate.go b/go/cmd/vtgate/vtgate.go index 989875499dc..2a3aa9445d3 100644 --- a/go/cmd/vtgate/vtgate.go +++ b/go/cmd/vtgate/vtgate.go @@ -86,6 +86,8 @@ func main() { vtg := vtgate.Init(context.Background(), healthCheck, resilientServer, *cell, *retryCount, tabletTypes) servenv.OnRun(func() { + // Flags are parsed now. Parse the template using the actual flag value and overwrite the current template. + discovery.ParseTabletURLTemplateFromFlag() addStatusParts(vtg) }) servenv.RunDefault() diff --git a/go/vt/discovery/healthcheck.go b/go/vt/discovery/healthcheck.go index c3b54815746..7ab456d0939 100644 --- a/go/vt/discovery/healthcheck.go +++ b/go/vt/discovery/healthcheck.go @@ -120,12 +120,12 @@ const ( ) func init() { - loadTabletURLTemplate() + // Flags are not parsed at this point and the default value of the flag (just the hostname) will be used. + ParseTabletURLTemplateFromFlag() } -// loadTabletURLTemplate loads or reloads the URL template. -// Should only be used independently for testing. -func loadTabletURLTemplate() { +// ParseTabletURLTemplateFromFlag loads or reloads the URL template. +func ParseTabletURLTemplateFromFlag() { tabletURLTemplate = template.New("") _, err := tabletURLTemplate.Parse(*tabletURLTemplateString) if err != nil { diff --git a/go/vt/discovery/healthcheck_test.go b/go/vt/discovery/healthcheck_test.go index 1e6086da33f..a301bb70ee3 100644 --- a/go/vt/discovery/healthcheck_test.go +++ b/go/vt/discovery/healthcheck_test.go @@ -574,7 +574,7 @@ func TestTemplate(t *testing.T) { func TestDebugURLFormatting(t *testing.T) { flag.Set("tablet_url_template", "https://{{.GetHostNameLevel 0}}.bastion.{{.Tablet.Alias.Cell}}.corp") - loadTabletURLTemplate() + ParseTabletURLTemplateFromFlag() tablet := topo.NewTablet(0, "cell", "host.dc.domain") ts := []*TabletStats{