Skip to content

Commit

Permalink
increase timeout to cancel pipeline builds, augment cancel-build status
Browse files Browse the repository at this point in the history
  • Loading branch information
gabemontero committed Jul 27, 2018
1 parent 0c4c2ad commit a3b1adc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 31 deletions.
30 changes: 21 additions & 9 deletions pkg/oc/cli/cancelbuild/cancelbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ type CancelBuildOptions struct {
Namespace string
BuildNames []string

HasError bool
ReportError func(error)
PrinterCancel printers.ResourcePrinter
PrinterRestart printers.ResourcePrinter
Mapper meta.RESTMapper
Client buildinternalclient.Interface
BuildClient buildtypedclient.BuildResourceInterface
BuildLister buildlister.BuildLister
HasError bool
ReportError func(error)
PrinterCancel printers.ResourcePrinter
PrinterCancelInProgress printers.ResourcePrinter
PrinterRestart printers.ResourcePrinter
Mapper meta.RESTMapper
Client buildinternalclient.Interface
BuildClient buildtypedclient.BuildResourceInterface
BuildLister buildlister.BuildLister

// timeout is used by unit tests to shorten the polling period
timeout time.Duration
Expand Down Expand Up @@ -122,6 +123,7 @@ func (o *CancelBuildOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, ar
// FIXME: this double printers should not be necessary
o.PrinterCancel = &printers.NamePrinter{Operation: "cancelled"}
o.PrinterRestart = &printers.NamePrinter{Operation: "restarted"}
o.PrinterCancelInProgress = &printers.NamePrinter{Operation: "marked for cancellation, waiting to be cancelled"}

if o.timeout.Seconds() == 0 {
o.timeout = 30 * time.Second
Expand Down Expand Up @@ -245,8 +247,18 @@ func (o *CancelBuildOptions) RunCancelBuild() error {
return
}

// ignore exit if error here; the phase verfication below is more important
o.PrinterCancelInProgress.PrintObj(kcmdutil.AsDefaultVersionedOrOriginal(build, nil), o.Out)

// Make sure the build phase is really cancelled.
err = wait.Poll(500*time.Millisecond, o.timeout, func() (bool, error) {
timeout := o.timeout
if build.Spec.Strategy.JenkinsPipelineStrategy != nil {
//bump the timeout in case we have to wait for Jenkins
//to come up so that the sync plugin can actually change
//the phase
timeout = timeout + (3 * time.Minute)
}
err = wait.Poll(500*time.Millisecond, timeout, func() (bool, error) {
updatedBuild, err := o.BuildClient.Get(build.Name, metav1.GetOptions{})
if err != nil {
return true, err
Expand Down
49 changes: 27 additions & 22 deletions pkg/oc/cli/cancelbuild/cancelbuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ func TestCancelBuildRun(t *testing.T) {
}{
"cancelled": {
opts: &CancelBuildOptions{
PrinterCancel: &discardingPrinter{},
PrinterRestart: &discardingPrinter{},
IOStreams: genericclioptions.NewTestIOStreamsDiscard(),
Namespace: "test",
States: []string{"new", "pending", "running"},
PrinterCancel: &discardingPrinter{},
PrinterCancelInProgress: &discardingPrinter{},
PrinterRestart: &discardingPrinter{},
IOStreams: genericclioptions.NewTestIOStreamsDiscard(),
Namespace: "test",
States: []string{"new", "pending", "running"},
},
phase: buildapi.BuildPhaseCancelled,
expectedActions: []testAction{
Expand All @@ -78,10 +79,11 @@ func TestCancelBuildRun(t *testing.T) {
},
"complete": {
opts: &CancelBuildOptions{
PrinterCancel: &discardingPrinter{},
PrinterRestart: &discardingPrinter{},
IOStreams: genericclioptions.NewTestIOStreamsDiscard(),
Namespace: "test",
PrinterCancel: &discardingPrinter{},
PrinterCancelInProgress: &discardingPrinter{},
PrinterRestart: &discardingPrinter{},
IOStreams: genericclioptions.NewTestIOStreamsDiscard(),
Namespace: "test",
},
phase: buildapi.BuildPhaseComplete,
expectedActions: []testAction{
Expand All @@ -91,10 +93,11 @@ func TestCancelBuildRun(t *testing.T) {
},
"new": {
opts: &CancelBuildOptions{
PrinterCancel: &discardingPrinter{},
PrinterRestart: &discardingPrinter{},
IOStreams: genericclioptions.NewTestIOStreamsDiscard(),
Namespace: "test",
PrinterCancel: &discardingPrinter{},
PrinterCancelInProgress: &discardingPrinter{},
PrinterRestart: &discardingPrinter{},
IOStreams: genericclioptions.NewTestIOStreamsDiscard(),
Namespace: "test",
},
phase: buildapi.BuildPhaseNew,
expectedActions: []testAction{
Expand All @@ -106,10 +109,11 @@ func TestCancelBuildRun(t *testing.T) {
},
"pending": {
opts: &CancelBuildOptions{
PrinterCancel: &discardingPrinter{},
PrinterRestart: &discardingPrinter{},
IOStreams: genericclioptions.NewTestIOStreamsDiscard(),
Namespace: "test",
PrinterCancel: &discardingPrinter{},
PrinterCancelInProgress: &discardingPrinter{},
PrinterRestart: &discardingPrinter{},
IOStreams: genericclioptions.NewTestIOStreamsDiscard(),
Namespace: "test",
},
phase: buildapi.BuildPhaseNew,
expectedActions: []testAction{
Expand All @@ -121,11 +125,12 @@ func TestCancelBuildRun(t *testing.T) {
},
"running and restart": {
opts: &CancelBuildOptions{
PrinterCancel: &discardingPrinter{},
PrinterRestart: &discardingPrinter{},
IOStreams: genericclioptions.NewTestIOStreamsDiscard(),
Namespace: "test",
Restart: true,
PrinterCancel: &discardingPrinter{},
PrinterCancelInProgress: &discardingPrinter{},
PrinterRestart: &discardingPrinter{},
IOStreams: genericclioptions.NewTestIOStreamsDiscard(),
Namespace: "test",
Restart: true,
},
phase: buildapi.BuildPhaseNew,
expectedActions: []testAction{
Expand Down

0 comments on commit a3b1adc

Please sign in to comment.