-
Notifications
You must be signed in to change notification settings - Fork 28
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
Build-206: BuildRun CRUD and logging #6
Conversation
@otaviof could you please take a look at this? |
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.
Here is my first run through of this pull request.
if err := rootCmd.Execute(); err != nil { | ||
fmt.Printf("[ERROR] %#v\n", err) | ||
fmt.Fprintf(os.Stderr, "ERROR: %v\n", err) |
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.
pkg/shp/cmd/build/delete.go
Outdated
br := resource.GetBuildResource(params) | ||
brr := resource.GetBuildRunResource(params) | ||
|
||
if err := br.Get(c.cmd.Context(), c.name, &b); err != 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.
If you are just checking for the existence here before you run the delete, you shouldn't need to, the delete should return an error if it doesn't exist.
pkg/shp/cmd/build/delete.go
Outdated
if c.deleteRuns { | ||
label := fmt.Sprintf("build.build.dev/name=%v", c.name) | ||
var brList buildv1alpha1.BuildRunList | ||
err := brr.ListWithOptions(c.cmd.Context(), &brList, v1.ListOptions{ |
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.
if err := brr.ListWithOptions(c.cmd.Context(), &brList, v1.ListOptions{
LabelSelector: label,
}); err != nil {
return err
}
pkg/shp/cmd/build/delete.go
Outdated
LabelSelector: label, | ||
}) | ||
|
||
if err != 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.
Then you can get rid of this
pkg/shp/cmd/build/delete.go
Outdated
} | ||
|
||
for _, buildrun := range brList.Items { | ||
brr.Delete(c.cmd.Context(), buildrun.Name) |
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.
Do we care about any errors that might happen here?
pkg/shp/cmd/build/create.go
Outdated
return err | ||
} | ||
|
||
fmt.Fprintf(io.Out, "Build created \"%v\"\n", sc.name) |
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.
You can replace \"%v\"
with %q
which will give you a double-quoted string safely escaped with Go syntax
pkg/shp/cmd/build/delete.go
Outdated
} | ||
|
||
func deleteCmd() runner.SubCommand { | ||
deleteCommand := &DeleteCommand{ | ||
cmd: &cobra.Command{ | ||
Use: "delete [flags] name", | ||
Use: "delete [flags] [name]", |
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 don't think that [name]
should have the square brackets around it (same with the other commands), unless you have a specific reason?
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 wanted it to be in brackets, because unlike delete
it's a variable, or a parameter, not subcommand.
But, I have just looked through man
pages conventions, and it seems, that angular brackets (<>
) might be a better choice here, because unlike square brackets ([]
), which represent optional parameter or value, angular ones represent mandatory parameter or piece of data.
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.
My suggestion is shp delete <name> [flags]
. By using <>
we delimitates the required items, which also should come first, and by using []
the optional -- as you've mentioned.
Do we agree with <>
for required and []
for optional?
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 like this format. and i think it is pretty self explanatory, so should work out well.
pkg/shp/cmd/build/delete.go
Outdated
Short: "Delete Build", | ||
}, | ||
} | ||
|
||
deleteCommand.cmd.Flags().BoolVarP(&deleteCommand.deleteRuns, "delete-runs", "r", false, "Also delete all the buildruns") |
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.
s/all the/all of the/
pkg/shp/cmd/build/delete.go
Outdated
var b buildv1alpha1.Build | ||
|
||
if err := buildResource.Get(c.name, &b); err != nil { | ||
br := resource.GetBuildResource(params) | ||
brr := resource.GetBuildRunResource(params) |
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.
You are only using the brr
variable inside of the if c.deleteRuns
block, so you should probably just create it inside of that block, since the code may never even be executed if that option is not set.
pkg/shp/cmd/build/delete.go
Outdated
return err | ||
} | ||
|
||
return buildResource.Delete(c.name) | ||
if c.deleteRuns { | ||
label := fmt.Sprintf("build.build.dev/name=%v", c.name) |
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.
It is probably safe to just replace the LabelSelector: label,
with LabelSelector: fmt.Sprintf(...),
instead of creating this separate variable.
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.
TODO: I also had it changed to const
from build
, but it probably got lost during the extensive cherry pick after the previous 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.
Here it goes my initial review comments, please consider.
br.yaml
Outdated
@@ -0,0 +1,7 @@ | |||
apiVersion: build.dev/v1alpha1 |
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.
Is this file intentionally part of the PR? I looks like a left over.
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.
yup, it's an accident from my latest testing, i'll remove it
if err := rootCmd.Execute(); err != nil { | ||
fmt.Printf("[ERROR] %#v\n", err) | ||
fmt.Fprintf(os.Stderr, "ERROR: %v\n", err) |
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. :-)
pkg/shp/cmd/build/create.go
Outdated
@@ -28,7 +31,7 @@ type CreateCommand struct { | |||
func createCmd() runner.SubCommand { | |||
createCommand := &CreateCommand{ | |||
cmd: &cobra.Command{ | |||
Use: "create [flags] name strategy url", | |||
Use: "create [flags] [name] [strategy] [url]", |
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 think we should have URL and strategy as flags, so it highlights the attributes used. Also, we should consider having a default strategy, therefore when not informed we could assume "buildpacks" and have --strategy
as optional.
shp create <name> --url=<url> --strategy=<strategy>
pkg/shp/cmd/build/delete.go
Outdated
} | ||
|
||
func deleteCmd() runner.SubCommand { | ||
deleteCommand := &DeleteCommand{ | ||
cmd: &cobra.Command{ | ||
Use: "delete [flags] name", | ||
Use: "delete [flags] [name]", |
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.
My suggestion is shp delete <name> [flags]
. By using <>
we delimitates the required items, which also should come first, and by using []
the optional -- as you've mentioned.
Do we agree with <>
for required and []
for optional?
"github.com/shipwright-io/cli/pkg/shp/resource" | ||
) | ||
|
||
type RunCommand struct { |
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.
Would be great do have doc-comments, and perhaps a initial doc.go
🙏🏼
In the latest commit I've fixed most of the requested changes. I haven't commited anything regarding the buildrun logs yet. Doing some research and testing before I do that. |
/lgtm Good changes, Alice! Thanks. |
@alicerum If you would squash your two code commits I would like to take another run through it. |
@coreydaley done, thank you |
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func NewBuildRun(build *buildv1alpha1.Build, prefix string) *buildv1alpha1.BuildRun { |
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.
Exported functions should have comments
The exported functions in this pull request, that are not boilerplate Cobra code, probably need comments added, at least a short blurb. |
@coreydaley done |
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.
Looks good to me
/approve |
New Subcommands for working with BuildRun Created via 'build run' Can be deleted, listed and view logs Resource objects now support context passed from cobra commands SubCommand Run method now accepts IoStreams for information output Other minor changes, including README
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: otaviof The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/refresh |
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.
/lgtm
Need to determine why tide is not working with the cli repo. Going to use the "green button" |
This pull request contains new sub-commands for working with
BuildRun
objects.BuildRun
can be created via commandbuild run
.They also can be deleted, listed and logs can be requested via
buildrun logs
Resource objects now support context passed from cobra commands.
SubCommand
sRun
method now acceptsIoStream
s for information output.Other minor changes, including
README
.