Skip to content

Conversation

karanibm6
Copy link
Contributor

@karanibm6 karanibm6 commented Mar 24, 2025

Changes

Add code changes to move to v1beta1 from v1alpha1

Fixes #294

Submitter Checklist

  • Includes tests if functionality changed/was added
  • Includes docs if changes are user-facing
  • Set a kind label on this PR
  • Release notes block has been filled in, or marked NONE

See the contributor guide
for details on coding conventions, github and prow interactions, and the code review process.

Release Notes

The CLI now interacts with the Shipwright artifacts using the v1beta1 API

@pull-request-size pull-request-size bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Mar 24, 2025
@openshift-ci openshift-ci bot requested review from HeavyWombat and qu1queee March 24, 2025 06:28
Copy link
Contributor

@HeavyWombat HeavyWombat left a comment

Choose a reason for hiding this comment

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

Thanks for all the work. Nice. I just left some comments and questions after an initial pass.

Comment on lines 32 to 33
--source-oci-artifact-image string source oci artifact image location, e.g. ghcr.io/shipwright-io/sample-go/source-bundle:latest
--source-oci-artifact-prune pruneOption source oci artifact image prune option, either Never, or AfterPull (default Never)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I think I should try uppercase since it's an acronym.

Suggested change
--source-oci-artifact-image string source oci artifact image location, e.g. ghcr.io/shipwright-io/sample-go/source-bundle:latest
--source-oci-artifact-prune pruneOption source oci artifact image prune option, either Never, or AfterPull (default Never)
--source-oci-artifact-image string source OCI artifact image location, e.g. ghcr.io/shipwright-io/sample-go/source-bundle:latest
--source-oci-artifact-prune pruneOption source OCI artifact image prune option, either Never, or AfterPull (default Never)

Copy link
Member

Choose a reason for hiding this comment

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

I believe this doc is auto-generated, so it needs to be made in the respective go code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

"github.com/spf13/cobra"

v1 "k8s.io/api/core/v1"
Copy link
Contributor

Choose a reason for hiding this comment

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

For consistency, we should use "full name".

Suggested change
v1 "k8s.io/api/core/v1"
corev1 "k8s.io/api/core/v1"

Comment on lines +22 to +28
Git: &buildv1beta1.Git{
Revision: ptr.To(""),
CloneSecret: ptr.To(""),
},
OCIArtifact: &buildv1beta1.OCIArtifact{
Prune: &pruneOption,
PullSecret: ptr.To(""),
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems a bit a weird to me to initialize everything with pointers to empty strings just to be later updated by flag values, if I understand it correctly. Is there any way we can simplify this? What do you think?

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 can take this up as a follow-up item to address. Since this PR is a pure refactor, I'd prefer to keep the existing behavior as close as possible to status quo.

Copy link
Member

Choose a reason for hiding this comment

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

Filed #310 so we don't lose track of this.

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.

/approve

Giving the 👍 for this change to go into v0.16. I called out a few items I noticed in my review.

Comment on lines 32 to 33
--source-oci-artifact-image string source oci artifact image location, e.g. ghcr.io/shipwright-io/sample-go/source-bundle:latest
--source-oci-artifact-prune pruneOption source oci artifact image prune option, either Never, or AfterPull (default Never)
Copy link
Member

Choose a reason for hiding this comment

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

I believe this doc is auto-generated, so it needs to be made in the respective go code.

return err
}
fmt.Fprintf(ioStreams.Out, "BuildRun created %q for Build %q\n", c.name, br.Spec.BuildRef.Name)
fmt.Fprintf(ioStreams.Out, "BuildRun created %q for Build %q\n", c.name, *br.Spec.Build.Name)
Copy link
Member

Choose a reason for hiding this comment

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

Risk of nil pointer dereference panic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

Choose a reason for hiding this comment

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

Looks like the nil dereference risk is still here...

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 in this context, we never have a standalone buildrun but always one that references a build? If so, would be worth a comment.

