From fcb3eeb85634068dc23ac776b86abd7986086c83 Mon Sep 17 00:00:00 2001 From: Kevin Tsai Date: Wed, 28 Jun 2017 21:12:49 +0900 Subject: [PATCH] support timeout --- main.go | 6 ++++++ plugin.go | 5 +++++ plugin_test.go | 3 ++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index e836586..5521812 100644 --- a/main.go +++ b/main.go @@ -98,6 +98,11 @@ func main() { Usage: "when upgrading, reuse the last release's values, and merge in any new values", EnvVar: "PLUGIN_REUSE_VALUES,REUSE_VALUES", }, + cli.StringFlag{ + Name: "timeout", + Usage: "time in seconds to wait for any individual kubernetes operation (like Jobs for hooks) (default 300)", + EnvVar: "PLUGIN_TIMEOUT,TIMEOUT", + }, } if err := app.Run(os.Args); err != nil { logrus.Fatal(err) @@ -129,6 +134,7 @@ func run(c *cli.Context) error { ClientOnly: c.Bool("client-only"), Upgrade: c.Bool("upgrade"), ReuseValues: c.Bool("reuse-values"), + Timeout: c.String("timeout"), }, } resolveSecrets(&plugin) diff --git a/plugin.go b/plugin.go index 0755b36..066bb8e 100644 --- a/plugin.go +++ b/plugin.go @@ -38,6 +38,7 @@ type ( Upgrade bool `json:"upgrade"` ClientOnly bool `json:"client_only"` ReuseValues bool `json:"reuse_values"` + Timeout string `json:"timeout"` } // Plugin default Plugin struct { @@ -98,6 +99,10 @@ func setPushEventCommand(p *Plugin) { if p.Config.ReuseValues { upgrade = append(upgrade, "--reuse-values") } + if p.Config.Timeout != "" { + upgrade = append(upgrade, "--timeout") + upgrade = append(upgrade, p.Config.Timeout) + } p.Config.HelmCommand = upgrade } diff --git a/plugin_test.go b/plugin_test.go index fe52f4b..3a19636 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -56,11 +56,12 @@ func TestGetHelmCommand(t *testing.T) { Values: "image.tag=v.0.1.0,nameOverride=my-over-app", Wait: true, ReuseValues: true, + Timeout: "500", }, } 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 --wait --reuse-values" + expected := "upgrade --install test-release ./chart/test --set image.tag=v.0.1.0,nameOverride=my-over-app --namespace default --dry-run --debug --wait --reuse-values --timeout 500" if res != expected { t.Errorf("Result is %s and we expected %s", res, expected) }