From b135aaed3e6d706cf1387f87a262b1d3c923bfa8 Mon Sep 17 00:00:00 2001 From: lucklove Date: Thu, 1 Apr 2021 18:46:21 +0800 Subject: [PATCH 1/3] Fix the dir check logic on imported cluster --- pkg/cluster/spec/validate.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/cluster/spec/validate.go b/pkg/cluster/spec/validate.go index fcbd6d8d19..ad12d76e45 100644 --- a/pkg/cluster/spec/validate.go +++ b/pkg/cluster/spec/validate.go @@ -223,6 +223,9 @@ func CheckClusterDirOverlap(entries []DirEntry) error { } if utils.IsSubDir(d1.dir, d2.dir) || utils.IsSubDir(d2.dir, d1.dir) { + if d1.instance.IsImported() && d2.instance.IsImported() { + continue + } properties := map[string]string{ "ThisDirKind": d1.dirKind, "ThisDir": d1.dir, From 579e746a472e10eed741a8b70d261ac9c2c12da6 Mon Sep 17 00:00:00 2001 From: lucklove Date: Tue, 6 Apr 2021 19:46:48 +0800 Subject: [PATCH 2/3] Fix the issue that can't import dm --- components/dm/ansible/import.go | 9 +++++++-- pkg/cluster/manager/deploy.go | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/components/dm/ansible/import.go b/components/dm/ansible/import.go index 18ae1f4bd2..e0fd50dc21 100644 --- a/components/dm/ansible/import.go +++ b/components/dm/ansible/import.go @@ -330,8 +330,9 @@ func (im *Importer) ImportFromAnsibleDir(ctx context.Context) (clusterName strin case "dm_master_servers": for _, host := range group.Hosts { srv := &spec.MasterSpec{ - Host: host.Vars["ansible_host"], - SSHPort: ansible.GetHostPort(host, cfg), + Host: host.Vars["ansible_host"], + SSHPort: ansible.GetHostPort(host, cfg), + Imported: true, } runFileName := filepath.Join(host.Vars["deploy_dir"], "scripts", "run_dm-master.sh") @@ -380,6 +381,7 @@ func (im *Importer) ImportFromAnsibleDir(ctx context.Context) (clusterName strin Host: host.Vars["ansible_host"], SSHPort: ansible.GetHostPort(host, cfg), DeployDir: firstNonEmpty(host.Vars["deploy_dir"], topo.GlobalOptions.DeployDir), + Imported: true, } runFileName := filepath.Join(host.Vars["deploy_dir"], "scripts", "run_dm-worker.sh") @@ -441,6 +443,7 @@ func (im *Importer) ImportFromAnsibleDir(ctx context.Context) (clusterName strin Host: host.Vars["ansible_host"], SSHPort: ansible.GetHostPort(host, cfg), DeployDir: firstNonEmpty(host.Vars["deploy_dir"], topo.GlobalOptions.DeployDir), + Imported: true, } runFileName := filepath.Join(host.Vars["deploy_dir"], "scripts", "run_prometheus.sh") @@ -489,6 +492,7 @@ func (im *Importer) ImportFromAnsibleDir(ctx context.Context) (clusterName strin Host: host.Vars["ansible_host"], SSHPort: ansible.GetHostPort(host, cfg), DeployDir: firstNonEmpty(host.Vars["deploy_dir"], topo.GlobalOptions.DeployDir), + Imported: true, } runFileName := filepath.Join(host.Vars["deploy_dir"], "scripts", "run_alertmanager.sh") @@ -546,6 +550,7 @@ func (im *Importer) ImportFromAnsibleDir(ctx context.Context) (clusterName strin Port: port, Username: grafanaUser, Password: grafanaPass, + Imported: true, } runFileName := filepath.Join(host.Vars["deploy_dir"], "scripts", "run_grafana.sh") diff --git a/pkg/cluster/manager/deploy.go b/pkg/cluster/manager/deploy.go index 1ca3ecde85..f38e82624e 100644 --- a/pkg/cluster/manager/deploy.go +++ b/pkg/cluster/manager/deploy.go @@ -187,8 +187,9 @@ func (m *Manager) Deploy( iterErr = nil topo.IterInstance(func(inst spec.Instance) { if _, found := uniqueHosts[inst.GetHost()]; !found { - // check for "imported" parameter, it can not be true when scaling out - if inst.IsImported() { + // check for "imported" parameter, it can not be true when deploying and scaling out + // only for tidb now, need to support dm + if inst.IsImported() && m.sysName == "tidb" { iterErr = errors.New( "'imported' is set to 'true' for new instance, this is only used " + "for instances imported from tidb-ansible and make no sense when " + From ab8baaccf71bc8de2dbd630017e0bc4159c4bfb0 Mon Sep 17 00:00:00 2001 From: lucklove Date: Wed, 7 Apr 2021 11:10:31 +0800 Subject: [PATCH 3/3] Fix test --- components/dm/ansible/import_test.go | 5 +++++ pkg/cluster/spec/prometheus.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/components/dm/ansible/import_test.go b/components/dm/ansible/import_test.go index 66109bcd3d..51711695f6 100644 --- a/components/dm/ansible/import_test.go +++ b/components/dm/ansible/import_test.go @@ -164,6 +164,7 @@ func TestImportFromAnsible(t *testing.T) { DeployDir: "", LogDir: "/home/tidb/deploy/log", Config: map[string]interface{}{"log-level": "info"}, + Imported: true, } assert.Equal(expectedMaster, master) @@ -180,6 +181,7 @@ func TestImportFromAnsible(t *testing.T) { DeployDir: "/home/tidb/deploy", LogDir: "/home/tidb/deploy/log", Config: map[string]interface{}{"log-level": "info"}, + Imported: true, } worker := topo.Workers[0] @@ -199,6 +201,7 @@ func TestImportFromAnsible(t *testing.T) { DeployDir: "", DataDir: "/home/tidb/deploy/data.alertmanager", LogDir: "/home/tidb/deploy/log", + Imported: true, } assert.Equal(expectedAlter, aler) @@ -212,6 +215,7 @@ func TestImportFromAnsible(t *testing.T) { Port: 3001, Username: "foo", Password: "bar", + Imported: true, } assert.Equal(expectedGrafana, grafana) @@ -225,6 +229,7 @@ func TestImportFromAnsible(t *testing.T) { DataDir: "/home/tidb/deploy/prometheus.data.metrics", LogDir: "/home/tidb/deploy/log", Port: 9090, + Imported: true, } assert.Equal(expectedMonitor, monitor) diff --git a/pkg/cluster/spec/prometheus.go b/pkg/cluster/spec/prometheus.go index fad408e7de..3b6703b11d 100644 --- a/pkg/cluster/spec/prometheus.go +++ b/pkg/cluster/spec/prometheus.go @@ -372,7 +372,7 @@ func (i *MonitorInstance) initRules(ctx context.Context, e ctxt.Executor, spec * "mkdir -p %[1]s/conf", `find %[1]s/conf -type f -name "*.rules.yml" -delete`, `find %[1]s/bin/prometheus -maxdepth 1 -type f -name "*.rules.yml" -exec cp {} %[1]s/conf/ \;`, - `find %[1]s/conf -maxdepth 1 -type f -name "*.rules.yml" -exec sed -i "s/ENV_LABELS_ENV/%[2]s/g" {} \;`, + `find %[1]s/conf -maxdepth 1 -type f -name "*.rules.yml" -exec sed -i -e "s/ENV_LABELS_ENV/%[2]s/g" {} \;`, } _, stderr, err := e.Execute(ctx, fmt.Sprintf(strings.Join(cmds, " && "), paths.Deploy, clusterName), false) if err != nil {