diff --git a/cmd/fluxctl/await.go b/cmd/fluxctl/await.go index bb1cc4bdd..f043084d6 100644 --- a/cmd/fluxctl/await.go +++ b/cmd/fluxctl/await.go @@ -16,7 +16,7 @@ var ErrTimeout = errors.New("timeout") // await polls for a job to complete, then for the resulting commit to // be applied -func await(ctx context.Context, stdout, stderr io.Writer, client api.Server, jobID job.ID, apply bool, verbosity int, timeout int) error { +func await(ctx context.Context, stdout, stderr io.Writer, client api.Server, jobID job.ID, apply bool, verbosity int, timeout time.Duration) error { result, err := awaitJob(ctx, client, jobID, timeout) if err != nil { if err == ErrTimeout { @@ -61,9 +61,9 @@ to run a sync interactively.`) } // await polls for a job to have been completed, with exponential backoff. -func awaitJob(ctx context.Context, client api.Server, jobID job.ID, timeout int) (job.Result, error) { +func awaitJob(ctx context.Context, client api.Server, jobID job.ID, timeout time.Duration) (job.Result, error) { var result job.Result - err := backoff(100*time.Millisecond, 2, 50, time.Duration(timeout)*time.Second, func() (bool, error) { + err := backoff(100*time.Millisecond, 2, 50, timeout, func() (bool, error) { j, err := client.JobStatus(ctx, jobID) if err != nil { return false, err @@ -86,8 +86,8 @@ func awaitJob(ctx context.Context, client api.Server, jobID job.ID, timeout int) } // await polls for a commit to have been applied, with exponential backoff. -func awaitSync(ctx context.Context, client api.Server, revision string, timeout int) error { - return backoff(1*time.Second, 2, 10, time.Duration(timeout)*time.Second, func() (bool, error) { +func awaitSync(ctx context.Context, client api.Server, revision string, timeout time.Duration) error { + return backoff(1*time.Second, 2, 10, timeout, func() (bool, error) { refs, err := client.SyncStatus(ctx, revision) return err == nil && len(refs) == 0, err }) diff --git a/cmd/fluxctl/root_cmd.go b/cmd/fluxctl/root_cmd.go index 6678a9848..d9c7f54a7 100644 --- a/cmd/fluxctl/root_cmd.go +++ b/cmd/fluxctl/root_cmd.go @@ -6,6 +6,7 @@ import ( "net/url" "os" "strings" + "time" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -23,7 +24,7 @@ type rootOpts struct { Namespace string Labels map[string]string API api.Server - Timeout int + Timeout time.Duration } func newRoot() *rootOpts { @@ -77,9 +78,8 @@ func (opts *rootOpts) Command() *cobra.Command { fmt.Sprintf("Base URL of the Flux API (defaults to %q if a token is provided); you can also set the environment variable %s", defaultURLGivenToken, envVariableURL)) cmd.PersistentFlags().StringVarP(&opts.Token, "token", "t", "", fmt.Sprintf("Weave Cloud authentication token; you can also set the environment variable %s or %s", envVariableCloudToken, envVariableToken)) - cmd.PersistentFlags().IntVar(&opts.Timeout, "timeout", 60, - fmt.Sprintf("Global command timeout, in seconds; you can also set the environment variable %s", envVariableTimeout)) - + cmd.PersistentFlags().DurationVar(&opts.Timeout, "timeout", 60*time.Second, + fmt.Sprintf("Global command timeout; you can also set the environment variable %s", envVariableTimeout)) cmd.AddCommand( newVersionCommand(), newImageList(opts).Command(),