Skip to content

Conversation

EyalPazz
Copy link
Member

/kind cleanup

Fixes #3945

Does this PR introduce a user-facing change?:

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Aug 20, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

The full list of commands accepted by this bot can be found 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

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 20, 2025
@EyalPazz
Copy link
Member Author

@JoelSpeed, is the fact that the fields are being marked as required the expected behavior here from a generator perspective?

@EyalPazz
Copy link
Member Author

@rikatz

@@ -3409,7 +3409,7 @@ func schema_sigsk8sio_gateway_api_apis_v1_GRPCRouteList(ref common.ReferenceCall
},
},
},
Required: []string{"items"},
Required: []string{"metadata", "items"},
Copy link
Member

Choose a reason for hiding this comment

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

this is not good :)

I think the right approach here is not to remove the omitempty, but add omitzero.

Copy link
Member

Choose a reason for hiding this comment

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

btw, Joel is on PTO and will be back next week, we can probably wait for him to be back for the clarification of

Structs that are not pointers should use omitzero
Structs that are pointers should use omitempty

and if we can move for now with the omitzeroadditional without messing with requirements and applyconfig

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea that's what i thought, seems weird
Is it a problem with the codegen itself? or is this the expected behavior

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 for these builtin metadata fields it is expected, and this is why we should not remove the "omitempty" right now.

There's some discussion around the differences between how CRDs consider optional fields vs how builtin consider optional fields, and at least for the sake of our safety, I would add omitempty,omitzero. This PR should not cause any change on generated files, we expect that the new tags are used right now just during the "wire" marshal/unmarshal process (aka converting the structs to/from json before putting it on the wire)

Copy link
Member Author

Choose a reason for hiding this comment

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

Got it, will fix

Copy link
Member

Choose a reason for hiding this comment

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

okie, please ping me once it is fixed so I don't miss the notification :)

Choose a reason for hiding this comment

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

The issue is that you are relying on fallback behaviour, add // +optional and // +required as appropriate to each field in your API and you won't need to care about whether omitempty affects the field being required or optional or not

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!
Ready for review @rikatz

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 24, 2025
@rikatz
Copy link
Member

rikatz commented Aug 25, 2025

/lgtm
Thanks
/cc @robscott @youngnick

@k8s-ci-robot k8s-ci-robot requested a review from youngnick August 25, 2025 17:45
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 25, 2025
@JoelSpeed
Copy link

Changes here LGTM

Is the GW API community happy with the trade off of if obj.OptionalStruct != OptionalStruct{} style checks instead of nil checks for optional structs?

I know this was discussed on some other threads

The CAPI folks have adopted this and have created IsDefined methods on optional structs to help capture this need, but in general have found the changes have improved their code readability and maintainability

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Struct fields should use omitzero when they are not a pointer
4 participants