Skip to content

Commit

Permalink
Extract helm download code
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed Oct 15, 2019
1 parent 09a4820 commit 20e1074
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
25 changes: 15 additions & 10 deletions pkg/cmd/metricsserver_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,21 @@ func makeInstallMetricsServer() *cobra.Command {
clientArch, clientOS := getClientArch()

fmt.Printf("Client: %s, %s\n", clientArch, clientOS)

log.Printf("User dir established as: %s\n", userPath)

os.Setenv("HELM_HOME", path.Join(userPath, ".helm"))

if _, statErr := os.Stat(path.Join(path.Join(userPath, ".bin"), "helm")); statErr != nil {
downloadHelm(userPath, clientArch, clientOS)

err = helmInit()
if err != nil {
return err
}
err = tryDownloadHelm(userPath, clientArch, clientOS)
if err != nil {
return err
}

err = updateHelmRepos()

if err != nil {
return err
}

chartPath := path.Join(os.TempDir(), "charts")

err = fetchChart(chartPath, "stable/metrics-server")

if err != nil {
Expand Down Expand Up @@ -119,3 +112,15 @@ Thank you for using k3sup!`)

return metricsServer
}

func tryDownloadHelm(userPath, clientArch, clientOS string) error {
if _, statErr := os.Stat(path.Join(path.Join(userPath, ".bin"), "helm")); statErr != nil {
downloadHelm(userPath, clientArch, clientOS)

err := helmInit()
if err != nil {
return err
}
}
return nil
}
10 changes: 3 additions & 7 deletions pkg/cmd/openfaas_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,9 @@ func makeInstallOpenFaaS() *cobra.Command {

os.Setenv("HELM_HOME", path.Join(userPath, ".helm"))

if _, statErr := os.Stat(path.Join(path.Join(userPath, ".bin"), "helm")); statErr != nil {
downloadHelm(userPath, clientArch, clientOS)

err = helmInit()
if err != nil {
return err
}
err = tryDownloadHelm(userPath, clientArch, clientOS)
if err != nil {
return err
}

err = addHelmRepo("openfaas", "https://openfaas.github.io/faas-netes/")
Expand Down

0 comments on commit 20e1074

Please sign in to comment.