Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/gemalto/helm-spray
Browse files Browse the repository at this point in the history
  • Loading branch information
jroucheton committed Jan 26, 2019
2 parents 670c470 + 7817721 commit 2c13d32
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
19 changes: 14 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ type sprayCmd struct {
chartName string
chartVersion string
namespace string
valuesFile string
valueFiles []string
valuesSet string
dryRun bool
debug bool
}

// Dependency ...
Expand Down Expand Up @@ -116,12 +117,20 @@ func newSprayCmd(args []string) *cobra.Command {
}

f := cmd.Flags()
f.StringVarP(&p.valuesFile, "values", "f", "", "specify values in a YAML file or a URL (can specify multiple)")
f.StringSliceVarP(&p.valueFiles, "values", "f", []string{}, "specify values in a YAML file or a URL (can specify multiple)")
f.StringVarP(&p.namespace, "namespace", "n", "default", "namespace to spray the chart into.")
f.StringVarP(&p.chartVersion, "version", "", "", "specify the exact chart version to install. If this is not specified, the latest version is installed")
f.StringVarP(&p.valuesSet, "set", "", "", "set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
f.BoolVar(&p.dryRun, "dry-run", false, "simulate a spray")
f.BoolVar(&p.debug, "debug", false, "enable verbose output")
f.Parse(args)

if !p.debug {
if "1" == os.Getenv("HELM_DEBUG") {
p.debug = true
}
}

return cmd

}
Expand Down Expand Up @@ -165,16 +174,16 @@ func (p *sprayCmd) spray() error {
}

// For debug...
/*
if p.debug {
for _, dependency := range dependencies {
fmt.Printf("dependencies: %s | %d\n", dependency.Name, dependency.Weight)
}
*/
}

for i := 0; i <= getMaxWeight(dependencies); i++ {
for _, dependency := range dependencies {
if dependency.Weight == i {
helm.UpgradeWithValues(p.namespace, dependency.Name, dependency.Name, p.chartName, p.valuesFile, p.valuesSet, p.dryRun)
helm.UpgradeWithValues(p.namespace, dependency.Name, dependency.Name, p.chartName, p.valueFiles, p.valuesSet, p.dryRun, p.debug)
status := helm.GetHelmStatus(dependency.Name)
if status != "DEPLOYED" && !p.dryRun {
os.Exit(1)
Expand Down
26 changes: 19 additions & 7 deletions pkg/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,20 @@ func Delete(chart string, dryRun bool) {
}

// UpgradeWithValues ...
func UpgradeWithValues(namespace string, release string, chartName string, chartPath string, valuesFile string, valuesSet string, dryRun bool) {
var myargs []string
func UpgradeWithValues(namespace string, release string, chartName string, chartPath string, valueFiles []string, valuesSet string, dryRun bool, debug bool) {
var myargs []string = []string{"upgrade", "--install", release, chartPath, "--namespace", namespace, "--set", chartName + ".enabled=true," + valuesSet}
for _, v := range valueFiles {
myargs = append(myargs, "-f")
myargs = append(myargs, v)
}
if dryRun {
myargs = []string{"upgrade", "--install", release, chartPath, "--namespace", namespace, "-f", valuesFile, "--set", chartName + ".enabled=true," + valuesSet, "--dry-run"}
} else {
myargs = []string{"upgrade", "--install", release, chartPath, "--namespace", namespace, "-f", valuesFile, "--set", chartName + ".enabled=true," + valuesSet}
}
myargs = append(myargs, "--dry-run")
}

if debug {
fmt.Printf("running command for %s: %v\n", release, myargs)
}

cmd := exec.Command("helm", myargs...)
cmdOutput := &bytes.Buffer{}
cmd.Stdout = cmdOutput
Expand All @@ -114,14 +121,19 @@ func UpgradeWithValues(namespace string, release string, chartName string, chart
}

// Upgrade ...
func Upgrade(namespace string, chart string, chartPath string, valuesSet string, dryRun bool) {
func Upgrade(namespace string, chart string, chartPath string, valuesSet string, dryRun bool, debug bool) {

var myargs []string
if dryRun {
myargs = []string{"upgrade", "--install", "--namespace", namespace, "--set", chart + ".enabled=true," + valuesSet, chart, chartPath, "--dry-run"}
} else {
myargs = []string{"upgrade", "--install", "--namespace", namespace, "--set", chart + ".enabled=true," + valuesSet, chart, chartPath}
}

if debug {
fmt.Printf("running command: %v\n", myargs)
}

cmd := exec.Command("helm", myargs...)
cmdOutput := &bytes.Buffer{}
cmd.Stdout = cmdOutput
Expand Down

0 comments on commit 2c13d32

Please sign in to comment.