Repository: shipwright-io/build
Pull request #1410 (2023-10-18 20:23:46)

Omit empty output object in BuildRun spec
# Changes

When a BuildRun without an output is converted to Beta, then this looks like this:

```yaml
apiVersion: shipwright.io/v1beta1
kind: BuildRun
spec:
  build:
    name: build-name
  output:
    image: ""
  serviceAccount: sa-name
```

The empty output section is not desired, especially as it has a mandatory image field which is then rendered as an empty string.

# Submitter Checklist

- [x] Includes tests if functionality changed/was added
- [ ] Includes docs if changes are user-facing
- [x] [Set a kind label on this PR](https://prow.k8s.io/command-help#kind)
- [x] Release notes block has been filled in, or marked NONE

See [the contributor guide](https://github.com/shipwright-io/build/blob/main/CONTRIBUTING.md)
for details on coding conventions, github and prow interactions, and the code review process.

# Release Notes

```release-note
NONE
```


openshift-ci[bot]: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by:
**Once this PR has been reviewed and has the lgtm label**, please ask for approval from [saschaschwarze0](https://github.com/saschaschwarze0). For more information see [the Kubernetes Code Review Process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process).

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=shipwright-io%2Fbuild).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/shipwright-io/build/blob/main/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["saschaschwarze0"]} -->

Patch:
diff --git a/pkg/apis/build/v1beta1/buildrun_conversion.go b/pkg/apis/build/v1beta1/buildrun_conversion.go
index 4d1e213b..ea67c600 100644
--- a/pkg/apis/build/v1beta1/buildrun_conversion.go
+++ b/pkg/apis/build/v1beta1/buildrun_conversion.go
@@ -224,16 +224,17 @@ func (dest *BuildRunSpec) ConvertFrom(orig *v1alpha1.BuildRunSpec) error {
 		dest.ParamValues = append(dest.ParamValues, param)
 	}
 
-	// Handle BuildSpec Output
-	dest.Output = &Image{}
+	// Handle BuildRunSpec Output
 	if orig.Output != nil {
-		dest.Output.Image = orig.Output.Image
-		dest.Output.Annotations = orig.Output.Annotations
-		dest.Output.Labels = orig.Output.Labels
-	}
+		dest.Output = &Image{
+			Image:       orig.Output.Image,
+			Annotations: orig.Output.Annotations,
+			Labels:      orig.Output.Labels,
+		}
 
-	if orig.Output != nil && orig.Output.Credentials != nil {
-		dest.Output.PushSecret = &orig.Output.Credentials.Name
+		if orig.Output.Credentials != nil {
+			dest.Output.PushSecret = &orig.Output.Credentials.Name
+		}
 	}
 
 	// BuildRunSpec State


Test patch:
diff --git a/pkg/webhook/conversion/converter_test.go b/pkg/webhook/conversion/converter_test.go
index a6967bb8..6907e17f 100644
--- a/pkg/webhook/conversion/converter_test.go
+++ b/pkg/webhook/conversion/converter_test.go
@@ -1089,7 +1089,6 @@ request:
 							},
 						},
 					},
-					Output: &v1beta1.Image{},
 				},
 			}
 
diff --git a/test/utils/v1beta1/image.go b/test/utils/v1beta1/image.go
index 4b900cb7..cc1c9ab1 100644
--- a/test/utils/v1beta1/image.go
+++ b/test/utils/v1beta1/image.go
@@ -22,7 +22,7 @@ import (
 
 func getImageURL(buildRun *buildv1beta1.BuildRun) string {
 	image := ""
-	if buildRun.Spec.Output.Image != "" {
+	if buildRun.Spec.Output != nil && buildRun.Spec.Output.Image != "" {
 		image = buildRun.Spec.Output.Image
 	} else {
 		image = buildRun.Status.BuildSpec.Output.Image