Comment on lines +22 to +28
Git: &buildv1beta1.Git{
Revision: ptr.To(""),
CloneSecret: ptr.To(""),
},
OCIArtifact: &buildv1beta1.OCIArtifact{
Prune: &pruneOption,
PullSecret: ptr.To(""),
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 can take this up as a follow-up item to address. Since this PR is a pure refactor, I'd prefer to keep the existing behavior as close as possible to status quo.

Copy link
Contributor

openshift-ci bot commented Mar 26, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: adambkaplan

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 openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 26, 2025
@karanibm6 karanibm6 force-pushed the update-cli-params branch 2 times, most recently from 8320cbf to 74ec843 Compare April 7, 2025 03:43
@pull-request-size pull-request-size bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Apr 7, 2025
@karanibm6 karanibm6 force-pushed the update-cli-params branch 5 times, most recently from 8cb2147 to cfea747 Compare April 7, 2025 12:59
@karanibm6 karanibm6 force-pushed the update-cli-params branch from e051935 to 359459c Compare April 7, 2025 18:24
}
}

if c.dockerfile != nil && *c.dockerfile != "" {
Copy link
Member

Choose a reason for hiding this comment

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

nit (not going to block on this) - you can do both checks in golang using len, since it is safe to use on nil pointers:

Suggested change
if c.dockerfile != nil && *c.dockerfile != "" {
if len(c.dockerfile) > 0 {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@adambkaplan , I know it works with arrays, but I tried this : https://go.dev/play/p/_nEyrfl96EZ and it didn't work for pointer strings.

c.buildSpec.ParamValues = append(c.buildSpec.ParamValues, dockerfileParam)
}

if c.builderImage != nil && *c.builderImage != "" {
Copy link
Member

Choose a reason for hiding this comment

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

nit (not blocking) - ditto on using len:

Suggested change
if c.builderImage != nil && *c.builderImage != "" {
if len(c.builderImage) > 0 {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@adambkaplan , I know it works with arrays, but I tried this : https://go.dev/play/p/_nEyrfl96EZ and it didn't work for pointer strings.

if buildRun == nil {
return "", fmt.Errorf("no buildrun provided, given reference is nil")
}

if buildRun.Spec.BuildRef != nil {
name, namespace := buildRun.Spec.BuildRef.Name, buildRun.Namespace
if buildRun.Spec.Build.Name != nil && *buildRun.Spec.Build.Name != "" {
Copy link
Member

Choose a reason for hiding this comment

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

nit - ditto on use of len:

Suggested change
if buildRun.Spec.Build.Name != nil && *buildRun.Spec.Build.Name != "" {
if len(buildRun.Spec.Build.Name) > 0 {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@adambkaplan , I know it works with arrays, but I tried this : https://go.dev/play/p/_nEyrfl96EZ and it didn't work for pointer strings.

ServiceAccountGenerateFlag,
false,
"generate a Kubernetes service-account for the build",
)
flags.MarkDeprecated("sa-generate", fmt.Sprintf("this flag has no effect, please use --%s for service account", ServiceAccountNameFlag))
Copy link
Member

Choose a reason for hiding this comment

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

Note that with this change, we should also remove the service account generation logic in the BuildRun controller. Filed shipwright-io/build#1873

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, we don't need any change in cli. Right ?

@adambkaplan
Copy link
Member

@karanibm6 almost there! I found one item that was missed in your updates, plus a few nits that otherwise wouldn't block merge. Once these are done, please squash your commits and then this should be ready to merge 😄 !

Copy link
Member

@SaschaSchwarze0 SaschaSchwarze0 left a comment

Choose a reason for hiding this comment

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

Nice work.

return err
}
fmt.Fprintf(ioStreams.Out, "BuildRun created %q for Build %q\n", c.name, br.Spec.BuildRef.Name)
fmt.Fprintf(ioStreams.Out, "BuildRun created %q for Build %q\n", c.name, *br.Spec.Build.Name)
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 in this context, we never have a standalone buildrun but always one that references a build? If so, would be worth a comment.

Copy link
Member

@SaschaSchwarze0 SaschaSchwarze0 left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 28, 2025
@SaschaSchwarze0 SaschaSchwarze0 added this to the release-v0.16.0 milestone Apr 28, 2025
@SaschaSchwarze0 SaschaSchwarze0 added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Apr 28, 2025
@openshift-merge-bot openshift-merge-bot bot merged commit 0fe28ba into shipwright-io:main Apr 28, 2025
10 checks passed
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. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm Indicates that a PR is ready to be merged. release-note size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[FEATURE] Use v1beta1 APIs Only
4 participants