Skip to content

refactor: use omitzero for struct fields in API types#1117

Closed
kahirokunn wants to merge 1 commit intoknative:mainfrom
kahirokunn:refactor/use-omitzero-for-struct-fields
Closed

refactor: use omitzero for struct fields in API types#1117
kahirokunn wants to merge 1 commit intoknative:mainfrom
kahirokunn:refactor/use-omitzero-for-struct-fields

Conversation

@kahirokunn
Copy link
Member

@kahirokunn kahirokunn commented Mar 9, 2026

Go 1.24 introduced the omitzero JSON tag option which properly handles struct fields. omitempty has no effect on non-pointer struct fields. the struct is never considered "empty" by encoding/json, so the tag is silently ignored. omitzero checks the zero value correctly for these types.

This commit replaces omitempty with omitzero on all non-pointer struct fields across the v1alpha1 API types (Ingress, Certificate, ClusterDomainClaim, ServerlessService and their List types).

Changes

  • 🧹 Replace omitempty with omitzero on embedded ObjectMeta / ListMeta and top-level Spec / Status struct fields
  • 🧹 Replace omitempty with omitzero on intstr.IntOrString field in HTTP01Challenge

/kind cleanup

Release Note

N/A

Docs

N/A

Go 1.24 introduced the omitzero JSON tag option which properly handles
struct fields.

Signed-off-by: kahirokunn <okinakahiro@gmail.com>
@knative-prow knative-prow bot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Mar 9, 2026
@knative-prow
Copy link

knative-prow bot commented Mar 9, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: kahirokunn
Once this PR has been reviewed and has the lgtm label, please assign dsimansk for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details 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

@knative-prow knative-prow bot requested review from dprotaso and skonto March 9, 2026 09:16
@knative-prow knative-prow bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 9, 2026
@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.33%. Comparing base (965e7c3) to head (74d8791).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1117   +/-   ##
=======================================
  Coverage   93.33%   93.33%           
=======================================
  Files          35       35           
  Lines        1005     1005           
=======================================
  Hits          938      938           
  Misses         53       53           
  Partials       14       14           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@knative-prow
Copy link

knative-prow bot commented Mar 9, 2026

@kahirokunn: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
build-tests_networking_main 74d8791 link true /test build-tests

Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@kahirokunn kahirokunn marked this pull request as draft March 9, 2026 12:37
@knative-prow knative-prow bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 9, 2026
@dprotaso
Copy link
Member

What problem are you trying to solve with omitzero ?

@kahirokunn
Copy link
Member Author

There are no particular issues either.
I decided to try out omitzero because of the following review comments. However, since many third-party developers directly import and use the Go code, it would constitute a breaking change for them. Therefore, I concluded it would be better not to modify the released version, so I'm closing this for now.
#1116 (comment)

@kahirokunn kahirokunn closed this Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants