[backport] gateway2: use safer merging to avoid assuming zero values as being unset #10559
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.