From 7eb65188e755168f4df8cda96ec2d44b03af87de Mon Sep 17 00:00:00 2001 From: Saylor Berman Date: Fri, 13 Jun 2025 15:24:35 -0600 Subject: [PATCH] Fix index out of bounds error when building status (#3513) Problem: There's a specific scenario where we can hit an out of bounds index while building route statuses. I don't know the exact scenario, but it involves a parentRef without a sectionName, on a Gateway with a single listener. Could possibly involve having multiple implementations being deployed as well. Solution: Adjust the logic to ensure we don't access indices that are out of bounds. --- internal/controller/status/prepare_requests.go | 6 +++--- internal/controller/status/prepare_requests_test.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/controller/status/prepare_requests.go b/internal/controller/status/prepare_requests.go index 4cb8fd5eab..f1909c1570 100644 --- a/internal/controller/status/prepare_requests.go +++ b/internal/controller/status/prepare_requests.go @@ -103,11 +103,11 @@ func removeDuplicateIndexParentRefs(parentRefs []graph.ParentRef) []graph.Parent idxToParentRef[ref.Idx] = append(idxToParentRef[ref.Idx], ref) } - results := make([]graph.ParentRef, len(idxToParentRef)) + results := make([]graph.ParentRef, 0, len(idxToParentRef)) for idx, refs := range idxToParentRef { if len(refs) == 1 { - results[idx] = refs[0] + results = append(results, refs[0]) continue } @@ -124,7 +124,7 @@ func removeDuplicateIndexParentRefs(parentRefs []graph.ParentRef) []graph.Parent } } } - results[idx] = winningParentRef + results = append(results, winningParentRef) } return results diff --git a/internal/controller/status/prepare_requests_test.go b/internal/controller/status/prepare_requests_test.go index 2480423d1e..f813f18335 100644 --- a/internal/controller/status/prepare_requests_test.go +++ b/internal/controller/status/prepare_requests_test.go @@ -445,7 +445,7 @@ func TestBuildHTTPRouteStatuses(t *testing.T) { err := k8sClient.Get(context.Background(), nsname, &hr) g.Expect(err).ToNot(HaveOccurred()) - g.Expect(helpers.Diff(expected, hr.Status)).To(BeEmpty()) + g.Expect(expected.RouteStatus.Parents).To(ConsistOf(hr.Status.Parents)) } } @@ -524,7 +524,7 @@ func TestBuildGRPCRouteStatuses(t *testing.T) { err := k8sClient.Get(context.Background(), nsname, &hr) g.Expect(err).ToNot(HaveOccurred()) - g.Expect(helpers.Diff(expected, hr.Status)).To(BeEmpty()) + g.Expect(expected.RouteStatus.Parents).To(ConsistOf(hr.Status.Parents)) } } @@ -601,7 +601,7 @@ func TestBuildTLSRouteStatuses(t *testing.T) { err := k8sClient.Get(context.Background(), nsname, &hr) g.Expect(err).ToNot(HaveOccurred()) - g.Expect(helpers.Diff(expected, hr.Status)).To(BeEmpty()) + g.Expect(expected.RouteStatus.Parents).To(ConsistOf(hr.Status.Parents)) } }