Skip to content

fix: compare pointer-bearing IR fields by value in Equals (HttpListenerPolicyIr, directResponse) (#14331) [v2.3.x backport]#14342

Merged
puertomontt merged 1 commit into
kgateway-dev:v2.3.xfrom
puertomontt:cherry-pick-14331-v2.3.x
Jul 1, 2026
Merged

fix: compare pointer-bearing IR fields by value in Equals (HttpListenerPolicyIr, directResponse) (#14331) [v2.3.x backport]#14342
puertomontt merged 1 commit into
kgateway-dev:v2.3.xfrom
puertomontt:cherry-pick-14331-v2.3.x

Conversation

@puertomontt

@puertomontt puertomontt commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Description

Backport of #14331 to v2.3.x.

Fixes two Equals methods 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.Equals compared DirectResponseSpec with ==; DirectResponseSpec has pointer fields (Body, BodyFormat). Now uses a value-based reflect.DeepEqual (it is a plain, non-proto API type).
  • HttpListenerPolicyIr.Equals compared serverHeaderTransformation (a *enum) with !=. Now uses cmputils.PointerValsEqual.

Also backports the test/testutils/equalstest completeness-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 to v2.3.x:

  • directResponse's BodyFormat lives in api/v1alpha1/kgateway on this branch (not api/v1alpha1/shared).
  • HttpListenerPolicyIr on v2.3.x does not have the localReplyConfig, maxRequestsPerConnection, forwardClientCertMode, or setCurrentClientCertDetails fields, so those harness cases were dropped. All 24 fields present on v2.3.x are covered.

The source fix itself applied cleanly.

Change Type

/kind fix

Changelog

Fixed HttpListenerPolicy and DirectResponse being re-translated unnecessarily because their IR Equals methods compared pointer-bearing fields by identity instead of by value.

…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]>
Copilot AI review requested due to automatic review settings July 1, 2026 14:48
@gateway-bot gateway-bot added do-not-merge/description-invalid kind/fix Categorizes issue or PR as related to a bug. release-note labels Jul 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.Equals to compare serverHeaderTransformation by value via cmputils.PointerValsEqual.
  • Fix directResponse.Equals to compare DirectResponseSpec by value (reflect.DeepEqual) instead of struct == (pointer identity for pointer fields).
  • Add a shared equalstest harness with an IncludeUnexported() 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
puertomontt added this pull request to the merge queue Jul 1, 2026
@puertomontt
puertomontt removed this pull request from the merge queue due to a manual request Jul 1, 2026
@puertomontt
puertomontt added this pull request to the merge queue Jul 1, 2026
Merged via the queue into kgateway-dev:v2.3.x with commit 3845e45 Jul 1, 2026
32 of 37 checks passed
@puertomontt
puertomontt deleted the cherry-pick-14331-v2.3.x branch July 1, 2026 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/fix Categorizes issue or PR as related to a bug. release-note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants