diff --git a/cmd/helm/install.go b/cmd/helm/install.go index b0f8919d2..61ba90084 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -121,7 +121,7 @@ func addInstallFlags(f *pflag.FlagSet, client *action.Install) { f.BoolVar(&client.DryRun, "dry-run", false, "simulate an install") f.BoolVar(&client.DisableHooks, "no-hooks", false, "prevent hooks from running during install") f.BoolVar(&client.Replace, "replace", false, "re-use the given name, even if that name is already used. This is unsafe in production") - f.Int64Var(&client.Timeout, "timeout", 300, "time in seconds to wait for any individual Kubernetes operation (like Jobs for hooks)") + f.DurationVar(&client.Timeout, "timeout", 300, "time to wait for any individual Kubernetes operation (like Jobs for hooks)") f.BoolVar(&client.Wait, "wait", false, "if set, will wait until all Pods, PVCs, Services, and minimum number of Pods of a Deployment are in a ready state before marking the release as successful. It will wait for as long as --timeout") f.BoolVarP(&client.GenerateName, "generate-name", "g", false, "generate the name (and omit the NAME parameter)") f.StringVar(&client.NameTemplate, "name-template", "", "specify template used to name the release") diff --git a/cmd/helm/install_test.go b/cmd/helm/install_test.go index f6da14496..20571867f 100644 --- a/cmd/helm/install_test.go +++ b/cmd/helm/install_test.go @@ -75,7 +75,7 @@ func TestInstall(t *testing.T) { // Install, with timeout { name: "install with a timeout", - cmd: "install foobar testdata/testcharts/empty --timeout 120", + cmd: "install foobar testdata/testcharts/empty --timeout 120s", golden: "output/install-with-timeout.txt", }, // Install, with wait diff --git a/cmd/helm/rollback.go b/cmd/helm/rollback.go index 3da4231ab..a46ee8b9d 100644 --- a/cmd/helm/rollback.go +++ b/cmd/helm/rollback.go @@ -60,7 +60,7 @@ func newRollbackCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { f.BoolVar(&client.Recreate, "recreate-pods", false, "performs pods restart for the resource if applicable") f.BoolVar(&client.Force, "force", false, "force resource update through delete/recreate if needed") f.BoolVar(&client.DisableHooks, "no-hooks", false, "prevent hooks from running during rollback") - f.Int64Var(&client.Timeout, "timeout", 300, "time in seconds to wait for any individual Kubernetes operation (like Jobs for hooks)") + f.DurationVar(&client.Timeout, "timeout", 300, "time to wait for any individual Kubernetes operation (like Jobs for hooks)") f.BoolVar(&client.Wait, "wait", false, "if set, will wait until all Pods, PVCs, Services, and minimum number of Pods of a Deployment are in a ready state before marking the release as successful. It will wait for as long as --timeout") return cmd diff --git a/cmd/helm/rollback_test.go b/cmd/helm/rollback_test.go index 42763d298..6283f6f20 100644 --- a/cmd/helm/rollback_test.go +++ b/cmd/helm/rollback_test.go @@ -46,7 +46,7 @@ func TestRollbackCmd(t *testing.T) { rels: rels, }, { name: "rollback a release with timeout", - cmd: "rollback funny-honey 1 --timeout 120", + cmd: "rollback funny-honey 1 --timeout 120s", golden: "output/rollback-timeout.txt", rels: rels, }, { diff --git a/cmd/helm/uninstall.go b/cmd/helm/uninstall.go index 37da40666..814237a55 100644 --- a/cmd/helm/uninstall.go +++ b/cmd/helm/uninstall.go @@ -67,7 +67,7 @@ func newUninstallCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { f.BoolVar(&client.DryRun, "dry-run", false, "simulate a uninstall") f.BoolVar(&client.DisableHooks, "no-hooks", false, "prevent hooks from running during uninstallation") f.BoolVar(&client.KeepHistory, "keep-history", false, "remove all associated resources and mark the release as deleted, but retain the release history") - f.Int64Var(&client.Timeout, "timeout", 300, "time in seconds to wait for any individual Kubernetes operation (like Jobs for hooks)") + f.DurationVar(&client.Timeout, "timeout", 300, "time to wait for any individual Kubernetes operation (like Jobs for hooks)") return cmd } diff --git a/cmd/helm/uninstall_test.go b/cmd/helm/uninstall_test.go index 409019a3c..2681dc447 100644 --- a/cmd/helm/uninstall_test.go +++ b/cmd/helm/uninstall_test.go @@ -41,7 +41,7 @@ func TestUninstall(t *testing.T) { }, { name: "uninstall with timeout", - cmd: "uninstall aeneas --timeout 120", + cmd: "uninstall aeneas --timeout 120s", golden: "output/uninstall-timeout.txt", rels: []*release.Release{release.Mock(&release.MockReleaseOptions{Name: "aeneas"})}, }, diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go index 7a5aebdbc..efc472d9e 100644 --- a/cmd/helm/upgrade.go +++ b/cmd/helm/upgrade.go @@ -142,7 +142,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { f.BoolVar(&client.Recreate, "recreate-pods", false, "performs pods restart for the resource if applicable") f.BoolVar(&client.Force, "force", false, "force resource update through delete/recreate if needed") f.BoolVar(&client.DisableHooks, "no-hooks", false, "disable pre/post upgrade hooks") - f.Int64Var(&client.Timeout, "timeout", 300, "time in seconds to wait for any individual Kubernetes operation (like Jobs for hooks)") + f.DurationVar(&client.Timeout, "timeout", 300, "time to wait for any individual Kubernetes operation (like Jobs for hooks)") f.BoolVar(&client.ResetValues, "reset-values", false, "when upgrading, reset the values to the ones built into the chart") f.BoolVar(&client.ReuseValues, "reuse-values", false, "when upgrading, reuse the last release's values and merge in any overrides from the command line via --set and -f. If '--reset-values' is specified, this is ignored.") f.BoolVar(&client.Wait, "wait", false, "if set, will wait until all Pods, PVCs, Services, and minimum number of Pods of a Deployment are in a ready state before marking the release as successful. It will wait for as long as --timeout") diff --git a/cmd/helm/upgrade_test.go b/cmd/helm/upgrade_test.go index d8f9d5bf0..1d8dc0317 100644 --- a/cmd/helm/upgrade_test.go +++ b/cmd/helm/upgrade_test.go @@ -89,7 +89,7 @@ func TestUpgradeCmd(t *testing.T) { }, { name: "upgrade a release with timeout", - cmd: fmt.Sprintf("upgrade funny-bunny --timeout 120 '%s'", chartPath), + cmd: fmt.Sprintf("upgrade funny-bunny --timeout 120s '%s'", chartPath), golden: "output/upgrade-with-timeout.txt", rels: []*release.Release{relMock("funny-bunny", 3, ch2)}, }, @@ -113,7 +113,7 @@ func TestUpgradeCmd(t *testing.T) { }, { name: "install a release with 'upgrade --install' and timeout", - cmd: fmt.Sprintf("upgrade crazy-bunny -i --timeout 120 '%s'", chartPath), + cmd: fmt.Sprintf("upgrade crazy-bunny -i --timeout 120s '%s'", chartPath), golden: "output/upgrade-with-install-timeout.txt", rels: []*release.Release{relMock("crazy-bunny", 1, ch)}, }, diff --git a/pkg/action/action_test.go b/pkg/action/action_test.go index 9b6e70615..cab02a9c4 100644 --- a/pkg/action/action_test.go +++ b/pkg/action/action_test.go @@ -184,6 +184,6 @@ type hookFailingKubeClient struct { kube.PrintingKubeClient } -func (h *hookFailingKubeClient) WatchUntilReady(r io.Reader, timeout int64) error { +func (h *hookFailingKubeClient) WatchUntilReady(r io.Reader, timeout time.Duration) error { return errors.New("Failed watch") } diff --git a/pkg/action/install.go b/pkg/action/install.go index a26935e8e..581cbcde7 100644 --- a/pkg/action/install.go +++ b/pkg/action/install.go @@ -74,7 +74,7 @@ type Install struct { Wait bool Devel bool DependencyUpdate bool - Timeout int64 + Timeout time.Duration Namespace string ReleaseName string GenerateName bool diff --git a/pkg/action/rollback.go b/pkg/action/rollback.go index 23fd57302..e3fcfee04 100644 --- a/pkg/action/rollback.go +++ b/pkg/action/rollback.go @@ -35,7 +35,7 @@ type Rollback struct { cfg *Configuration Version int - Timeout int64 + Timeout time.Duration Wait bool DisableHooks bool DryRun bool diff --git a/pkg/action/uninstall.go b/pkg/action/uninstall.go index a23f0b1c1..f07b23ec1 100644 --- a/pkg/action/uninstall.go +++ b/pkg/action/uninstall.go @@ -39,7 +39,7 @@ type Uninstall struct { DisableHooks bool DryRun bool KeepHistory bool - Timeout int64 + Timeout time.Duration } // NewUninstall creates a new Uninstall object with the given configuration. diff --git a/pkg/action/upgrade.go b/pkg/action/upgrade.go index 1d4f10d01..07ad5606a 100644 --- a/pkg/action/upgrade.go +++ b/pkg/action/upgrade.go @@ -43,7 +43,7 @@ type Upgrade struct { Install bool Devel bool Namespace string - Timeout int64 + Timeout time.Duration Wait bool // Values is a string containing (unparsed) YAML values. Values map[string]interface{} @@ -275,8 +275,8 @@ func (u *Upgrade) reuseValues(chart *chart.Chart, current *release.Release) erro return nil } -func validateManifest(c kube.KubernetesClient, ns string, manifest []byte) error { - _, err := c.BuildUnstructured(ns, bytes.NewReader(manifest)) +func validateManifest(c kube.KubernetesClient, manifest []byte) error { + _, err := c.BuildUnstructured(bytes.NewReader(manifest)) return err } diff --git a/pkg/kube/client.go b/pkg/kube/client.go index 815039b9c..52bff7e3f 100644 --- a/pkg/kube/client.go +++ b/pkg/kube/client.go @@ -100,7 +100,7 @@ func (c *Client) Create(reader io.Reader) error { return err } -func (c *Client) Wait(reader io.Reader, timeout int64) error { +func (c *Client) Wait(reader io.Reader, timeout time.Duration) error { infos, err := c.BuildUnstructured(reader) if err != nil { return err @@ -112,7 +112,7 @@ func (c *Client) Wait(reader io.Reader, timeout int64) error { w := waiter{ c: cs, log: c.Log, - timeout: time.Duration(timeout), + timeout: timeout, } return w.waitForResources(infos) } @@ -354,14 +354,14 @@ func (c *Client) watchTimeout(t time.Duration) resourceActorFunc { // ascertained by watching the Status fields in a job's output. // // Handling for other kinds will be added as necessary. -func (c *Client) WatchUntilReady(reader io.Reader, timeout int64) error { +func (c *Client) WatchUntilReady(reader io.Reader, timeout time.Duration) error { infos, err := c.Build(reader) if err != nil { return err } // For jobs, there's also the option to do poll c.Jobs(namespace).Get(): // https://github.com/adamreese/kubernetes/blob/master/test/e2e/job.go#L291-L300 - return perform(infos, c.watchTimeout(time.Duration(timeout)*time.Second)) + return perform(infos, c.watchTimeout(timeout)) } func perform(infos Result, fn resourceActorFunc) error { diff --git a/pkg/kube/printer.go b/pkg/kube/printer.go index ad5bb513c..1a9a8daee 100644 --- a/pkg/kube/printer.go +++ b/pkg/kube/printer.go @@ -34,7 +34,7 @@ type KubernetesClient interface { // by "\n---\n"). Create(reader io.Reader) error - Wait(r io.Reader, timeout int64) error + Wait(r io.Reader, timeout time.Duration) error // Get gets one or more resources. Returned string hsa the format like kubectl // provides with the column headers separating the resource types. @@ -54,7 +54,7 @@ type KubernetesClient interface { // For Jobs, "ready" means the job ran to completion (excited without error). // For all other kinds, it means the kind was created or modified without // error. - WatchUntilReady(reader io.Reader, timeout int64) error + WatchUntilReady(reader io.Reader, timeout time.Duration) error // Update updates one or more resources or creates the resource // if it doesn't exist. @@ -83,7 +83,7 @@ func (p *PrintingKubeClient) Create(r io.Reader) error { return err } -func (p *PrintingKubeClient) Wait(r io.Reader, timeout int64) error { +func (p *PrintingKubeClient) Wait(r io.Reader, timeout time.Duration) error { _, err := io.Copy(p.Out, r) return err } @@ -103,7 +103,7 @@ func (p *PrintingKubeClient) Delete(r io.Reader) error { } // WatchUntilReady implements KubeClient WatchUntilReady. -func (p *PrintingKubeClient) WatchUntilReady(r io.Reader, timeout int64) error { +func (p *PrintingKubeClient) WatchUntilReady(r io.Reader, timeout time.Duration) error { _, err := io.Copy(p.Out, r) return err } diff --git a/pkg/kube/printer_test.go b/pkg/kube/printer_test.go index da9403dde..876b280bb 100644 --- a/pkg/kube/printer_test.go +++ b/pkg/kube/printer_test.go @@ -28,7 +28,7 @@ import ( type mockKubeClient struct{} -func (k *mockKubeClient) Wait(r io.Reader, _ int64) error { +func (k *mockKubeClient) Wait(r io.Reader, _ time.Duration) error { return nil } func (k *mockKubeClient) Create(r io.Reader) error { @@ -43,7 +43,7 @@ func (k *mockKubeClient) Delete(r io.Reader) error { func (k *mockKubeClient) Update(currentReader, modifiedReader io.Reader, force, recreate bool) error { return nil } -func (k *mockKubeClient) WatchUntilReady(r io.Reader, timeout int64) error { +func (k *mockKubeClient) WatchUntilReady(r io.Reader, timeout time.Duration) error { return nil } func (k *mockKubeClient) Build(reader io.Reader) (Result, error) {