Add timeout flag for phase run in cli

Syntax:
	airshipctl phase run <PHASE_NAME> --timeout <time_unit>

Exmaple:
	airshipctl phase run initinfra-ephemeral --debug --wait-timeout 1000s

Change-Id: Ic8c699f5302eb482f32aee0e7d7c593df2ed7d3b
This commit is contained in:
Sirajudeen 2020-09-25 03:11:16 +00:00
parent 484a4b1549
commit 3e4c228638
5 changed files with 21 additions and 6 deletions

View File

@ -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
}

View File

@ -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

View File

@ -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

View File

@ -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)
}

View File

@ -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