Skip to content

Commit

Permalink
Fix issue with new version of go-execute
Browse files Browse the repository at this point in the history
Fixes: 978

Due to the way go-execute had to change for Windows users
command can only specify a single command or binary, rather
than a whole string separated by spaces. This commit makes
sure Args is always used to pass in extra arguments.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Oct 2, 2023
1 parent f40de71 commit c41c316
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 29 deletions.
9 changes: 7 additions & 2 deletions pkg/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ import (

// GetClientArch returns a pair of arch and os
func GetClientArch() (arch string, os string) {
task := execute.ExecTask{Command: "uname", Args: []string{"-m"}, StreamStdio: false}
task := execute.ExecTask{
Command: "uname",
Args: []string{"-m"},
StreamStdio: false}
res, err := task.Execute(context.Background())
if err != nil {
log.Println(err)
}

archResult := strings.TrimSpace(res.Stdout)

taskOS := execute.ExecTask{Command: "uname", Args: []string{"-s"}, StreamStdio: false}
taskOS := execute.ExecTask{Command: "uname",
Args: []string{"-s"},
StreamStdio: false}
resOS, errOS := taskOS.Execute(context.Background())
if errOS != nil {
log.Println(errOS)
Expand Down
35 changes: 8 additions & 27 deletions pkg/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,34 +71,12 @@ func DownloadHelm(userPath, clientArch, clientOS, subdir string) error {
return nil
}

func HelmInit() error {
fmt.Println("Running \"helm init\".")
subdir := ""

task := execute.ExecTask{
Command: env.LocalBinary("helm", subdir),
Env: os.Environ(),
Args: []string{"init", "--client-only"},
StreamStdio: true,
}

res, err := task.Execute(context.Background())

if err != nil {
return err
}

if res.ExitCode != 0 {
return fmt.Errorf("exit code %d", res.ExitCode)
}
return nil
}

func UpdateHelmRepos(helm3 bool) error {
subdir := ""

task := execute.ExecTask{
Command: fmt.Sprintf("%s repo update", env.LocalBinary("helm", subdir)),
Command: env.LocalBinary("helm", subdir),
Args: []string{"repo", "update"},
Env: os.Environ(),
StreamStdio: true,
}
Expand All @@ -123,7 +101,8 @@ func AddHelmRepo(name, url string, update bool) error {
}

task := execute.ExecTask{
Command: fmt.Sprintf("%s repo add %s %s --force-update", env.LocalBinary("helm", subdir), name, url),
Command: env.LocalBinary("helm", subdir),
Args: []string{"repo", "add", name, url, "--force-update"},
Env: os.Environ(),
StreamStdio: true,
}
Expand All @@ -140,7 +119,8 @@ func AddHelmRepo(name, url string, update bool) error {

if update {
task := execute.ExecTask{
Command: fmt.Sprintf("%s repo update", env.LocalBinary("helm", subdir)),
Command: env.LocalBinary("helm", subdir),
Args: []string{"repo", "update"},
Env: os.Environ(),
StreamStdio: true,
}
Expand Down Expand Up @@ -180,7 +160,8 @@ func FetchChart(chart, version string) error {
return mkErr
}
task := execute.ExecTask{
Command: fmt.Sprintf("%s fetch %s --untar=true --untardir %s%s", env.LocalBinary("helm", subdir), chart, chartsPath, versionStr),
Command: env.LocalBinary("helm", subdir),
Args: []string{"fetch", chart, "--untar=true", "--untardir", chartsPath + versionStr},
Env: os.Environ(),
StreamStdio: true,
}
Expand Down

0 comments on commit c41c316

Please sign in to comment.