forked from shipwright-io/cli
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from gabemontero/buildrun-cancel
add buildrun cancel
- Loading branch information
Showing
29 changed files
with
1,314 additions
and
466 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package buildrun | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/cli-runtime/pkg/genericclioptions" | ||
|
||
buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" | ||
"github.com/shipwright-io/cli/pkg/shp/cmd/runner" | ||
"github.com/shipwright-io/cli/pkg/shp/params" | ||
"github.com/shipwright-io/cli/pkg/shp/resource" | ||
) | ||
|
||
// CancelCommand contains data input from user for delete sub-command | ||
type CancelCommand struct { | ||
cmd *cobra.Command | ||
|
||
name string | ||
} | ||
|
||
func cancelCmd() runner.SubCommand { | ||
return &CancelCommand{ | ||
cmd: &cobra.Command{ | ||
Use: "cancel <name>", | ||
Short: "Cancel BuildRun", | ||
Args: cobra.ExactArgs(1), | ||
}, | ||
} | ||
} | ||
|
||
// Cmd returns cobra command object | ||
func (c *CancelCommand) Cmd() *cobra.Command { | ||
return c.cmd | ||
} | ||
|
||
// Complete fills in data provided by user | ||
func (c *CancelCommand) Complete(params *params.Params, args []string) error { | ||
c.name = args[0] | ||
|
||
return nil | ||
} | ||
|
||
// Validate validates data input by user | ||
func (c *CancelCommand) Validate() error { | ||
return nil | ||
} | ||
|
||
// Run executes cancel sub-command logic | ||
func (c *CancelCommand) Run(params *params.Params, ioStreams *genericclioptions.IOStreams) error { | ||
brr := resource.GetBuildRunResource(params) | ||
|
||
br := &buildv1alpha1.BuildRun{} | ||
if err := brr.Get(c.cmd.Context(), c.name, br); err != nil { | ||
return fmt.Errorf("failed to retrieve BuildRun %s: %s", c.name, err.Error()) | ||
} | ||
//TODO replace with br.IsDone() when that is available and vendored in | ||
cond := br.Status.GetCondition(buildv1alpha1.Succeeded) | ||
if cond != nil && cond.GetStatus() != corev1.ConditionUnknown { | ||
return fmt.Errorf("failed to cancel BuildRun %s: execution has already finished", c.name) | ||
} | ||
|
||
//TODO use constant when vendor in api changes | ||
if err := brr.Patch(c.cmd.Context(), c.name, "replace", "/spec/state", "BuildRunCanceled"); err != nil { | ||
return err | ||
} | ||
|
||
fmt.Fprintf(ioStreams.Out, "BuildRun successfully canceled '%v'\n", c.name) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 7 additions & 4 deletions
11
vendor/github.com/shipwright-io/build/pkg/apis/build/v1alpha1/build_types.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.