From 9200644946d848911df9784771359037f4b96eb1 Mon Sep 17 00:00:00 2001 From: makocchi Date: Mon, 1 Nov 2021 17:46:52 +0900 Subject: [PATCH] support rendering template when set "--local" option (#1596) --- components/cluster/command/template.go | 66 +++++++++- components/cluster/command/template_test.go | 128 ++++++++++++++++++ components/dm/command/template.go | 78 ++++++++++- components/dm/command/template_test.go | 139 ++++++++++++++++++++ embed/examples/cluster/local.tpl | 65 +++++++++ embed/examples/cluster/local.yaml | 32 ----- embed/examples/dm/local.tpl | 54 ++++++++ 7 files changed, 523 insertions(+), 39 deletions(-) create mode 100644 components/cluster/command/template_test.go create mode 100644 components/dm/command/template_test.go create mode 100644 embed/examples/cluster/local.tpl delete mode 100644 embed/examples/cluster/local.yaml create mode 100644 embed/examples/dm/local.tpl diff --git a/components/cluster/command/template.go b/components/cluster/command/template.go index 707739dcec..c7b9abd9c9 100644 --- a/components/cluster/command/template.go +++ b/components/cluster/command/template.go @@ -14,8 +14,10 @@ package command import ( + "bytes" "fmt" "path" + "text/template" "github.com/pingcap/errors" "github.com/pingcap/tiup/embed" @@ -26,7 +28,24 @@ import ( type TemplateOptions struct { Full bool // print full template MultiDC bool // print template for deploying to multiple data center - Local bool // print local template + Local bool // print and render local template +} + +// LocalTemplate contains the variables for print local template. +type LocalTemplate struct { + GlobalUser string // global.user in yaml template + GlobalGroup string // global.group in yaml template + GlobalSSHPort int // global.ssh_port in yaml template + GlobalDeployDir string // global.deploy_dir in yaml template + GlobalDataDir string // global.data_dir in yaml template + GlobalArch string // global.arch in yaml template + PDServers []string // pd_servers in yaml template + TiDBServers []string // tidb_servers in yaml template + TiKVServers []string // tikv_servers in yaml template + TiFlashServers []string // tiflash_servers in yaml template + MonitoringServers []string // monitoring_servers in yaml template + GrafanaServers []string // grafana_servers in yaml template + AlertManagerServers []string // alertmanager_servers in yaml template } // This is used to identify how many bool type options are set, so that an @@ -43,6 +62,7 @@ func sumBool(b ...bool) int { func newTemplateCmd() *cobra.Command { opt := TemplateOptions{} + localOpt := LocalTemplate{} cmd := &cobra.Command{ Use: "template", @@ -58,7 +78,7 @@ func newTemplateCmd() *cobra.Command { case opt.MultiDC: name = "multi-dc.yaml" case opt.Local: - name = "local.yaml" + name = "local.tpl" } fp := path.Join("examples", "cluster", name) @@ -67,14 +87,52 @@ func newTemplateCmd() *cobra.Command { return err } - fmt.Println(string(tpl)) + if !opt.Local { + // print example yaml and return + fmt.Fprintln(cmd.OutOrStdout(), string(tpl)) + return nil + } + + // redner template + + // validate arch + if localOpt.GlobalArch != "amd64" && localOpt.GlobalArch != "arm64" { + return fmt.Errorf(`supported values are "amd64" or "arm64" in global.arch`) + } + + tmpl, err := template.New(name).Parse(string(tpl)) + if err != nil { + return err + } + + content := bytes.NewBufferString("") + if err := tmpl.Execute(content, &localOpt); err != nil { + return err + } + + fmt.Fprintln(cmd.OutOrStdout(), content.String()) return nil }, } cmd.Flags().BoolVar(&opt.Full, "full", false, "Print the full topology template for TiDB cluster.") cmd.Flags().BoolVar(&opt.MultiDC, "multi-dc", false, "Print template for deploying to multiple data center.") - cmd.Flags().BoolVar(&opt.Local, "local", false, "Print template for deploying a simple cluster locally.") + cmd.Flags().BoolVar(&opt.Local, "local", false, "Print and render template for deploying a simple cluster locally.") + + // template values for rendering + cmd.Flags().StringVar(&localOpt.GlobalUser, "user", "tidb", "The user who runs the tidb cluster.") + cmd.Flags().StringVar(&localOpt.GlobalGroup, "group", "", "group is used to specify the group name the user belong to if it's not the same as user.") + cmd.Flags().IntVar(&localOpt.GlobalSSHPort, "ssh-port", 22, "SSH port of servers in the managed cluster.") + cmd.Flags().StringVar(&localOpt.GlobalDeployDir, "deploy-dir", "/tidb-deploy", "Storage directory for cluster deployment files, startup scripts, and configuration files.") + cmd.Flags().StringVar(&localOpt.GlobalDataDir, "data-dir", "/tidb-data", "TiDB Cluster data storage directory.") + cmd.Flags().StringVar(&localOpt.GlobalArch, "arch", "amd64", "Supported values: \"amd64\", \"arm64\".") + cmd.Flags().StringSliceVar(&localOpt.PDServers, "pd-servers", []string{"127.0.0.1"}, "List of PD servers") + cmd.Flags().StringSliceVar(&localOpt.TiDBServers, "tidb-servers", []string{"127.0.0.1"}, "List of TiDB servers") + cmd.Flags().StringSliceVar(&localOpt.TiKVServers, "tikv-servers", []string{"127.0.0.1"}, "List of TiKV servers") + cmd.Flags().StringSliceVar(&localOpt.TiFlashServers, "tiflash-servers", nil, "List of TiFlash servers") + cmd.Flags().StringSliceVar(&localOpt.MonitoringServers, "monitoring-servers", []string{"127.0.0.1"}, "List of monitor servers") + cmd.Flags().StringSliceVar(&localOpt.GrafanaServers, "grafana-servers", []string{"127.0.0.1"}, "List of grafana servers") + cmd.Flags().StringSliceVar(&localOpt.AlertManagerServers, "alertmanager-servers", nil, "List of alermanager servers") return cmd } diff --git a/components/cluster/command/template_test.go b/components/cluster/command/template_test.go new file mode 100644 index 0000000000..e5f4ff8828 --- /dev/null +++ b/components/cluster/command/template_test.go @@ -0,0 +1,128 @@ +package command + +import ( + "bytes" + "io" + "strings" + "testing" +) + +func Test_TemplateLocalCommandSingle(t *testing.T) { + tests := []struct { + optKey string + optVal string + expected string + }{ + {"user", "ubuntu", "user: \"ubuntu\""}, + {"group", "ubuntu", "group: \"ubuntu\""}, + {"ssh-port", "2222", "ssh_port: 2222"}, + {"deploy-dir", "/path/to/deploy", "deploy_dir: \"/path/to/deploy\""}, + {"data-dir", "/path/to/data", "data_dir: \"/path/to/data\""}, + {"arch", "arm64", "arch: \"arm64\""}, + {"pd-servers", "a,b,c", "pd_servers:\n - host: a\n - host: b\n - host: c"}, + {"tidb-servers", "a,b,c", "tidb_servers:\n - host: a\n - host: b\n - host: c"}, + {"tikv-servers", "a,b,c", "tikv_servers:\n - host: a\n - host: b\n - host: c"}, + {"tiflash-servers", "a,b,c", "tiflash_servers:\n - host: a\n - host: b\n - host: c"}, + {"monitoring-servers", "a,b,c", "monitoring_servers:\n - host: a\n - host: b\n - host: c"}, + {"grafana-servers", "a,b,c", "grafana_servers:\n - host: a\n - host: b\n - host: c"}, + {"alertmanager-servers", "a,b,c", "alertmanager_servers:\n - host: a\n - host: b\n - host: c"}, + } + + for _, test := range tests { + cmd := newTemplateCmd() + b := bytes.NewBufferString("") + cmd.SetOut(b) + _ = cmd.Flags().Set("local", "true") // add --local + _ = cmd.Flags().Set(test.optKey, test.optVal) + + if err := cmd.Execute(); err != nil { + t.Fatal(err) + } + + out, err := io.ReadAll(b) + if err != nil { + t.Fatal(err) + } + if !strings.Contains(string(out), test.expected) { + t.Fatalf("expected \"%s\", got \"%s\"", test.expected, string(out)) + } + } +} + +func Test_TemplateLocalCommandMulti(t *testing.T) { + cmd := newTemplateCmd() + b := bytes.NewBufferString("") + cmd.SetOut(b) + _ = cmd.Flags().Set("local", "true") // add --local + _ = cmd.Flags().Set("user", "ubuntu") // add --user=ubuntu + _ = cmd.Flags().Set("group", "ubuntu") // add --group=ubuntu + _ = cmd.Flags().Set("tidb-servers", "a,b,c") // add --tidb-servers=a,b,c + _ = cmd.Flags().Set("alertmanager-servers", "a,b,c") // add --alertmanager-servers=a,b,c + + if err := cmd.Execute(); err != nil { + t.Fatal(err) + } + + out, err := io.ReadAll(b) + if err != nil { + t.Fatal(err) + } + + for _, b := range []bool{ + strings.Contains(string(out), "user: \"ubuntu\""), + strings.Contains(string(out), "group: \"ubuntu\""), + strings.Contains(string(out), "tidb_servers:\n - host: a\n - host: b\n - host: c"), + strings.Contains(string(out), "alertmanager_servers:\n - host: a\n - host: b\n - host: c"), + } { + if !b { + t.Fatalf("unexpected output. got \"%s\"", string(out)) + } + } +} + +func Test_TemplateLocalCommandNoopt(t *testing.T) { + cmd := newTemplateCmd() + b := bytes.NewBufferString("") + cmd.SetOut(b) + _ = cmd.Flags().Set("local", "true") // add --local + + if err := cmd.Execute(); err != nil { + t.Fatal(err) + } + + out, err := io.ReadAll(b) + if err != nil { + t.Fatal(err) + } + + // check default output + for _, b := range []bool{ + strings.Contains(string(out), "user: \"tidb\""), + strings.Contains(string(out), "ssh_port: 22"), + strings.Contains(string(out), "deploy_dir: \"/tidb-deploy\""), + strings.Contains(string(out), "data_dir: \"/tidb-data\""), + strings.Contains(string(out), "arch: \"amd64\""), + strings.Contains(string(out), "pd_servers:\n - host: 127.0.0.1"), + strings.Contains(string(out), "tidb_servers:\n - host: 127.0.0.1"), + strings.Contains(string(out), "tikv_servers:\n - host: 127.0.0.1"), + strings.Contains(string(out), "monitoring_servers:\n - host: 127.0.0.1"), + strings.Contains(string(out), "grafana_servers:\n - host: 127.0.0.1"), + } { + if !b { + t.Fatalf("unexpected output. got \"%s\"", string(out)) + } + } +} + +func Test_TemplateLocalCommandValidate(t *testing.T) { + cmd := newTemplateCmd() + b := bytes.NewBufferString("") + cmd.SetOut(b) + _ = cmd.Flags().Set("local", "true") // add --local + _ = cmd.Flags().Set("arch", "i386") // add --arch=i386 (invalid) + + // should returns err + if err := cmd.Execute(); err == nil { + t.Fatal(err) + } +} diff --git a/components/dm/command/template.go b/components/dm/command/template.go index 6cba6212ee..96450e3fa0 100644 --- a/components/dm/command/template.go +++ b/components/dm/command/template.go @@ -14,8 +14,10 @@ package command import ( + "bytes" "fmt" "path" + "text/template" "github.com/pingcap/tiup/embed" "github.com/spf13/cobra" @@ -23,19 +25,39 @@ import ( // TemplateOptions contains the options for print topology template. type TemplateOptions struct { - Full bool // print full template + Full bool // print full template + Local bool // print and render local template +} + +// LocalTemplate contains the variables for print local template. +type LocalTemplate struct { + GlobalUser string // global.user in yaml template + GlobalGroup string // global.group in yaml template + GlobalSSHPort int // global.ssh_port in yaml template + GlobalDeployDir string // global.deploy_dir in yaml template + GlobalDataDir string // global.data_dir in yaml template + GlobalArch string // global.arch in yaml template + MasterServers []string // master_servers in yaml template + WorkerServers []string // worker_servers in yaml template + MonitoringServers []string // monitoring_servers in yaml template + GrafanaServers []string // grafana_servers in yaml template + AlertManagerServers []string // alertmanager_servers in yaml template } func newTemplateCmd() *cobra.Command { opt := TemplateOptions{} + localOpt := LocalTemplate{} cmd := &cobra.Command{ Use: "template", Short: "Print topology template", RunE: func(cmd *cobra.Command, args []string) error { name := "minimal.yaml" - if opt.Full { + switch { + case opt.Full: name = "topology.example.yaml" + case opt.Local: + name = "local.tpl" } fp := path.Join("examples", "dm", name) @@ -44,12 +66,62 @@ func newTemplateCmd() *cobra.Command { return err } - fmt.Println(string(tpl)) + if !opt.Local { + // print example yaml and return + fmt.Fprintln(cmd.OutOrStdout(), string(tpl)) + return nil + } + + // redner template + + // validate arch + if localOpt.GlobalArch != "amd64" && localOpt.GlobalArch != "arm64" { + return fmt.Errorf(`supported values are "amd64" or "arm64" in global.arch`) + } + + // validate number of masters and workers + if len(localOpt.MasterServers) < 3 { + return fmt.Errorf( + "at least 3 masters must be defined (given %d servers)", + len(localOpt.MasterServers), + ) + } + if len(localOpt.WorkerServers) < 3 { + return fmt.Errorf( + "at least 3 workers must be defined (given %d servers)", + len(localOpt.WorkerServers), + ) + } + + tmpl, err := template.New(name).Parse(string(tpl)) + if err != nil { + return err + } + content := bytes.NewBufferString("") + if err := tmpl.Execute(content, &localOpt); err != nil { + return err + } + + fmt.Fprintln(cmd.OutOrStdout(), content.String()) return nil }, } cmd.Flags().BoolVar(&opt.Full, "full", false, "Print the full topology template for DM cluster.") + cmd.Flags().BoolVar(&opt.Local, "local", false, "Print and render template for deploying a simple DM cluster locally.") + + // template values for rendering + cmd.Flags().StringVar(&localOpt.GlobalUser, "user", "tidb", "The user who runs the tidb cluster.") + cmd.Flags().StringVar(&localOpt.GlobalGroup, "group", "", "group is used to specify the group name the user belong to if it's not the same as user.") + cmd.Flags().IntVar(&localOpt.GlobalSSHPort, "ssh-port", 22, "SSH port of servers in the managed cluster.") + cmd.Flags().StringVar(&localOpt.GlobalDeployDir, "deploy-dir", "/tidb-deploy", "Storage directory for cluster deployment files, startup scripts, and configuration files.") + cmd.Flags().StringVar(&localOpt.GlobalDataDir, "data-dir", "/tidb-data", "TiDB Cluster data storage directory.") + cmd.Flags().StringVar(&localOpt.GlobalArch, "arch", "amd64", "Supported values: \"amd64\", \"arm64\".") + cmd.Flags().StringSliceVar(&localOpt.MasterServers, "master-servers", []string{"172.19.0.101", "172.19.0.102", "172.19.0.103"}, "List of Master servers") + cmd.Flags().StringSliceVar(&localOpt.WorkerServers, "worker-servers", []string{"172.19.0.101", "172.19.0.102", "172.19.0.103"}, "List of Worker servers") + cmd.Flags().StringSliceVar(&localOpt.MonitoringServers, "monitoring-servers", []string{"172.19.0.101"}, "List of monitor servers") + cmd.Flags().StringSliceVar(&localOpt.GrafanaServers, "grafana-servers", []string{"172.19.0.101"}, "List of grafana servers") + cmd.Flags().StringSliceVar(&localOpt.AlertManagerServers, "alertmanager-servers", []string{"172.19.0.101"}, "List of alermanager servers") return cmd } diff --git a/components/dm/command/template_test.go b/components/dm/command/template_test.go new file mode 100644 index 0000000000..d9799957ab --- /dev/null +++ b/components/dm/command/template_test.go @@ -0,0 +1,139 @@ +package command + +import ( + "bytes" + "io" + "strings" + "testing" +) + +func Test_DMTemplateLocalCommandSingle(t *testing.T) { + tests := []struct { + optKey string + optVal string + expected string + }{ + {"user", "ubuntu", "user: \"ubuntu\""}, + {"group", "ubuntu", "group: \"ubuntu\""}, + {"ssh-port", "2222", "ssh_port: 2222"}, + {"deploy-dir", "/path/to/deploy", "deploy_dir: \"/path/to/deploy\""}, + {"data-dir", "/path/to/data", "data_dir: \"/path/to/data\""}, + {"arch", "arm64", "arch: \"arm64\""}, + {"master-servers", "a,b,c", "master_servers:\n - host: a\n - host: b\n - host: c"}, + {"worker-servers", "a,b,c", "worker_servers:\n - host: a\n - host: b\n - host: c"}, + {"monitoring-servers", "a,b,c", "monitoring_servers:\n - host: a\n - host: b\n - host: c"}, + {"grafana-servers", "a,b,c", "grafana_servers:\n - host: a\n - host: b\n - host: c"}, + {"alertmanager-servers", "a,b,c", "alertmanager_servers:\n - host: a\n - host: b\n - host: c"}, + } + + for _, test := range tests { + cmd := newTemplateCmd() + b := bytes.NewBufferString("") + cmd.SetOut(b) + _ = cmd.Flags().Set("local", "true") // add --local + _ = cmd.Flags().Set(test.optKey, test.optVal) + + if err := cmd.Execute(); err != nil { + t.Fatal(err) + } + + out, err := io.ReadAll(b) + if err != nil { + t.Fatal(err) + } + if !strings.Contains(string(out), test.expected) { + t.Fatalf("expected \"%s\", got \"%s\"", test.expected, string(out)) + } + } +} + +func Test_DMTemplateLocalCommandMulti(t *testing.T) { + cmd := newTemplateCmd() + b := bytes.NewBufferString("") + cmd.SetOut(b) + _ = cmd.Flags().Set("local", "true") // add --local + _ = cmd.Flags().Set("user", "ubuntu") // add --user=ubuntu + _ = cmd.Flags().Set("group", "ubuntu") // add --group=ubuntu + _ = cmd.Flags().Set("master-servers", "m1,m2,m3") // add --master-servers=m1,m2,m3 + _ = cmd.Flags().Set("worker-servers", "w1,w2,w3") // add --worker-servers=w1,w2,w3 + _ = cmd.Flags().Set("alertmanager-servers", "a1,a2,a3") // add --alertmanager-servers=a1,a2,a3 + + if err := cmd.Execute(); err != nil { + t.Fatal(err) + } + + out, err := io.ReadAll(b) + if err != nil { + t.Fatal(err) + } + + for _, b := range []bool{ + strings.Contains(string(out), "user: \"ubuntu\""), + strings.Contains(string(out), "group: \"ubuntu\""), + strings.Contains(string(out), "master_servers:\n - host: m1\n - host: m2\n - host: m3"), + strings.Contains(string(out), "worker_servers:\n - host: w1\n - host: w2\n - host: w3"), + strings.Contains(string(out), "alertmanager_servers:\n - host: a1\n - host: a2\n - host: a3"), + } { + if !b { + t.Fatalf("unexpected output. got \"%s\"", string(out)) + } + } +} + +func Test_TemplateLocalCommandNoopt(t *testing.T) { + cmd := newTemplateCmd() + b := bytes.NewBufferString("") + cmd.SetOut(b) + _ = cmd.Flags().Set("local", "true") // add --local + + if err := cmd.Execute(); err != nil { + t.Fatal(err) + } + + out, err := io.ReadAll(b) + if err != nil { + t.Fatal(err) + } + + // check default output + for _, b := range []bool{ + strings.Contains(string(out), "user: \"tidb\""), + strings.Contains(string(out), "ssh_port: 22"), + strings.Contains(string(out), "deploy_dir: \"/tidb-deploy\""), + strings.Contains(string(out), "data_dir: \"/tidb-data\""), + strings.Contains(string(out), "arch: \"amd64\""), + strings.Contains(string(out), "master_servers:\n - host: 172.19.0.101\n - host: 172.19.0.102\n - host: 172.19.0.103"), + strings.Contains(string(out), "worker_servers:\n - host: 172.19.0.101\n - host: 172.19.0.102\n - host: 172.19.0.103"), + strings.Contains(string(out), "monitoring_servers:\n - host: 172.19.0.101"), + strings.Contains(string(out), "grafana_servers:\n - host: 172.19.0.101"), + strings.Contains(string(out), "alertmanager_servers:\n - host: 172.19.0.101"), + } { + if !b { + t.Fatalf("unexpected output. got \"%s\"", string(out)) + } + } +} + +func Test_TemplateLocalCommandValidate(t *testing.T) { + tests := []struct { + optKey string + optVal string + }{ + {"arch", "i386"}, + {"master-servers", "m1,m2"}, + {"worker-servers", "w1"}, + } + + for _, test := range tests { + cmd := newTemplateCmd() + b := bytes.NewBufferString("") + cmd.SetOut(b) + _ = cmd.Flags().Set("local", "true") // add --local + _ = cmd.Flags().Set(test.optKey, test.optVal) // add invalid option + + // should returns err + if err := cmd.Execute(); err == nil { + t.Fatal(err) + } + } +} diff --git a/embed/examples/cluster/local.tpl b/embed/examples/cluster/local.tpl new file mode 100644 index 0000000000..a5b0679551 --- /dev/null +++ b/embed/examples/cluster/local.tpl @@ -0,0 +1,65 @@ +# For more information about the format of the tiup cluster topology file, consult +# https://docs.pingcap.com/tidb/stable/production-deployment-using-tiup#step-3-initialize-cluster-topology-file + +# # Global variables are applied to all deployments and used as the default value of +# # the deployments if a specific deployment value is missing. +global: + # # The OS user who runs the tidb cluster. + user: "{{ .GlobalUser }}" + {{- if .GlobalGroup }} + # group is used to specify the group name the user belong to if it's not the same as user. + group: "{{ .GlobalGroup }}" + {{- end }} + # # SSH port of servers in the managed cluster. + ssh_port: {{ .GlobalSSHPort }} + # # Storage directory for cluster deployment files, startup scripts, and configuration files. + deploy_dir: "{{ .GlobalDeployDir }}" + # # TiDB Cluster data storage directory + data_dir: "{{ .GlobalDataDir }}" + {{- if .GlobalArch }} + # # Supported values: "amd64", "arm64" (default: "amd64") + arch: "{{ .GlobalArch }}" + {{- end }} + +{{ if .TiDBServers -}} +pd_servers: +{{- range .PDServers }} + - host: {{ . }} +{{- end }} +{{ end }} +{{ if .TiDBServers -}} +tidb_servers: +{{- range .TiDBServers }} + - host: {{ . }} +{{- end }} +{{ end }} +{{ if .TiKVServers -}} +tikv_servers: +{{- range .TiKVServers }} + - host: {{ . }} +{{- end }} +{{ end }} +{{- if .TiFlashServers }} +tiflash_servers: + {{- range .TiFlashServers }} + - host: {{ . }} +{{- end }} +{{ end }} +{{ if .MonitoringServers -}} +monitoring_servers: + {{- range .MonitoringServers }} + - host: {{ . }} +{{- end }} +{{ end }} +{{ if .GrafanaServers -}} +grafana_servers: + {{- range .GrafanaServers }} + - host: {{ . }} +{{- end }} +{{ end }} +{{- if .AlertManagerServers }} +alertmanager_servers: + {{- range .AlertManagerServers }} + - host: {{ . }} +{{- end }} +{{ end }} \ No newline at end of file diff --git a/embed/examples/cluster/local.yaml b/embed/examples/cluster/local.yaml deleted file mode 100644 index b510c9b00f..0000000000 --- a/embed/examples/cluster/local.yaml +++ /dev/null @@ -1,32 +0,0 @@ -# For more information about the format of the tiup cluster topology file, consult -# https://docs.pingcap.com/tidb/stable/production-deployment-using-tiup#step-3-initialize-cluster-topology-file - -# # Global variables are applied to all deployments and used as the default value of -# # the deployments if a specific deployment value is missing. -global: - # # The OS user who runs the tidb cluster. - user: "ubuntu" - # # SSH port of servers in the managed cluster. - ssh_port: 22 - # # Storage directory for cluster deployment files, startup scripts, and configuration files. - deploy_dir: "/home/ubuntu/.tiup/cluster/tidb-deploy" - # # TiDB Cluster data storage directory - data_dir: "/home/ubuntu/.tiup/cluster/tidb-data" - -pd_servers: - - host: 127.0.0.1 - -tidb_servers: - - host: 127.0.0.1 - -tikv_servers: - - host: 127.0.0.1 - -tiflash_servers: - - host: 127.0.0.1 - -monitoring_servers: - - host: 127.0.0.1 - -grafana_servers: - - host: 127.0.0.1 diff --git a/embed/examples/dm/local.tpl b/embed/examples/dm/local.tpl new file mode 100644 index 0000000000..8a3f5bf00d --- /dev/null +++ b/embed/examples/dm/local.tpl @@ -0,0 +1,54 @@ +# The topology template is used deploy a minimal DM cluster, which suitable +# for scenarios with only three machinescontains. The minimal cluster contains +# - 3 master nodes +# - 3 worker nodes +# You can change the hosts according your environment +--- +global: + # # The OS user who runs the tidb cluster. + user: "{{ .GlobalUser }}" + {{- if .GlobalGroup }} + # group is used to specify the group name the user belong to if it's not the same as user. + group: "{{ .GlobalGroup }}" + {{- end }} + # # SSH port of servers in the managed cluster. + ssh_port: {{ .GlobalSSHPort }} + # # Storage directory for cluster deployment files, startup scripts, and configuration files. + deploy_dir: "{{ .GlobalDeployDir }}" + # # TiDB Cluster data storage directory + data_dir: "{{ .GlobalDataDir }}" + {{- if .GlobalArch }} + # # Supported values: "amd64", "arm64" (default: "amd64") + arch: "{{ .GlobalArch }}" + {{- end }} + +{{ if .MasterServers -}} +master_servers: +{{- range .MasterServers }} + - host: {{ . }} +{{- end }} +{{ end }} +{{ if .WorkerServers -}} +worker_servers: +{{- range .WorkerServers }} + - host: {{ . }} +{{- end }} +{{ end }} +{{ if .MonitoringServers -}} +monitoring_servers: + {{- range .MonitoringServers }} + - host: {{ . }} +{{- end }} +{{ end }} +{{ if .GrafanaServers -}} +grafana_servers: + {{- range .GrafanaServers }} + - host: {{ . }} +{{- end }} +{{ end }} +{{- if .AlertManagerServers }} +alertmanager_servers: + {{- range .AlertManagerServers }} + - host: {{ . }} +{{- end }} +{{ end }} \ No newline at end of file