From 3e4c2286380b60d2b8a9b8e71deeb6cf6a02d76d Mon Sep 17 00:00:00 2001 From: Sirajudeen Date: Fri, 25 Sep 2020 03:11:16 +0000 Subject: [PATCH] Add timeout flag for phase run in cli Syntax: airshipctl phase run --timeout Exmaple: airshipctl phase run initinfra-ephemeral --debug --wait-timeout 1000s Change-Id: Ic8c699f5302eb482f32aee0e7d7c593df2ed7d3b --- cmd/phase/run.go | 5 +++++ .../testdata/TestRunGoldenOutput/run-with-help.golden | 5 +++-- docs/source/cli/airshipctl_phase_run.md | 5 +++-- pkg/k8s/applier/executor.go | 8 +++++++- pkg/phase/command.go | 4 +++- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/cmd/phase/run.go b/cmd/phase/run.go index 697607f09..6141f952a 100644 --- a/cmd/phase/run.go +++ b/cmd/phase/run.go @@ -55,5 +55,10 @@ func NewRunCommand(cfgFactory config.Factory) *cobra.Command { "dry-run", false, "simulate phase execution") + flags.DurationVar( + &p.Options.Timeout, + "wait-timeout", + 0, + "wait timeout") return runCmd } diff --git a/cmd/phase/testdata/TestRunGoldenOutput/run-with-help.golden b/cmd/phase/testdata/TestRunGoldenOutput/run-with-help.golden index f55613edc..229e1dd2f 100644 --- a/cmd/phase/testdata/TestRunGoldenOutput/run-with-help.golden +++ b/cmd/phase/testdata/TestRunGoldenOutput/run-with-help.golden @@ -10,5 +10,6 @@ airshipctl phase run ephemeral-control-plane Flags: - --dry-run simulate phase execution - -h, --help help for run + --dry-run simulate phase execution + -h, --help help for run + --wait-timeout duration wait timeout diff --git a/docs/source/cli/airshipctl_phase_run.md b/docs/source/cli/airshipctl_phase_run.md index 247343b49..5f8f793da 100644 --- a/docs/source/cli/airshipctl_phase_run.md +++ b/docs/source/cli/airshipctl_phase_run.md @@ -22,8 +22,9 @@ airshipctl phase run ephemeral-control-plane ### Options ``` - --dry-run simulate phase execution - -h, --help help for run + --dry-run simulate phase execution + -h, --help help for run + --wait-timeout duration wait timeout ``` ### Options inherited from parent commands diff --git a/pkg/k8s/applier/executor.go b/pkg/k8s/applier/executor.go index ae3d08ee6..3391f9a50 100644 --- a/pkg/k8s/applier/executor.go +++ b/pkg/k8s/applier/executor.go @@ -104,11 +104,17 @@ func (e *Executor) Run(ch chan events.Event, runOpts ifc.RunOptions) { if runOpts.DryRun { dryRunStrategy = common.DryRunClient } + timeout := time.Second * time.Duration(e.apiObject.Config.WaitOptions.Timeout) + if int64(runOpts.Timeout/time.Second) != 0 { + timeout = runOpts.Timeout + } + + log.Debugf("WaitTimeout: %v", timeout) applyOptions := ApplyOptions{ DryRunStrategy: dryRunStrategy, Prune: e.apiObject.Config.PruneOptions.Prune, BundleName: e.Options.BundleName, - WaitTimeout: time.Second * time.Duration(e.apiObject.Config.WaitOptions.Timeout), + WaitTimeout: timeout, } applier.ApplyBundle(filteredBundle, applyOptions) } diff --git a/pkg/phase/command.go b/pkg/phase/command.go index 50618cc21..3a99db012 100644 --- a/pkg/phase/command.go +++ b/pkg/phase/command.go @@ -16,6 +16,7 @@ package phase import ( "io" + "time" "opendev.org/airship/airshipctl/pkg/config" "opendev.org/airship/airshipctl/pkg/phase/ifc" @@ -24,6 +25,7 @@ import ( // RunFlags options for phase run command type RunFlags struct { DryRun bool + Timeout time.Duration PhaseID ifc.ID } @@ -51,7 +53,7 @@ func (c *RunCommand) RunE() error { if err != nil { return err } - return phase.Run(ifc.RunOptions{DryRun: c.Options.DryRun}) + return phase.Run(ifc.RunOptions{DryRun: c.Options.DryRun, Timeout: c.Options.Timeout}) } // PlanCommand plan command