diff --git a/README.md b/README.md index 72f6e5a..3700b5b 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ pipeline: values: secret.password=${SECRET_PASSWORD},image.tag=${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7} prefix: STAGING debug: true + wait: true when: branch: [master] ``` @@ -66,6 +67,7 @@ pipeline: values: secret.password=${SECRET_PASSWORD},image.tag=${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7} prefix: STAGING debug: true + wait: true when: branch: exclude: [ master ] @@ -79,6 +81,7 @@ pipeline_production: values: secret.password=${SECRET_PASSWORD},image.tag=${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7} prefix: PROD debug: true + wait: true when: branch: [master] ``` diff --git a/main.go b/main.go index d086da1..dad6834 100644 --- a/main.go +++ b/main.go @@ -73,6 +73,11 @@ func main() { Usage: "Namespace to install Tiller", EnvVar: "PLUGIN_TILLER_NS,TILLER_NS", }, + cli.BoolFlag{ + Name: "wait", + Usage: "if set, will wait until all Pods, PVCs, and Services are in a ready state before marking the release as successful.", + EnvVar: "PLUGIN_WAIT,WAIT", + }, } if err := app.Run(os.Args); err != nil { logrus.Fatal(err) @@ -99,6 +104,7 @@ func run(c *cli.Context) error { Secrets: c.StringSlice("secrets"), Prefix: c.String("prefix"), TillerNs: c.String("tiller-ns"), + Wait: c.Bool("wait"), }, } resolveSecrets(&plugin) diff --git a/plugin.go b/plugin.go index e6dafb6..6ef6343 100644 --- a/plugin.go +++ b/plugin.go @@ -32,6 +32,7 @@ type ( Secrets []string `json:"secrets"` Prefix string `json:"prefix"` TillerNs string `json:"tiller_ns"` + Wait bool `json:"wait"` } // Plugin default Plugin struct { @@ -64,10 +65,10 @@ func setPushEventCommand(p *Plugin) { upgrade = append(upgrade, p.Config.Values) } if p.Config.ValuesFiles != "" { - for _, valuesFile := range strings.Split(p.Config.ValuesFiles, ",") { - upgrade = append(upgrade, "--values") - upgrade = append(upgrade, valuesFile) - } + for _, valuesFile := range strings.Split(p.Config.ValuesFiles, ",") { + upgrade = append(upgrade, "--values") + upgrade = append(upgrade, valuesFile) + } } if p.Config.Namespace != "" { upgrade = append(upgrade, "--namespace") @@ -79,6 +80,9 @@ func setPushEventCommand(p *Plugin) { if p.Config.Debug { upgrade = append(upgrade, "--debug") } + if p.Config.Wait { + upgrade = append(upgrade, "--wait") + } p.Config.HelmCommand = upgrade } diff --git a/plugin_test.go b/plugin_test.go index 1a9f280..8b17f88 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -54,11 +54,12 @@ func TestGetHelmCommand(t *testing.T) { Chart: "./chart/test", Release: "test-release", Values: "image.tag=v.0.1.0,nameOverride=my-over-app", + Wait: true, }, } setHelmCommand(plugin) res := strings.Join(plugin.Config.HelmCommand[:], " ") - expected := "upgrade --install test-release ./chart/test --set image.tag=v.0.1.0,nameOverride=my-over-app --namespace default --dry-run --debug" + expected := "upgrade --install test-release ./chart/test --set image.tag=v.0.1.0,nameOverride=my-over-app --namespace default --dry-run --debug --wait" if res != expected { t.Errorf("Result is %s and we expected %s", res, expected) }