ref(*): use time.Duration for timeouts

Signed-off-by: Adam Reese <adam@reese.io>
pull/5646/head
Adam Reese 6 years ago
parent 2dd4744d23
commit b97f881be0
No known key found for this signature in database
GPG Key ID: 06F35E60A7A18DD6

@ -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.DryRun, "dry-run", false, "simulate an install")
f.BoolVar(&client.DisableHooks, "no-hooks", false, "prevent hooks from running during 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.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.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.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") f.StringVar(&client.NameTemplate, "name-template", "", "specify template used to name the release")

@ -75,7 +75,7 @@ func TestInstall(t *testing.T) {
// Install, with timeout // Install, with timeout
{ {
name: "install with a 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", golden: "output/install-with-timeout.txt",
}, },
// Install, with wait // Install, with wait

@ -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.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.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.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") 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 return cmd

@ -46,7 +46,7 @@ func TestRollbackCmd(t *testing.T) {
rels: rels, rels: rels,
}, { }, {
name: "rollback a release with timeout", 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", golden: "output/rollback-timeout.txt",
rels: rels, rels: rels,
}, { }, {

@ -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.DryRun, "dry-run", false, "simulate a uninstall")
f.BoolVar(&client.DisableHooks, "no-hooks", false, "prevent hooks from running during uninstallation") 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.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 return cmd
} }

@ -41,7 +41,7 @@ func TestUninstall(t *testing.T) {
}, },
{ {
name: "uninstall with timeout", name: "uninstall with timeout",
cmd: "uninstall aeneas --timeout 120", cmd: "uninstall aeneas --timeout 120s",
golden: "output/uninstall-timeout.txt", golden: "output/uninstall-timeout.txt",
rels: []*release.Release{release.Mock(&release.MockReleaseOptions{Name: "aeneas"})}, rels: []*release.Release{release.Mock(&release.MockReleaseOptions{Name: "aeneas"})},
}, },

@ -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.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.Force, "force", false, "force resource update through delete/recreate if needed")
f.BoolVar(&client.DisableHooks, "no-hooks", false, "disable pre/post upgrade hooks") 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.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.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") 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")

@ -89,7 +89,7 @@ func TestUpgradeCmd(t *testing.T) {
}, },
{ {
name: "upgrade a release with timeout", 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", golden: "output/upgrade-with-timeout.txt",
rels: []*release.Release{relMock("funny-bunny", 3, ch2)}, 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", 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", golden: "output/upgrade-with-install-timeout.txt",
rels: []*release.Release{relMock("crazy-bunny", 1, ch)}, rels: []*release.Release{relMock("crazy-bunny", 1, ch)},
}, },

@ -184,6 +184,6 @@ type hookFailingKubeClient struct {
kube.PrintingKubeClient 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") return errors.New("Failed watch")
} }

@ -74,7 +74,7 @@ type Install struct {
Wait bool Wait bool
Devel bool Devel bool
DependencyUpdate bool DependencyUpdate bool
Timeout int64 Timeout time.Duration
Namespace string Namespace string
ReleaseName string ReleaseName string
GenerateName bool GenerateName bool

@ -35,7 +35,7 @@ type Rollback struct {
cfg *Configuration cfg *Configuration
Version int Version int
Timeout int64 Timeout time.Duration
Wait bool Wait bool
DisableHooks bool DisableHooks bool
DryRun bool DryRun bool

@ -39,7 +39,7 @@ type Uninstall struct {
DisableHooks bool DisableHooks bool
DryRun bool DryRun bool
KeepHistory bool KeepHistory bool
Timeout int64 Timeout time.Duration
} }
// NewUninstall creates a new Uninstall object with the given configuration. // NewUninstall creates a new Uninstall object with the given configuration.

@ -43,7 +43,7 @@ type Upgrade struct {
Install bool Install bool
Devel bool Devel bool
Namespace string Namespace string
Timeout int64 Timeout time.Duration
Wait bool Wait bool
// Values is a string containing (unparsed) YAML values. // Values is a string containing (unparsed) YAML values.
Values map[string]interface{} Values map[string]interface{}
@ -275,8 +275,8 @@ func (u *Upgrade) reuseValues(chart *chart.Chart, current *release.Release) erro
return nil return nil
} }
func validateManifest(c kube.KubernetesClient, ns string, manifest []byte) error { func validateManifest(c kube.KubernetesClient, manifest []byte) error {
_, err := c.BuildUnstructured(ns, bytes.NewReader(manifest)) _, err := c.BuildUnstructured(bytes.NewReader(manifest))
return err return err
} }

@ -100,7 +100,7 @@ func (c *Client) Create(reader io.Reader) error {
return err 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) infos, err := c.BuildUnstructured(reader)
if err != nil { if err != nil {
return err return err
@ -112,7 +112,7 @@ func (c *Client) Wait(reader io.Reader, timeout int64) error {
w := waiter{ w := waiter{
c: cs, c: cs,
log: c.Log, log: c.Log,
timeout: time.Duration(timeout), timeout: timeout,
} }
return w.waitForResources(infos) 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. // ascertained by watching the Status fields in a job's output.
// //
// Handling for other kinds will be added as necessary. // 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) infos, err := c.Build(reader)
if err != nil { if err != nil {
return err return err
} }
// For jobs, there's also the option to do poll c.Jobs(namespace).Get(): // 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 // 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 { func perform(infos Result, fn resourceActorFunc) error {

@ -34,7 +34,7 @@ type KubernetesClient interface {
// by "\n---\n"). // by "\n---\n").
Create(reader io.Reader) error 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 // Get gets one or more resources. Returned string hsa the format like kubectl
// provides with the column headers separating the resource types. // 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 Jobs, "ready" means the job ran to completion (excited without error).
// For all other kinds, it means the kind was created or modified without // For all other kinds, it means the kind was created or modified without
// error. // 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 // Update updates one or more resources or creates the resource
// if it doesn't exist. // if it doesn't exist.
@ -83,7 +83,7 @@ func (p *PrintingKubeClient) Create(r io.Reader) error {
return err 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) _, err := io.Copy(p.Out, r)
return err return err
} }
@ -103,7 +103,7 @@ func (p *PrintingKubeClient) Delete(r io.Reader) error {
} }
// WatchUntilReady implements KubeClient WatchUntilReady. // 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) _, err := io.Copy(p.Out, r)
return err return err
} }

@ -28,7 +28,7 @@ import (
type mockKubeClient struct{} type mockKubeClient struct{}
func (k *mockKubeClient) Wait(r io.Reader, _ int64) error { func (k *mockKubeClient) Wait(r io.Reader, _ time.Duration) error {
return nil return nil
} }
func (k *mockKubeClient) Create(r io.Reader) error { 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 { func (k *mockKubeClient) Update(currentReader, modifiedReader io.Reader, force, recreate bool) error {
return nil 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 return nil
} }
func (k *mockKubeClient) Build(reader io.Reader) (Result, error) { func (k *mockKubeClient) Build(reader io.Reader) (Result, error) {

Loading…
Cancel
Save