From 78b1b5b9c2b9fd2b01057854e480843edfa86193 Mon Sep 17 00:00:00 2001 From: nexustar Date: Thu, 24 Mar 2022 15:26:34 +0800 Subject: [PATCH] playground: fix cannot bind 0.0.0.0 (#1811) --- components/playground/instance/tiflash.go | 2 +- components/playground/instance/tiflash_config.go | 3 ++- components/playground/instance/tiflash_proxy_config.go | 3 ++- components/playground/playground.go | 3 --- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/components/playground/instance/tiflash.go b/components/playground/instance/tiflash.go index 0f7ed0166d..0bc901ffab 100644 --- a/components/playground/instance/tiflash.go +++ b/components/playground/instance/tiflash.go @@ -83,7 +83,7 @@ type replicateEnablePlacementRulesConfig struct { // Addr return the address of tiflash func (inst *TiFlashInstance) Addr() string { - return fmt.Sprintf("%s:%d", inst.Host, inst.ServicePort) + return fmt.Sprintf("%s:%d", AdvertiseHost(inst.Host), inst.ServicePort) } // StatusAddrs implements Instance interface. diff --git a/components/playground/instance/tiflash_config.go b/components/playground/instance/tiflash_config.go index 368feaed91..02a4b92ec4 100644 --- a/components/playground/instance/tiflash_config.go +++ b/components/playground/instance/tiflash_config.go @@ -97,11 +97,12 @@ quota = "default" ip = "::/0" ` -func writeTiFlashConfig(w io.Writer, version utils.Version, tcpPort, httpPort, servicePort, metricsPort int, ip, deployDir, clusterManagerPath string, tidbStatusAddrs, endpoints []string) error { +func writeTiFlashConfig(w io.Writer, version utils.Version, tcpPort, httpPort, servicePort, metricsPort int, host, deployDir, clusterManagerPath string, tidbStatusAddrs, endpoints []string) error { pdAddrs := strings.Join(endpoints, ",") dataDir := fmt.Sprintf("%s/data", deployDir) tmpDir := fmt.Sprintf("%s/tmp", deployDir) logDir := fmt.Sprintf("%s/log", deployDir) + ip := AdvertiseHost(host) var conf string if semver.Compare(version.String(), "v5.4.0") >= 0 || version.IsNightly() { conf = fmt.Sprintf(tiflashConfig, pdAddrs, httpPort, tcpPort, diff --git a/components/playground/instance/tiflash_proxy_config.go b/components/playground/instance/tiflash_proxy_config.go index 2d9f25629a..29bef476ad 100644 --- a/components/playground/instance/tiflash_proxy_config.go +++ b/components/playground/instance/tiflash_proxy_config.go @@ -46,10 +46,11 @@ data-dir = "%[6]s" max-open-files = 256 ` -func writeTiFlashProxyConfig(w io.Writer, version utils.Version, ip, deployDir string, servicePort, proxyPort, proxyStatusPort int) error { +func writeTiFlashProxyConfig(w io.Writer, version utils.Version, host, deployDir string, servicePort, proxyPort, proxyStatusPort int) error { // TODO: support multi-dir dataDir := fmt.Sprintf("%s/flash", deployDir) logDir := fmt.Sprintf("%s/log", deployDir) + ip := AdvertiseHost(host) var statusAddr string if semver.Compare(version.String(), "v4.0.5") >= 0 || version.IsNightly() { statusAddr = fmt.Sprintf(`status-addr = "0.0.0.0:%[2]d" diff --git a/components/playground/playground.go b/components/playground/playground.go index 7a3a67fced..fef1cf65fc 100644 --- a/components/playground/playground.go +++ b/components/playground/playground.go @@ -634,9 +634,6 @@ func (p *Playground) addInstance(componentID string, cfg instance.Config) (ins i host = cfg.Host } - // use the advertised host instead of 0.0.0.0 - host = instance.AdvertiseHost(host) - switch componentID { case spec.ComponentPD: inst := instance.NewPDInstance(cfg.BinPath, dir, host, cfg.ConfigPath, id)