From fa10cc96304ac1eebf1f1339dc4de560d5790a0a Mon Sep 17 00:00:00 2001 From: "Eric.Runquist" Date: Thu, 16 Feb 2017 13:46:06 -0600 Subject: [PATCH 1/3] Updated to helm 2.2.0. Added support for a values file. --- Dockerfile | 7 ++++++- main.go | 8 +++++++- plugin.go | 16 +++++++++++++--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8bad909..49527dd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,12 @@ MAINTAINER Ivan Pedrazas RUN apk -Uuv add curl bash && rm /var/cache/apk/* -ENV VERSION v2.1.3 +#WORKS: +ENV VERSION v2.2.0 + +# Does not support the --tiller-namespace option to upgrade command! +#ENV VERSION v2.1.3 + ENV FILENAME helm-${VERSION}-linux-amd64.tar.gz ENV KUBECTL v1.5.2 diff --git a/main.go b/main.go index 8aec948..7ea1df5 100644 --- a/main.go +++ b/main.go @@ -43,6 +43,11 @@ func main() { Usage: "Kubernetes helm release", EnvVar: "PLUGIN_VALUES,VALUES", }, + cli.StringFlag{ + Name: "values_file", + Usage: "Kubernetes helm release", + EnvVar: "PLUGIN_VALUES_FILE,VALUES_FILE", + }, cli.BoolFlag{ Name: "skip_tls_verify", Usage: "Skip TLS verification", @@ -86,13 +91,14 @@ func run(c *cli.Context) error { Namespace: c.String("namespace"), SkipTLSVerify: c.Bool("skip_tls_verify"), Values: c.String("values"), + ValuesFile: c.String("values_file"), Release: c.String("release"), Chart: c.String("chart"), Debug: c.Bool("debug"), DryRun: c.Bool("dry-run"), Secrets: c.StringSlice("secrets"), Prefix: c.String("prefix"), - TillerNs: c.String("tiller_ns"), + TillerNs: c.String("tiller-ns"), }, } resolveSecrets(&plugin) diff --git a/plugin.go b/plugin.go index f0bc4c0..910c80a 100644 --- a/plugin.go +++ b/plugin.go @@ -26,6 +26,7 @@ type ( Release string `json:"release"` Chart string `json:"chart"` Values string `json:"values"` + ValuesFile string `json:"values_file"` Debug bool `json:"debug"` DryRun bool `json:"dry_run"` Secrets []string `json:"secrets"` @@ -62,10 +63,18 @@ func setPushEventCommand(p *Plugin) { upgrade = append(upgrade, "--set") upgrade = append(upgrade, p.Config.Values) } + if p.Config.ValuesFile != "" { + upgrade = append(upgrade, "--values") + upgrade = append(upgrade, p.Config.ValuesFile) + } if p.Config.Namespace != "" { upgrade = append(upgrade, "--namespace") upgrade = append(upgrade, p.Config.Namespace) } + if p.Config.TillerNs != "" { + upgrade = append(upgrade, "--tiller-namespace") + upgrade = append(upgrade, p.Config.TillerNs) + } if p.Config.DryRun { upgrade = append(upgrade, "--dry-run") } @@ -118,7 +127,7 @@ func (p *Plugin) Exec() error { init := doHelmInit(p) err := runCommand(init) if err != nil { - return fmt.Errorf("Error running helm comand: " + strings.Join(init[:], " ")) + return fmt.Errorf("Error running helm command: " + strings.Join(init[:], " ")) } setHelmCommand(p) @@ -127,7 +136,7 @@ func (p *Plugin) Exec() error { } err = runCommand(p.Config.HelmCommand) if err != nil { - return fmt.Errorf("Error running helm comand: " + strings.Join(p.Config.HelmCommand[:], " ")) + return fmt.Errorf("Error running helm command: " + strings.Join(p.Config.HelmCommand[:], " ")) } return nil } @@ -193,7 +202,8 @@ func (p *Plugin) debug() { // debug plugin obj fmt.Printf("Api server: %s \n", p.Config.APIServer) fmt.Printf("Values: %s \n", p.Config.Values) - fmt.Printf("Values: %s \n", p.Config.Secrets) + fmt.Printf("Secrets: %s \n", p.Config.Secrets) + fmt.Printf("ValuesFile: %s \n", p.Config.ValuesFile) kubeconfig, err := ioutil.ReadFile(KUBECONFIG) if err == nil { From fafea7378054091bade344c6032e2e45d9c14355 Mon Sep 17 00:00:00 2001 From: "Eric.Runquist" Date: Thu, 16 Feb 2017 14:26:20 -0600 Subject: [PATCH 2/3] Added support for multiple values files. --- build.sh | 8 ++++++++ main.go | 8 ++++---- plugin.go | 12 +++++++----- 3 files changed, 19 insertions(+), 9 deletions(-) create mode 100755 build.sh diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..661d40b --- /dev/null +++ b/build.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +set -e + +export GOOS=linux +export GOARCH=386 +go build +docker build -t drone-helm . diff --git a/main.go b/main.go index 7ea1df5..d086da1 100644 --- a/main.go +++ b/main.go @@ -44,9 +44,9 @@ func main() { EnvVar: "PLUGIN_VALUES,VALUES", }, cli.StringFlag{ - Name: "values_file", - Usage: "Kubernetes helm release", - EnvVar: "PLUGIN_VALUES_FILE,VALUES_FILE", + Name: "values_files", + Usage: "Helm values override files", + EnvVar: "PLUGIN_VALUES_FILES,VALUES_FILES", }, cli.BoolFlag{ Name: "skip_tls_verify", @@ -91,7 +91,7 @@ func run(c *cli.Context) error { Namespace: c.String("namespace"), SkipTLSVerify: c.Bool("skip_tls_verify"), Values: c.String("values"), - ValuesFile: c.String("values_file"), + ValuesFiles: c.String("values_files"), Release: c.String("release"), Chart: c.String("chart"), Debug: c.Bool("debug"), diff --git a/plugin.go b/plugin.go index 910c80a..d58af01 100644 --- a/plugin.go +++ b/plugin.go @@ -26,7 +26,7 @@ type ( Release string `json:"release"` Chart string `json:"chart"` Values string `json:"values"` - ValuesFile string `json:"values_file"` + ValuesFiles string `json:"values_files"` Debug bool `json:"debug"` DryRun bool `json:"dry_run"` Secrets []string `json:"secrets"` @@ -63,9 +63,11 @@ func setPushEventCommand(p *Plugin) { upgrade = append(upgrade, "--set") upgrade = append(upgrade, p.Config.Values) } - if p.Config.ValuesFile != "" { - upgrade = append(upgrade, "--values") - upgrade = append(upgrade, p.Config.ValuesFile) + if p.Config.ValuesFiles != "" { + for _, valuesFile := range strings.Split(p.Config.ValuesFiles, ",") { + upgrade = append(upgrade, "--values") + upgrade = append(upgrade, valuesFile) + } } if p.Config.Namespace != "" { upgrade = append(upgrade, "--namespace") @@ -203,7 +205,7 @@ func (p *Plugin) debug() { fmt.Printf("Api server: %s \n", p.Config.APIServer) fmt.Printf("Values: %s \n", p.Config.Values) fmt.Printf("Secrets: %s \n", p.Config.Secrets) - fmt.Printf("ValuesFile: %s \n", p.Config.ValuesFile) + fmt.Printf("ValuesFiles: %s \n", p.Config.ValuesFiles) kubeconfig, err := ioutil.ReadFile(KUBECONFIG) if err == nil { From 572504a34ab309bd4d21c66a662d7b4d75651432 Mon Sep 17 00:00:00 2001 From: "Eric.Runquist" Date: Fri, 17 Feb 2017 10:19:24 -0600 Subject: [PATCH 3/3] Backed out tiller namespace option on helm upgrade. Switched back to helm 2.1.3. --- Dockerfile | 7 +------ plugin.go | 4 ---- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 49527dd..8bad909 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,12 +4,7 @@ MAINTAINER Ivan Pedrazas RUN apk -Uuv add curl bash && rm /var/cache/apk/* -#WORKS: -ENV VERSION v2.2.0 - -# Does not support the --tiller-namespace option to upgrade command! -#ENV VERSION v2.1.3 - +ENV VERSION v2.1.3 ENV FILENAME helm-${VERSION}-linux-amd64.tar.gz ENV KUBECTL v1.5.2 diff --git a/plugin.go b/plugin.go index d58af01..e6dafb6 100644 --- a/plugin.go +++ b/plugin.go @@ -73,10 +73,6 @@ func setPushEventCommand(p *Plugin) { upgrade = append(upgrade, "--namespace") upgrade = append(upgrade, p.Config.Namespace) } - if p.Config.TillerNs != "" { - upgrade = append(upgrade, "--tiller-namespace") - upgrade = append(upgrade, p.Config.TillerNs) - } if p.Config.DryRun { upgrade = append(upgrade, "--dry-run") }