-
Notifications
You must be signed in to change notification settings - Fork 35
Build-206: BuildRun CRUD and logging #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| // build contains types and functions for build cobra sub-command | ||
| package build |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package build | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" | ||
| "github.com/spf13/cobra" | ||
|
|
||
| "k8s.io/cli-runtime/pkg/genericclioptions" | ||
|
|
||
| "github.com/shipwright-io/cli/pkg/shp/cmd/buildrun" | ||
| "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" | ||
| ) | ||
|
|
||
| // RunCommand contains data input from user for run sub-command | ||
| type RunCommand struct { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be great do have doc-comments, and perhaps a initial |
||
| cmd *cobra.Command | ||
|
|
||
| buildName string | ||
| } | ||
|
|
||
| // Cmd returns cobra command object | ||
| func (c *RunCommand) Cmd() *cobra.Command { | ||
| return c.cmd | ||
| } | ||
|
|
||
| func runCmd() runner.SubCommand { | ||
| runCommand := &RunCommand{ | ||
| cmd: &cobra.Command{ | ||
| Use: "run <name>", | ||
| Short: "Start a build specified by 'name'", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can add |
||
| Args: cobra.ExactArgs(1), | ||
| }, | ||
| } | ||
|
|
||
| return runCommand | ||
| } | ||
|
|
||
| // Complete fills in data provided by user | ||
| func (c *RunCommand) Complete(params *params.Params, args []string) error { | ||
| if len(args) < 1 { | ||
| return errors.New("'name' argument is empty") | ||
| } | ||
|
|
||
| c.buildName = args[0] | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // Validate validates data input by user | ||
| func (c *RunCommand) Validate() error { | ||
| return nil | ||
| } | ||
|
|
||
| // Run executes run sub-command logic | ||
| func (c *RunCommand) Run(params *params.Params, ioStreams *genericclioptions.IOStreams) error { | ||
| br := resource.GetBuildResource(params) | ||
| brr := resource.GetBuildRunResource(params) | ||
|
|
||
| var build buildv1alpha1.Build | ||
| if err := br.Get(c.cmd.Context(), c.buildName, &build); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| buildRun := buildrun.NewBuildRun(&build, build.Name) | ||
|
|
||
| if err := brr.Create(c.cmd.Context(), "", buildRun); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| fmt.Fprintf(ioStreams.Out, "BuildRun created %q\n", buildRun.Name) | ||
| return nil | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we switch to using klog v2 here (and throughout ShipWright)?
That would give us logging levels and InfoF, WarnF, ErrorF, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest making a small issue for that. I think it must be done, but not as part of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. Feel free to create issues and reference them here, please. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#7 was created for this issue.