Skip to content

Commit

Permalink
Support flag overrides
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Oct 11, 2019
1 parent b13bebb commit 2093d6e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
11 changes: 8 additions & 3 deletions pkg/cmd/kubernetes_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,22 @@ func getArchitecture() string {
return arch
}

func templateChart(basePath, chart, namespace, outputPath, values string) error {
func templateChart(basePath, chart, namespace, outputPath, values string, overrides map[string]string) error {

mkErr := os.MkdirAll(outputPath, 0700)
if mkErr != nil {
return mkErr
}

overridesStr := ""
for k, v := range overrides {
overridesStr += fmt.Sprintf(" --set %s=%s", k, v)
}

chartRoot := path.Join(basePath, chart)
task := execute.ExecTask{
Command: fmt.Sprintf("%s template %s --output-dir %s --values %s --namespace %s",
localBinary("helm"), chart, outputPath, path.Join(chartRoot, values), namespace),
Command: fmt.Sprintf("%s template %s --output-dir %s --values %s --namespace %s %s",
localBinary("helm"), chart, outputPath, path.Join(chartRoot, values), namespace, overridesStr),
Env: os.Environ(),
Cwd: basePath,
}
Expand Down
25 changes: 20 additions & 5 deletions pkg/cmd/openfaas_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/url"
"os"
"path"
"strconv"
"strings"

"github.com/alexellis/go-execute"
Expand All @@ -28,8 +29,9 @@ func makeInstallOpenFaaS() *cobra.Command {
SilenceUsage: true,
}

openfaas.Flags().Bool("loadbalancer", false, "add a loadbalancer")
openfaas.Flags().StringP("namespace", "n", "openfaas", "Namespace for core services")
openfaas.Flags().BoolP("basic-auth", "a", true, "Enable authentication")
openfaas.Flags().BoolP("load-balancer", "l", false, "Add a loadbalancer")
openfaas.Flags().StringP("namespace", "n", "openfaas", "The namespace for the core services")

openfaas.RunE = func(command *cobra.Command, args []string) error {
kubeConfigPath := path.Join(os.Getenv("HOME"), ".kube/config")
Expand Down Expand Up @@ -75,8 +77,6 @@ func makeInstallOpenFaaS() *cobra.Command {
}
}

// lb, _ := command.Flags().GetBool("loadbalancer")

namespace, _ := command.Flags().GetString("namespace")

err = addHelmRepo("openfaas", "https://openfaas.github.io/faas-netes/")
Expand Down Expand Up @@ -115,8 +115,23 @@ func makeInstallOpenFaaS() *cobra.Command {
return err
}

overrides := map[string]string{}

basicAuth, _ := command.Flags().GetBool("basic-auth")
overrides["basicAuth"] = strings.ToLower(strconv.FormatBool(basicAuth))

overrides["serviceType"] = "NodePort"
lb, _ := command.Flags().GetBool("load-balancer")
if lb {
overrides["serviceType"] = "LoadBalancer"
}

outputPath := path.Join(chartPath, "openfaas/rendered")
err = templateChart(chartPath, "openfaas", namespace, outputPath, "values"+valuesSuffix+".yaml")
err = templateChart(chartPath, "openfaas",
namespace,
outputPath,
"values"+valuesSuffix+".yaml",
overrides)
if err != nil {
return err
}
Expand Down

0 comments on commit 2093d6e

Please sign in to comment.