From c2f155dfd30473c95ce933ebe38eca3a8e706b9f Mon Sep 17 00:00:00 2001 From: Sascha Schwarze Date: Wed, 18 Oct 2023 22:21:18 +0200 Subject: [PATCH] Omit empty output object in BuildRun spec --- pkg/apis/build/v1beta1/buildrun_conversion.go | 17 +++++++++-------- pkg/webhook/conversion/converter_test.go | 1 - test/utils/v1beta1/image.go | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/apis/build/v1beta1/buildrun_conversion.go b/pkg/apis/build/v1beta1/buildrun_conversion.go index 4d1e213b70..ea67c60074 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 diff --git a/pkg/webhook/conversion/converter_test.go b/pkg/webhook/conversion/converter_test.go index a6967bb84d..6907e17ffc 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 4b900cb727..cc1c9ab104 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