From 2eaf9579393479541001f3a19639808722462110 Mon Sep 17 00:00:00 2001 From: nexustar Date: Wed, 8 Nov 2023 11:00:42 +0800 Subject: [PATCH] cluster/dm: add gloabl listen_host (#2303) --- components/dm/spec/logic.go | 2 ++ embed/examples/cluster/minimal.yaml | 2 ++ embed/examples/cluster/multi-dc.yaml | 2 ++ embed/examples/cluster/topology.example.yaml | 2 ++ pkg/cluster/spec/alertmanager.go | 2 +- pkg/cluster/spec/cdc.go | 1 + pkg/cluster/spec/dashboard.go | 1 + pkg/cluster/spec/drainer.go | 1 + pkg/cluster/spec/grafana.go | 1 + pkg/cluster/spec/monitoring.go | 1 + pkg/cluster/spec/pd.go | 2 +- pkg/cluster/spec/pump.go | 1 + pkg/cluster/spec/spec.go | 1 + pkg/cluster/spec/tidb.go | 2 +- pkg/cluster/spec/tiflash.go | 1 + pkg/cluster/spec/tikv.go | 2 +- pkg/cluster/spec/tikv_cdc.go | 1 + pkg/cluster/spec/tiproxy.go | 1 + 18 files changed, 22 insertions(+), 4 deletions(-) diff --git a/components/dm/spec/logic.go b/components/dm/spec/logic.go index 8078aeda54..3f8c48c20a 100644 --- a/components/dm/spec/logic.go +++ b/components/dm/spec/logic.go @@ -90,6 +90,7 @@ func (c *DMMasterComponent) Instances() []Instance { Name: c.Name(), Host: s.Host, ManageHost: s.ManageHost, + ListenHost: c.Topology.BaseTopo().GlobalOptions.ListenHost, Port: s.Port, SSHP: s.SSHPort, Source: s.GetSource(), @@ -304,6 +305,7 @@ func (c *DMWorkerComponent) Instances() []Instance { Name: c.Name(), Host: s.Host, ManageHost: s.ManageHost, + ListenHost: c.Topology.BaseTopo().GlobalOptions.ListenHost, Port: s.Port, SSHP: s.SSHPort, Source: s.GetSource(), diff --git a/embed/examples/cluster/minimal.yaml b/embed/examples/cluster/minimal.yaml index 91c7789b9c..7d469a3758 100644 --- a/embed/examples/cluster/minimal.yaml +++ b/embed/examples/cluster/minimal.yaml @@ -11,6 +11,8 @@ global: deploy_dir: "/tidb-deploy" # # TiDB Cluster data storage directory data_dir: "/tidb-data" + # # default listen_host for all components + listen_host: 0.0.0.0 # # Supported values: "amd64", "arm64" (default: "amd64") arch: "amd64" # # Resource Control is used to limit the resource of an instance. diff --git a/embed/examples/cluster/multi-dc.yaml b/embed/examples/cluster/multi-dc.yaml index 666936f7bc..3fcb2bb7af 100644 --- a/embed/examples/cluster/multi-dc.yaml +++ b/embed/examples/cluster/multi-dc.yaml @@ -11,6 +11,8 @@ global: deploy_dir: "/tidb-deploy" # # TiDB Cluster data storage directory data_dir: "/tidb-data" + # # default listen_host for all components + listen_host: 0.0.0.0 # # Supported values: "amd64", "arm64" (default: "amd64") arch: "amd64" # # Resource Control is used to limit the resource of an instance. diff --git a/embed/examples/cluster/topology.example.yaml b/embed/examples/cluster/topology.example.yaml index d1b09a0daa..72998cc847 100644 --- a/embed/examples/cluster/topology.example.yaml +++ b/embed/examples/cluster/topology.example.yaml @@ -11,6 +11,8 @@ global: deploy_dir: "/tidb-deploy" # # TiDB Cluster data storage directory data_dir: "/tidb-data" + # # default listen_host for all components + listen_host: 0.0.0.0 # # Supported values: "amd64", "arm64" (default: "amd64") arch: "amd64" # # Resource Control is used to limit the resource of an instance. diff --git a/pkg/cluster/spec/alertmanager.go b/pkg/cluster/spec/alertmanager.go index a6ba3a617b..b71392b858 100644 --- a/pkg/cluster/spec/alertmanager.go +++ b/pkg/cluster/spec/alertmanager.go @@ -127,7 +127,7 @@ func (c *AlertManagerComponent) Instances() []Instance { Name: c.Name(), Host: s.Host, ManageHost: s.ManageHost, - ListenHost: s.ListenHost, + ListenHost: utils.Ternary(s.ListenHost != "", s.ListenHost, c.Topology.BaseTopo().GlobalOptions.ListenHost).(string), Port: s.WebPort, SSHP: s.SSHPort, NumaNode: s.NumaNode, diff --git a/pkg/cluster/spec/cdc.go b/pkg/cluster/spec/cdc.go index 341627833c..23a03b1c12 100644 --- a/pkg/cluster/spec/cdc.go +++ b/pkg/cluster/spec/cdc.go @@ -137,6 +137,7 @@ func (c *CDCComponent) Instances() []Instance { Name: c.Name(), Host: s.Host, ManageHost: s.ManageHost, + ListenHost: c.Topology.BaseTopo().GlobalOptions.ListenHost, Port: s.Port, SSHP: s.SSHPort, Source: s.GetSource(), diff --git a/pkg/cluster/spec/dashboard.go b/pkg/cluster/spec/dashboard.go index 26c429e4b5..f6493ce3d5 100644 --- a/pkg/cluster/spec/dashboard.go +++ b/pkg/cluster/spec/dashboard.go @@ -139,6 +139,7 @@ func (c *DashboardComponent) Instances() []Instance { Name: c.Name(), Host: s.Host, ManageHost: s.ManageHost, + ListenHost: c.Topology.BaseTopo().GlobalOptions.ListenHost, Port: s.Port, SSHP: s.SSHPort, Source: s.Source, diff --git a/pkg/cluster/spec/drainer.go b/pkg/cluster/spec/drainer.go index 90d75dcba4..402b6bbb49 100644 --- a/pkg/cluster/spec/drainer.go +++ b/pkg/cluster/spec/drainer.go @@ -158,6 +158,7 @@ func (c *DrainerComponent) Instances() []Instance { Name: c.Name(), Host: s.Host, ManageHost: s.ManageHost, + ListenHost: c.Topology.BaseTopo().GlobalOptions.ListenHost, Port: s.Port, SSHP: s.SSHPort, Source: s.GetSource(), diff --git a/pkg/cluster/spec/grafana.go b/pkg/cluster/spec/grafana.go index 29d9171fa0..e18a543448 100644 --- a/pkg/cluster/spec/grafana.go +++ b/pkg/cluster/spec/grafana.go @@ -135,6 +135,7 @@ func (c *GrafanaComponent) Instances() []Instance { Name: c.Name(), Host: s.Host, ManageHost: s.ManageHost, + ListenHost: c.Topology.BaseTopo().GlobalOptions.ListenHost, Port: s.Port, SSHP: s.SSHPort, NumaNode: "", diff --git a/pkg/cluster/spec/monitoring.go b/pkg/cluster/spec/monitoring.go index 1039b96fd1..07aafaf5c4 100644 --- a/pkg/cluster/spec/monitoring.go +++ b/pkg/cluster/spec/monitoring.go @@ -151,6 +151,7 @@ func (c *MonitorComponent) Instances() []Instance { Name: c.Name(), Host: s.Host, ManageHost: s.ManageHost, + ListenHost: c.Topology.BaseTopo().GlobalOptions.ListenHost, Port: s.Port, SSHP: s.SSHPort, NumaNode: s.NumaNode, diff --git a/pkg/cluster/spec/pd.go b/pkg/cluster/spec/pd.go index 4671f3794d..f505db7b18 100644 --- a/pkg/cluster/spec/pd.go +++ b/pkg/cluster/spec/pd.go @@ -185,7 +185,7 @@ func (c *PDComponent) Instances() []Instance { Name: c.Name(), Host: s.Host, ManageHost: s.ManageHost, - ListenHost: s.ListenHost, + ListenHost: utils.Ternary(s.ListenHost != "", s.ListenHost, c.Topology.BaseTopo().GlobalOptions.ListenHost).(string), Port: s.ClientPort, SSHP: s.SSHPort, Source: s.GetSource(), diff --git a/pkg/cluster/spec/pump.go b/pkg/cluster/spec/pump.go index 42ac0a1f42..00dc89ddfd 100644 --- a/pkg/cluster/spec/pump.go +++ b/pkg/cluster/spec/pump.go @@ -157,6 +157,7 @@ func (c *PumpComponent) Instances() []Instance { Name: c.Name(), Host: s.Host, ManageHost: s.ManageHost, + ListenHost: c.Topology.BaseTopo().GlobalOptions.ListenHost, Port: s.Port, SSHP: s.SSHPort, Source: s.GetSource(), diff --git a/pkg/cluster/spec/spec.go b/pkg/cluster/spec/spec.go index 37ba046f29..58a536b52f 100644 --- a/pkg/cluster/spec/spec.go +++ b/pkg/cluster/spec/spec.go @@ -82,6 +82,7 @@ type ( SSHPort int `yaml:"ssh_port,omitempty" default:"22" validate:"ssh_port:editable"` SSHType executor.SSHType `yaml:"ssh_type,omitempty" default:"builtin"` TLSEnabled bool `yaml:"enable_tls,omitempty"` + ListenHost string `yaml:"listen_host,omitempty" validate:"listen_host:editable"` DeployDir string `yaml:"deploy_dir,omitempty" default:"deploy"` DataDir string `yaml:"data_dir,omitempty" default:"data"` LogDir string `yaml:"log_dir,omitempty"` diff --git a/pkg/cluster/spec/tidb.go b/pkg/cluster/spec/tidb.go index 6e5ef550a5..3d793f9a76 100644 --- a/pkg/cluster/spec/tidb.go +++ b/pkg/cluster/spec/tidb.go @@ -134,7 +134,7 @@ func (c *TiDBComponent) Instances() []Instance { Name: c.Name(), Host: s.Host, ManageHost: s.ManageHost, - ListenHost: s.ListenHost, + ListenHost: utils.Ternary(s.ListenHost != "", s.ListenHost, c.Topology.BaseTopo().GlobalOptions.ListenHost).(string), Port: s.Port, SSHP: s.SSHPort, Source: s.Source, diff --git a/pkg/cluster/spec/tiflash.go b/pkg/cluster/spec/tiflash.go index 7dafc28ad4..45ed2e8dd0 100644 --- a/pkg/cluster/spec/tiflash.go +++ b/pkg/cluster/spec/tiflash.go @@ -305,6 +305,7 @@ func (c *TiFlashComponent) Instances() []Instance { Name: c.Name(), Host: s.Host, ManageHost: s.ManageHost, + ListenHost: c.Topology.BaseTopo().GlobalOptions.ListenHost, Port: s.GetMainPort(), SSHP: s.SSHPort, Source: s.GetSource(), diff --git a/pkg/cluster/spec/tikv.go b/pkg/cluster/spec/tikv.go index 089d1cb9bf..48f24dcf38 100644 --- a/pkg/cluster/spec/tikv.go +++ b/pkg/cluster/spec/tikv.go @@ -209,7 +209,7 @@ func (c *TiKVComponent) Instances() []Instance { Name: c.Name(), Host: s.Host, ManageHost: s.ManageHost, - ListenHost: s.ListenHost, + ListenHost: utils.Ternary(s.ListenHost != "", s.ListenHost, c.Topology.BaseTopo().GlobalOptions.ListenHost).(string), Port: s.Port, SSHP: s.SSHPort, Source: s.Source, diff --git a/pkg/cluster/spec/tikv_cdc.go b/pkg/cluster/spec/tikv_cdc.go index 1247178216..ee9d6c5c5d 100644 --- a/pkg/cluster/spec/tikv_cdc.go +++ b/pkg/cluster/spec/tikv_cdc.go @@ -135,6 +135,7 @@ func (c *TiKVCDCComponent) Instances() []Instance { Name: c.Name(), Host: s.Host, ManageHost: s.ManageHost, + ListenHost: c.Topology.BaseTopo().GlobalOptions.ListenHost, Port: s.Port, SSHP: s.SSHPort, Source: s.GetSource(), diff --git a/pkg/cluster/spec/tiproxy.go b/pkg/cluster/spec/tiproxy.go index 9cfdc56104..9d65ffa886 100644 --- a/pkg/cluster/spec/tiproxy.go +++ b/pkg/cluster/spec/tiproxy.go @@ -154,6 +154,7 @@ func (c *TiProxyComponent) Instances() []Instance { Name: c.Name(), Host: s.Host, ManageHost: s.ManageHost, + ListenHost: c.Topology.BaseTopo().GlobalOptions.ListenHost, Port: s.Port, SSHP: s.SSHPort, Source: ComponentTiProxy,