From 31c2793ef80965d45bca8a388d197247df65fea0 Mon Sep 17 00:00:00 2001 From: 0fatal <2816813070@qq.com> Date: Mon, 18 Dec 2023 07:36:46 +0000 Subject: [PATCH] Support specify conf path of toolv2 Signed-off-by: 0fatal <2816813070@qq.com> --- cli/command/install/tool.go | 10 ++++++---- internal/common/common.go | 4 ++-- internal/task/task/install/install_tool.go | 14 +++++++++----- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/cli/command/install/tool.go b/cli/command/install/tool.go index 8c2f94415..a93520842 100644 --- a/cli/command/install/tool.go +++ b/cli/command/install/tool.go @@ -18,8 +18,9 @@ var ( ) type installOptions struct { - host string - path string + host string + path string + confPath string } func NewInstallToolCommand(curveadm *cli.CurveAdm) *cobra.Command { @@ -38,6 +39,7 @@ func NewInstallToolCommand(curveadm *cli.CurveAdm) *cobra.Command { flags := cmd.Flags() flags.StringVar(&options.host, "host", "localhost", "Specify target host") flags.StringVar(&options.path, "path", "/usr/local/bin/curve", "Specify target install path of tool v2") + flags.StringVar(&options.confPath, "confPath", "~/.curve/curve.yaml", "Specify target config path of tool v2") return cmd } @@ -57,8 +59,8 @@ func genInstallToolPlaybook(curveadm *cli.CurveAdm, Type: step, Configs: configs, Options: map[string]interface{}{ - comm.KEY_INSTALL_HOST: options.host, - comm.KEY_INSTALL_PATH: options.path, + comm.KEY_INSTALL_PATH: options.path, + comm.KEY_INSTALL_CONF_PATH: options.confPath, }, }) } diff --git a/internal/common/common.go b/internal/common/common.go index 2b718f20c..81cc34858 100644 --- a/internal/common/common.go +++ b/internal/common/common.go @@ -136,8 +136,8 @@ const ( KEY_WEBSITE_STATUS = "WEBSITE_STATUS" // install - KEY_INSTALL_HOST = "INSTALL_HOST" - KEY_INSTALL_PATH = "INSTALL_PATH" + KEY_INSTALL_PATH = "INSTALL_PATH" + KEY_INSTALL_CONF_PATH = "INSTALL_CONF_PATH" ) // others diff --git a/internal/task/task/install/install_tool.go b/internal/task/task/install/install_tool.go index 20be81242..8dfcf4816 100644 --- a/internal/task/task/install/install_tool.go +++ b/internal/task/task/install/install_tool.go @@ -10,6 +10,7 @@ import ( "github.com/opencurve/curveadm/internal/task/task" tui "github.com/opencurve/curveadm/internal/tui/common" "github.com/opencurve/curveadm/pkg/module" + "path/filepath" ) func checkPathExist(path string, sshConfig *module.SSHConfig, curveadm *cli.CurveAdm) error { @@ -30,9 +31,9 @@ func checkPathExist(path string, sshConfig *module.SSHConfig, curveadm *cli.Curv func NewInstallToolTask(curveadm *cli.CurveAdm, dc *topology.DeployConfig) (*task.Task, error) { layout := dc.GetProjectLayout() - host := curveadm.MemStorage().Get(comm.KEY_INSTALL_HOST).(string) path := curveadm.MemStorage().Get(comm.KEY_INSTALL_PATH).(string) - hc, err := curveadm.GetHost(host) + confPath := curveadm.MemStorage().Get(comm.KEY_INSTALL_CONF_PATH).(string) + hc, err := curveadm.GetHost(dc.GetHost()) if err != nil { return nil, err } @@ -46,8 +47,11 @@ func NewInstallToolTask(curveadm *cli.CurveAdm, dc *topology.DeployConfig) (*tas if err = checkPathExist(path, hc.GetSSHConfig(), curveadm); err != nil { return nil, err } + if err = checkPathExist(confPath, hc.GetSSHConfig(), curveadm); err != nil { + return nil, err + } - subname := fmt.Sprintf("host=%s", host) + subname := fmt.Sprintf("host=%s", dc.GetHost()) t := task.NewTask("Install tool v2", subname, hc.GetSSHConfig()) t.AddStep(&step.CopyFromContainer{ @@ -57,13 +61,13 @@ func NewInstallToolTask(curveadm *cli.CurveAdm, dc *topology.DeployConfig) (*tas ExecOptions: curveadm.ExecOptions(), }) t.AddStep(&step.CreateDirectory{ - Paths: []string{"~/.curve"}, + Paths: []string{filepath.Dir(confPath)}, ExecOptions: curveadm.ExecOptions(), }) t.AddStep(&step.CopyFromContainer{ ContainerSrcPath: layout.ToolsV2ConfSystemPath, ContainerId: containerId, - HostDestPath: "~/.curve/curve.yaml", + HostDestPath: confPath, ExecOptions: curveadm.ExecOptions(), })