-
Notifications
You must be signed in to change notification settings - Fork 587
fix: struct fields to use omitzero #4006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: EyalPazz 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 |
@JoelSpeed, is the fact that the fields are being marked as required the expected behavior here from a generator perspective? |
@@ -3409,7 +3409,7 @@ func schema_sigsk8sio_gateway_api_apis_v1_GRPCRouteList(ref common.ReferenceCall | |||
}, | |||
}, | |||
}, | |||
Required: []string{"items"}, | |||
Required: []string{"metadata", "items"}, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 omitzero
additional without messing with requirements and applyconfig
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, will fix
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
/lgtm |
Changes here LGTM Is the GW API community happy with the trade off of I know this was discussed on some other threads The CAPI folks have adopted this and have created |
/kind cleanup
Fixes #3945
Does this PR introduce a user-facing change?: