fix: compare pointer-bearing IR fields by value in Equals (HttpListenerPolicyIr, directResponse) (#14331) [v2.3.x backport]#14342
Merged
puertomontt merged 1 commit intoJul 1, 2026
Conversation
…erPolicyIr, directResponse) (kgateway-dev#14331) Signed-off-by: omar <[email protected]> (cherry picked from commit 14ebe9d) Backport note: adapted the equality harness tests to the v2.3.x IR shape. directResponse's BodyFormat lives in api/v1alpha1/kgateway on this branch (not api/v1alpha1/shared), and HttpListenerPolicyIr on v2.3.x does not have the localReplyConfig, maxRequestsPerConnection, forwardClientCertMode, or setCurrentClientCertDetails fields, so their harness cases were dropped. Signed-off-by: omar <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This backport fixes IR Equals implementations that previously compared pointer-bearing fields by pointer identity, causing KRT recomputes to spuriously detect changes and trigger unnecessary re-translation. It also adds an equalstest harness plus per-plugin harness tests to prevent regressions by ensuring every IR field is covered by Equals.
Changes:
- Fix
HttpListenerPolicyIr.Equalsto compareserverHeaderTransformationby value viacmputils.PointerValsEqual. - Fix
directResponse.Equalsto compareDirectResponseSpecby value (reflect.DeepEqual) instead of struct==(pointer identity for pointer fields). - Add a shared
equalstestharness with anIncludeUnexported()option and add plugin-specific equality harness tests for listenerpolicy and directresponse.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/testutils/equalstest/equalstest.go | Introduces the reusable Equals completeness/reflexivity/mutation harness and IncludeUnexported() option. |
| test/testutils/equalstest/equalstest_test.go | Black-box tests validating the harness behavior with a small fixture type. |
| test/testutils/equalstest/equalstest_internal_test.go | White-box tests for helper behavior (embedding flattening, unexported-field inclusion). |
| pkg/kgateway/extensions2/plugins/listenerpolicy/http.go | Fixes pointer-identity comparison of serverHeaderTransformation in HttpListenerPolicyIr.Equals. |
| pkg/kgateway/extensions2/plugins/listenerpolicy/equality_harness_test.go | Adds field-by-field Equals harness coverage for HttpListenerPolicyIr (including unexported fields). |
| pkg/kgateway/extensions2/plugins/directresponse/direct_response_plugin.go | Fixes directResponse.Equals to compare DirectResponseSpec by value to avoid needless re-translation. |
| pkg/kgateway/extensions2/plugins/directresponse/equality_harness_test.go | Adds harness coverage ensuring directResponse.Equals detects spec changes and is reflexive across distinct pointer graphs. |
Comment on lines
+27
to
+28
| // Case mutates one logical field of T and states whether Equals must | ||
| // report inequality afterwards. |
Comment on lines
+104
to
+107
| t.Errorf( | ||
| "completeness check failed for %s: exported field(s) %v are neither covered by a mutation Case nor listed as exempt — add a Case or add the field name to exempt", | ||
| typeName(typ), | ||
| missing, |
Comment on lines
+52
to
+54
| // exportedFields emits both "Embedded" (flattened) and "EmbeddedBase" (the | ||
| // embedding name itself). With covered containing only "Embedded", | ||
| // "EmbeddedBase" must appear as uncovered. |
Comment on lines
+63
to
+64
| // Cover every name that exportedFields produces for internalFixture. | ||
| covered := map[string]bool{"Plain": true, "Embedded": true, "EmbeddedBase": true} |
puertomontt
enabled auto-merge
July 1, 2026 15:07
jenshu
approved these changes
Jul 1, 2026
Merged
via the queue into
kgateway-dev:v2.3.x
with commit Jul 1, 2026
3845e45
32 of 37 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Backport of #14331 to
v2.3.x.Fixes two
Equalsmethods on IR types that compared pointer-bearing fields by pointer identity instead of by value. Because these IRs are rebuilt from freshly decoded objects on every KRT recompute, equal-content specs get distinct pointers, so identity comparison spuriously reported inequality and triggered needless re-translation:directResponse.EqualscomparedDirectResponseSpecwith==;DirectResponseSpechas pointer fields (Body,BodyFormat). Now uses a value-basedreflect.DeepEqual(it is a plain, non-proto API type).HttpListenerPolicyIr.EqualscomparedserverHeaderTransformation(a*enum) with!=. Now usescmputils.PointerValsEqual.Also backports the
test/testutils/equalstestcompleteness-harness and per-plugin harness tests that guard against this class of regression.Backport adaptations
The harness tests were written against
main's IR shape and were adapted tov2.3.x:directResponse'sBodyFormatlives inapi/v1alpha1/kgatewayon this branch (notapi/v1alpha1/shared).HttpListenerPolicyIronv2.3.xdoes not have thelocalReplyConfig,maxRequestsPerConnection,forwardClientCertMode, orsetCurrentClientCertDetailsfields, so those harness cases were dropped. All 24 fields present onv2.3.xare covered.The source fix itself applied cleanly.
Change Type
/kind fix
Changelog