Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: cleanup wrong conf files #738

Merged
merged 5 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/dm/spec/grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (i *GrafanaInstance) InitConfig(e executor.Executor, clusterName, clusterVe
func (i *GrafanaInstance) initDashboards(e executor.Executor, spec GrafanaSpec, paths meta.DirPaths) error {
dashboardsDir := filepath.Join(paths.Deploy, "dashboards")
// To make this step idempotent, we need cleanup old dashboards first
if _, _, err := e.Execute(fmt.Sprintf("rm -f %s/*", dashboardsDir), false); err != nil {
if _, _, err := e.Execute(fmt.Sprintf("rm -f %s/*.json", dashboardsDir), false); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/cluster/executor/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (e *EasySSHExecutor) initialize(config SSHConfig) {
func (e *EasySSHExecutor) Execute(cmd string, sudo bool, timeout ...time.Duration) ([]byte, []byte, error) {
// try to acquire root permission
if e.Sudo || sudo {
cmd = fmt.Sprintf("sudo -H -u root bash -c \"%s\"", cmd)
cmd = fmt.Sprintf("sudo -H bash -c \"%s\"", cmd)
}

// set a basic PATH in case it's empty on login
Expand Down Expand Up @@ -278,7 +278,7 @@ func (e *NativeSSHExecutor) Execute(cmd string, sudo bool, timeout ...time.Durat

// try to acquire root permission
if e.Sudo || sudo {
cmd = fmt.Sprintf("sudo -H -u root bash -c \"%s\"", cmd)
cmd = fmt.Sprintf("sudo -H bash -c \"%s\"", cmd)
}

// set a basic PATH in case it's empty on login
Expand Down
9 changes: 5 additions & 4 deletions pkg/cluster/spec/alertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,15 @@ func (i *AlertManagerInstance) InitConfig(e executor.Executor, clusterName, clus
}

// transfer config

dst = filepath.Join(paths.Deploy, "conf", "alertmanager.yml")
if spec.ConfigFilePath != "" {
dst = filepath.Join(paths.Deploy, "conf", "alertmanager.yml")
return i.TransferLocalConfigFile(e, spec.ConfigFilePath, dst)
}

configPath := filepath.Join(paths.Cache, fmt.Sprintf("alertmanager_%s.yml", i.GetHost()))
return config.NewAlertManagerConfig().ConfigToFile(configPath)
if err := config.NewAlertManagerConfig().ConfigToFile(configPath); err != nil {
return err
}
return i.TransferLocalConfigFile(e, configPath, dst)
}

// ScaleConfig deploy temporary config on scaling
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/spec/grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (i *GrafanaInstance) InitConfig(e executor.Executor, clusterName, clusterVe
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/*", 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 Down
2 changes: 1 addition & 1 deletion pkg/cluster/spec/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (i *MonitorInstance) InitConfig(e executor.Executor, clusterName, 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/*", 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 Down