mirror of https://github.com/helm/helm.git
ref(*): use time.Duration for timeouts
Signed-off-by: Adam Reese <adam@reese.io>
This commit is contained in:
parent
2dd4744d23
commit
b97f881be0
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
}, {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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"})},
|
||||
},
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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)},
|
||||
},
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ type Install struct {
|
|||
Wait bool
|
||||
Devel bool
|
||||
DependencyUpdate bool
|
||||
Timeout int64
|
||||
Timeout time.Duration
|
||||
Namespace string
|
||||
ReleaseName string
|
||||
GenerateName bool
|
||||
|
|
|
@ -35,7 +35,7 @@ type Rollback struct {
|
|||
cfg *Configuration
|
||||
|
||||
Version int
|
||||
Timeout int64
|
||||
Timeout time.Duration
|
||||
Wait bool
|
||||
DisableHooks bool
|
||||
DryRun bool
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue