Skip to content

Commit 2f3bed7

Browse files
committed
Fix conformance test
1 parent d2f7d45 commit 2f3bed7

File tree

2 files changed

+89
-14
lines changed

2 files changed

+89
-14
lines changed

internal/controller/status/prepare_requests.go

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,29 +98,36 @@ func PrepareRouteRequests(
9898
// removeDuplicateIndexParentRefs removes duplicate ParentRefs by Idx, keeping the first occurrence.
9999
// If an Idx is duplicated, the SectionName for the stored ParentRef is nil.
100100
func removeDuplicateIndexParentRefs(parentRefs []graph.ParentRef) []graph.ParentRef {
101-
idxCount := make(map[int]int)
101+
idxToParentRef := make(map[int][]graph.ParentRef)
102102
for _, ref := range parentRefs {
103-
idxCount[ref.Idx]++
103+
idxToParentRef[ref.Idx] = append(idxToParentRef[ref.Idx], ref)
104104
}
105105

106-
seen := make(map[int]bool)
107-
result := make([]graph.ParentRef, 0, len(parentRefs))
106+
results := make([]graph.ParentRef, len(idxToParentRef))
108107

109-
for _, ref := range parentRefs {
110-
if seen[ref.Idx] {
111-
continue // skip duplicates
108+
for idx, refs := range idxToParentRef {
109+
if len(refs) == 1 {
110+
results[idx] = refs[0]
111+
continue
112112
}
113-
seen[ref.Idx] = true
114113

115-
// If this Idx was duplicated, clear SectionName
116-
if idxCount[ref.Idx] > 1 {
117-
ref.SectionName = nil
114+
winningParentRef := graph.ParentRef{
115+
Idx: idx,
116+
Gateway: refs[0].Gateway,
117+
Attachment: refs[0].Attachment,
118118
}
119119

120-
result = append(result, ref)
120+
for _, ref := range refs {
121+
if ref.Attachment.Attached {
122+
if len(ref.Attachment.FailedConditions) == 0 || winningParentRef.Attachment == nil {
123+
winningParentRef.Attachment = ref.Attachment
124+
}
125+
}
126+
}
127+
results[idx] = winningParentRef
121128
}
122129

123-
return result
130+
return results
124131
}
125132

126133
func prepareRouteStatus(

internal/controller/status/prepare_requests_test.go

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ var (
7878
{
7979
SectionName: helpers.GetPointer[v1.SectionName]("listener-443-2"),
8080
},
81+
{
82+
SectionName: helpers.GetPointer[v1.SectionName]("listener-443-3"),
83+
},
84+
{
85+
SectionName: helpers.GetPointer[v1.SectionName]("listener-8080-1"),
86+
},
87+
{
88+
SectionName: helpers.GetPointer[v1.SectionName]("listener-8080-2"),
89+
},
8190
},
8291
}
8392

@@ -121,7 +130,8 @@ var (
121130
Gateway: &graph.ParentRefGateway{NamespacedName: gwNsName},
122131
SectionName: commonRouteSpecValid.ParentRefs[3].SectionName,
123132
Attachment: &graph.ParentRefAttachmentStatus{
124-
Attached: true,
133+
Attached: false,
134+
FailedConditions: []conditions.Condition{invalidAttachmentCondition},
125135
},
126136
},
127137
{
@@ -132,6 +142,33 @@ var (
132142
Attached: true,
133143
},
134144
},
145+
{
146+
Idx: 3,
147+
Gateway: &graph.ParentRefGateway{NamespacedName: gwNsName},
148+
SectionName: commonRouteSpecValid.ParentRefs[5].SectionName,
149+
Attachment: &graph.ParentRefAttachmentStatus{
150+
Attached: true,
151+
FailedConditions: []conditions.Condition{invalidAttachmentCondition},
152+
},
153+
},
154+
{
155+
Idx: 4,
156+
Gateway: &graph.ParentRefGateway{NamespacedName: gwNsName},
157+
SectionName: commonRouteSpecValid.ParentRefs[6].SectionName,
158+
Attachment: &graph.ParentRefAttachmentStatus{
159+
Attached: false,
160+
FailedConditions: []conditions.Condition{invalidAttachmentCondition},
161+
},
162+
},
163+
{
164+
Idx: 4,
165+
Gateway: &graph.ParentRefGateway{NamespacedName: gwNsName},
166+
SectionName: commonRouteSpecValid.ParentRefs[7].SectionName,
167+
Attachment: &graph.ParentRefAttachmentStatus{
168+
Attached: false,
169+
FailedConditions: []conditions.Condition{invalidAttachmentCondition},
170+
},
171+
},
135172
}
136173

137174
parentRefsInvalid = []graph.ParentRef{
@@ -260,6 +297,37 @@ var (
260297
},
261298
},
262299
},
300+
{
301+
ParentRef: v1.ParentReference{
302+
Namespace: helpers.GetPointer(v1.Namespace(gwNsName.Namespace)),
303+
Name: v1.ObjectName(gwNsName.Name),
304+
},
305+
ControllerName: gatewayCtlrName,
306+
Conditions: []metav1.Condition{
307+
{
308+
Type: string(v1.RouteConditionAccepted),
309+
Status: metav1.ConditionTrue,
310+
ObservedGeneration: 3,
311+
LastTransitionTime: transitionTime,
312+
Reason: string(v1.RouteReasonAccepted),
313+
Message: "The route is accepted",
314+
},
315+
{
316+
Type: string(v1.RouteConditionResolvedRefs),
317+
Status: metav1.ConditionTrue,
318+
ObservedGeneration: 3,
319+
LastTransitionTime: transitionTime,
320+
Reason: string(v1.RouteReasonResolvedRefs),
321+
Message: "All references are resolved",
322+
},
323+
{
324+
Type: invalidAttachmentCondition.Type,
325+
Status: metav1.ConditionTrue,
326+
ObservedGeneration: 3,
327+
LastTransitionTime: transitionTime,
328+
},
329+
},
330+
},
263331
},
264332
}
265333

0 commit comments

Comments
 (0)