Skip to content

Commit

Permalink
fix(cluster): quote surround wildcard
Browse files Browse the repository at this point in the history
  • Loading branch information
jsvisa committed Dec 10, 2020
1 parent 9e5f2bd commit a2a7a8e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
8 changes: 4 additions & 4 deletions pkg/cluster/spec/grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (i *GrafanaInstance) InitConfig(
func (i *GrafanaInstance) initDashboards(e executor.Executor, spec GrafanaSpec, paths meta.DirPaths, clusterName string) error {
dashboardsDir := filepath.Join(paths.Deploy, "dashboards")
// To make this step idempotent, we need cleanup old dashboards first
cmd := fmt.Sprintf("mkdir -p %[1]s && rm -f %[1]s/*.json", dashboardsDir)
cmd := fmt.Sprintf(`mkdir -p %[1]s && rm -f "%[1]s/*.json"`, dashboardsDir)
if _, stderr, err := e.Execute(cmd, false); err != nil {
return errors.Annotatef(err, "cleanup old dashboards: %s, cmd: %s", string(stderr), cmd)
}
Expand All @@ -212,7 +212,7 @@ func (i *GrafanaInstance) initDashboards(e executor.Executor, spec GrafanaSpec,
})
}

cmd = fmt.Sprintf("cp %[1]s/bin/*.json %[1]s/dashboards/", paths.Deploy)
cmd = fmt.Sprintf(`cp "%[1]s/bin/*.json" %[1]s/dashboards/`, paths.Deploy)
if _, _, err := e.Execute(cmd, false); err != nil {
return errors.Annotatef(err, "execute command failed: %s", err)
}
Expand Down Expand Up @@ -265,12 +265,12 @@ func (i *GrafanaInstance) installDashboards(e executor.Executor, deployDir, clus

// copy dm-master/scripts/*.json
targetDir := filepath.Join(deployDir, "bin")
_, stderr, err = e.Execute(fmt.Sprintf("mkdir -p %[1]s && rm -f %[1]s/*.json", targetDir), false)
_, stderr, err = e.Execute(fmt.Sprintf(`mkdir -p %[1]s && rm -f "%[1]s/*.json"`, targetDir), false)
if err != nil {
return errors.Annotatef(err, "stderr: %s", string(stderr))
}

cmd = fmt.Sprintf("cp %s/dm-master/scripts/*.json %s", tmp, targetDir)
cmd = fmt.Sprintf(`cp "%s/dm-master/scripts/*.json" %s`, tmp, targetDir)
_, stderr, err = e.Execute(cmd, false)
if err != nil {
return errors.Annotatef(err, "stderr: %s", string(stderr))
Expand Down
11 changes: 7 additions & 4 deletions pkg/cluster/spec/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,15 @@ func (i *MonitorInstance) installRules(e executor.Executor, deployDir, clusterVe

// copy dm-master/conf/*.rules.yml
targetDir := filepath.Join(deployDir, "bin", "prometheus")
_, stderr, err = e.Execute(fmt.Sprintf("mkdir -p %[1]s && rm -f %[1]s/*.rules.yml", targetDir), false)
_, stderr, err = e.Execute(fmt.Sprintf(`mkdir -p %[1]s && rm -f "%[1]s/*.rules.yml"`, targetDir), false)
if err != nil {
return errors.Annotatef(err, "stderr: %s", string(stderr))
}

cmd = fmt.Sprintf("cp %s/dm-master/conf/*.rules.yml %s", tmp, targetDir)
// in zsh, if a wildcard pattern doesn't match any file, you'll get an error,
// use quote to prevent this.
// ref https://github.com/pingcap/tiup/issues/974#issuecomment-740462495
cmd = fmt.Sprintf(`cp "%s/dm-master/conf/*.rules.yml" %s`, tmp, targetDir)
_, stderr, err = e.Execute(cmd, false)
if err != nil {
return errors.Annotatef(err, "stderr: %s", string(stderr))
Expand All @@ -319,7 +322,7 @@ func (i *MonitorInstance) installRules(e executor.Executor, deployDir, clusterVe

func (i *MonitorInstance) initRules(e executor.Executor, spec PrometheusSpec, paths meta.DirPaths) error {
// To make this step idempotent, we need cleanup old rules first
if _, _, err := e.Execute(fmt.Sprintf("rm -f %s/*.rules.yml", path.Join(paths.Deploy, "conf")), false); err != nil {
if _, _, err := e.Execute(fmt.Sprintf(`rm -f "%s/*.rules.yml"`, path.Join(paths.Deploy, "conf")), false); err != nil {
return err
}

Expand All @@ -330,7 +333,7 @@ func (i *MonitorInstance) initRules(e executor.Executor, spec PrometheusSpec, pa
}

// Use the default ones
cmd := fmt.Sprintf("cp %[1]s/bin/prometheus/*.rules.yml %[1]s/conf/", paths.Deploy)
cmd := fmt.Sprintf(`cp "%[1]s/bin/prometheus/*.rules.yml" %[1]s/conf/`, paths.Deploy)
if _, _, err := e.Execute(cmd, false); err != nil {
return err
}
Expand Down

0 comments on commit a2a7a8e

Please sign in to comment.