diff --git a/changelog/v1.18.0-rc3/platform-agnostic-lbephash.yaml b/changelog/v1.18.0-rc3/platform-agnostic-lbephash.yaml new file mode 100644 index 00000000000..049b7fdc8c5 --- /dev/null +++ b/changelog/v1.18.0-rc3/platform-agnostic-lbephash.yaml @@ -0,0 +1,6 @@ +changelog: + - type: NON_USER_FACING + description: >- + Don't use native endian-ness when generating hashes. + This creates difficulty reproducing tests on different machines + where the hashes end up in goldenfiles. diff --git a/projects/gateway2/krtcollections/endpoints.go b/projects/gateway2/krtcollections/endpoints.go index 4a69ba85c09..611b23df16d 100644 --- a/projects/gateway2/krtcollections/endpoints.go +++ b/projects/gateway2/krtcollections/endpoints.go @@ -170,8 +170,8 @@ func hashEndpoints(l PodLocality, emd EndpointWithMd) uint64 { func hash(a, b uint64) uint64 { hasher := fnv.New64a() var buf [16]byte - binary.NativeEndian.PutUint64(buf[:8], a) - binary.NativeEndian.PutUint64(buf[8:], b) + binary.LittleEndian.PutUint64(buf[:8], a) + binary.LittleEndian.PutUint64(buf[8:], b) hasher.Write(buf[:]) return hasher.Sum64() } diff --git a/projects/gateway2/krtcollections/endpoints_test.go b/projects/gateway2/krtcollections/endpoints_test.go index 1f4d84d7191..40c8348d9f6 100644 --- a/projects/gateway2/krtcollections/endpoints_test.go +++ b/projects/gateway2/krtcollections/endpoints_test.go @@ -131,7 +131,6 @@ func TestEndpointsForUpstreamOrderDoesntMatter(t *testing.T) { Zone: "zone2", }, emd2) g.Expect(result1.Equals(*result4)).To(BeFalse(), "not expected %v, got %v", result1, result2) - } func TestEndpointsForUpstreamWithDiscoveredUpstream(t *testing.T) { @@ -239,7 +238,6 @@ func TestEndpointsForUpstreamWithDiscoveredUpstream(t *testing.T) { h2 := result3.LbEpsEqualityHash ^ result4.LbEpsEqualityHash g.Expect(h1).NotTo(Equal(h2), "not expected %v, got %v", h1, h2) - } func TestEndpoints(t *testing.T) { @@ -960,5 +958,4 @@ func TestEndpoints(t *testing.T) { g.Expect(eps.Equals(*res)).To(BeTrue(), "expected %v, got %v", res, eps) }) } - } diff --git a/projects/gateway2/utils/hash.go b/projects/gateway2/utils/hash.go index e787776475c..8ec7b988b76 100644 --- a/projects/gateway2/utils/hash.go +++ b/projects/gateway2/utils/hash.go @@ -119,7 +119,7 @@ func hashValue(newhash func() hash.Hash64, h hash.Hash, value *structpb.Value) e func HashUint64(hasher io.Writer, value uint64) { var bytes [8]byte - binary.NativeEndian.PutUint64(bytes[:], value) + binary.LittleEndian.PutUint64(bytes[:], value) hasher.Write(bytes[:]) }