Skip to content
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

[backport] gateway2: use safer merging to avoid assuming zero values as being unset #10559

Merged
merged 1 commit into from
Jan 8, 2025

Conversation

shashankram
Copy link

Backports #10555 to v1.18.x

The legacy Edge code uses ShallowMerge() which can undesirably overwrite zero values mistaking them for unset values. RouteOptions merging in GatewayV2 uses the same API, but this can result in undesirable effects if the merging considers zero valued fields as being unset. To avoid this, the options merging used by GatewayV2 relies on a safer merge that only allows merging of values that can be set to Nil (pointers, slices, maps, etc.) which works since all user-facing fields on the RouteOptions are nil-able. Functionally, this is the same as before due to all fields being nil-able but it affects how overwrites are counted, and is a bit clearer to readers. Moreover, trying to merge a non-nil field will panic which can catch potential misuse of the API.

The legacy Edge code uses ShallowMerge() which can undesirably overwrite
zero values mistaking them for unset values. RouteOptions merging in
GatewayV2 uses the same API, but this can result in undesirable effects
if the merging considers zero valued fields as being unset. To avoid
this, the options merging used by GatewayV2 relies on a safer merge
that only allows merging of values that can be set to Nil (pointers,
slices, maps, etc.) which works since all user-facing fields on the
RouteOptions are nil-able. Functionally, this is the same as before
due to all fields being nil-able but it affects how overwrites are
counted, and is a bit clearer to readers. Moreover, trying to merge a
non-nil field will panic which can catch potential misuse of the API.

Signed-off-by: Shashank Ram <[email protected]>
@shashankram shashankram changed the title gateway2: use safer merging to avoid assuming zero values as being unset [backport] gateway2: use safer merging to avoid assuming zero values as being unset Jan 8, 2025
@soloio-bulldozer soloio-bulldozer bot merged commit 7b72f42 into v1.18.x Jan 8, 2025
19 checks passed
@soloio-bulldozer soloio-bulldozer bot deleted the shashankram/merge-check_bk-118 branch January 8, 2025 20:02
kevin-shelaga pushed a commit that referenced this pull request Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants