fix(api): add omitempty to SingleValue optional fields - #2293
Conversation
|
/kind cleanup |
|
/retest |
The Value, ConfigMapValue and SecretValue fields of SingleValue are
mutually exclusive and optional, but their JSON tags lacked omitempty.
As a result, serialized build parameters always rendered the two unset
fields as explicit nulls, for example:
- name: build-args
values:
- configMapValue: null
secretValue: null
value: BUILD_VERSION=1.0.0
Adding omitempty makes only the field that is actually set appear in the
output, producing cleaner Build/BuildRun YAML. This is a serialization-
only change; the CRD schema is unaffected (optionality is already driven
by the +optional markers). A unit test covering the value, configMap and
secret cases is added.
Co-Authored-By: Claude
Signed-off-by: Prateek Singh Rathore <prateek.singh.rathore@gmail.com>
34e87ec to
f55d882
Compare
|
Rebased ^^ |
|
@psrvere out of interest, which client is rendering the null values for you? I am totally understanding your change and kind of surprised we don't have the fields defined like that. But basically, I do not understand why I never observed this issue with
|
|
Hi @SaschaSchwarze0, it's not a kubectl client. I hit this while generating YAML directly from the Go API types. I am building a migration tool that converts OpenShift BuildConfigs to OpenShift Builds (which uses Shipwright under the hood): https://github.com/migtools/crane-plugin-buildconfig-to-shipwright. It constructs Build objects in Go and marshals them with sigs.k8s.io/yaml to write manifest files. Without omitempty, the unset pointer fields render as explicit configMapValue: null / secretValue: null in the generated YAML. I will work on refactoring the tests. |
…Table Signed-off-by: Prateek Singh Rathore <prateek.singh.rathore@gmail.com>
b5b9f09 to
cfc4524
Compare
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: SaschaSchwarze0 The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |

Changes
The
Value,ConfigMapValueandSecretValuefields of theSingleValuetype are mutually exclusive and optional, but their JSON tags lacked
omitempty. As a result, serialized build parameter values always renderedthe two unset fields as explicit nulls:
This adds
omitemptyto all three fields so only the field that is actuallyset appears in the output, producing cleaner Build/BuildRun YAML.
This is a serialization-only change — the CRD schema is unaffected, since
optionality is already driven by the
+optionalmarkers (verified: no CRDregeneration diff). A unit test covering the value, configMap and secret
cases is included.
Submitter Checklist
See the contributor guide
for details on coding conventions, github and prow interactions, and the code review process.
Release Notes
Co-Authored-By: Claude