Skip to content
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

Merged
merged 2 commits into from
Apr 7, 2021

Conversation

alicerum
Copy link
Member

This pull request contains new sub-commands for working with BuildRun objects.
BuildRun can be created via command build run.
They also can be deleted, listed and logs can be requested via buildrun logs
Resource objects now support context passed from cobra commands.
SubCommands Run method now accepts IoStreams for information output.
Other minor changes, including README.

@alicerum
Copy link
Member Author

@otaviof could you please take a look at this?

@alicerum alicerum requested review from otaviof and coreydaley March 29, 2021 12:54
Copy link
Contributor

@coreydaley coreydaley left a 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)
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member

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. :-)

Copy link
Contributor

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.

br := resource.GetBuildResource(params)
brr := resource.GetBuildRunResource(params)

if err := br.Get(c.cmd.Context(), c.name, &b); err != nil {
Copy link
Contributor

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.

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{
Copy link
Contributor

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
}

LabelSelector: label,
})

if err != nil {
Copy link
Contributor

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

}

for _, buildrun := range brList.Items {
brr.Delete(c.cmd.Context(), buildrun.Name)
Copy link
Contributor

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?

return err
}

fmt.Fprintf(io.Out, "Build created \"%v\"\n", sc.name)
Copy link
Contributor

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

}

func deleteCmd() runner.SubCommand {
deleteCommand := &DeleteCommand{
cmd: &cobra.Command{
Use: "delete [flags] name",
Use: "delete [flags] [name]",
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

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.

Short: "Delete Build",
},
}

deleteCommand.cmd.Flags().BoolVarP(&deleteCommand.deleteRuns, "delete-runs", "r", false, "Also delete all the buildruns")
Copy link
Contributor

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/

var b buildv1alpha1.Build

if err := buildResource.Get(c.name, &b); err != nil {
br := resource.GetBuildResource(params)
brr := resource.GetBuildRunResource(params)
Copy link
Contributor

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.

return err
}

return buildResource.Delete(c.name)
if c.deleteRuns {
label := fmt.Sprintf("build.build.dev/name=%v", c.name)
Copy link
Contributor

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.

Copy link
Member Author

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

Copy link
Member

@otaviof otaviof left a 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
Copy link
Member

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.

Copy link
Member Author

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)
Copy link
Member

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. :-)

@@ -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]",
Copy link
Member

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>

}

func deleteCmd() runner.SubCommand {
deleteCommand := &DeleteCommand{
cmd: &cobra.Command{
Use: "delete [flags] name",
Use: "delete [flags] [name]",
Copy link
Member

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 {
Copy link
Member

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 🙏🏼

@alicerum
Copy link
Member Author

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.

@otaviof
Copy link
Member

otaviof commented Mar 31, 2021

/lgtm

Good changes, Alice! Thanks.

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 31, 2021
@coreydaley
Copy link
Contributor

@alicerum If you would squash your two code commits I would like to take another run through it.

@alicerum
Copy link
Member Author

@coreydaley done, thank you

@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Mar 31, 2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func NewBuildRun(build *buildv1alpha1.Build, prefix string) *buildv1alpha1.BuildRun {
Copy link
Contributor

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

@coreydaley
Copy link
Contributor

The exported functions in this pull request, that are not boilerplate Cobra code, probably need comments added, at least a short blurb.

@alicerum
Copy link
Member Author

alicerum commented Apr 1, 2021

@coreydaley done

Copy link
Contributor

@coreydaley coreydaley left a 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

@otaviof
Copy link
Member

otaviof commented Apr 6, 2021

/approve

Alice Rum added 2 commits April 7, 2021 16:19
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
@openshift-ci-robot
Copy link

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 7, 2021
@adambkaplan
Copy link
Member

/refresh

Copy link
Member

@adambkaplan adambkaplan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@adambkaplan
Copy link
Member

Need to determine why tide is not working with the cli repo. Going to use the "green button"

@adambkaplan adambkaplan merged commit 1d887fb into shipwright-io:main Apr 7, 2021
@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants