Commit 42470de
committed
fix(gateway): correct BackendRef matching and canary header build
Fixes in pkg/trafficrouting/network/gateway/gateway.go:
* getServiceBackendRef: per the Gateway API spec, BackendObjectReference.Kind
defaults to "Service" when nil. The previous check
`ref.Kind != nil && *ref.Kind == "Service"` skipped refs without an
explicit Kind, so HTTPRoutes emitted by controllers that omit the field
(e.g. Envoy Gateway) were never recognised as stable/canary backends and
the rollout silently failed to inject canary traffic. Treat nil Kind as
Service. Also return (-1, nil) on miss instead of (0, nil) to remove the
ambiguity between "not found" and "found at index 0".
* setServiceBackendRef: symmetric fix — refuse only when an explicit Kind
other than Service is set, so canary BackendRefs derived from a stable
ref with nil Kind can be written back. Replace the manual slice rebuild
with an in-place assignment.
* buildCanaryHeaderHttpRoutes: the inner loop indexed `matches[k]` while
`k` ranged over `nonPathMatches`. The two slices have different lengths
whenever a path-bearing match is not the first element, so headers and
query params from the wrong match were grafted onto canary rules. Index
`nonPathMatches[k]` instead.
* buildCanaryHeaderHttpRoutes: the shallow copy
`canaryRuleMatchBase := *canaryRuleMatch` shares the underlying arrays
of Headers/QueryParams with the original rule. Subsequent appends could
mutate the original HTTPRoute when its slices had spare capacity. Clone
the slices before extending; preserve nil-ness to keep output identical
to the previous implementation when nothing is appended.
* EnsureRoutes: surface the error from
intstr.GetScaledValueFromIntOrPercent rather than silently coercing
malformed traffic strings to 0 %.
* EnsureRoutes / Finalise: pass the inbound ctx to client Get/Update
inside the retry closure instead of context.TODO(), so cancellation and
deadlines propagate.
Tests in pkg/trafficrouting/network/gateway/gateway_test.go:
* Added regression cases covering BackendRefs with nil Kind across the
weight, header, and finalise code paths.
* Added a case where matches mix path and non-path entries so that
pathMatches and nonPathMatches diverge in length, exercising the
index-correctness fix.
* Added a clean-state weight canary case; the existing weight-20 case
fed in the final 80/20 shape and only proved idempotence.
* Added TestInitialize, TestEnsureRoutesAndFinalise, and
TestEnsureRoutesInvalidTraffic to drive the controller end-to-end
against a fake client, covering happy path, idempotence, finalise,
rollback, and invalid-input rejection.
Signed-off-by: Marco Ma <qingjin_ma@163.com>1 parent b2600e9 commit 42470de
2 files changed
Lines changed: 627 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
66 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
67 | 71 | | |
68 | 72 | | |
69 | 73 | | |
| |||
81 | 85 | | |
82 | 86 | | |
83 | 87 | | |
84 | | - | |
| 88 | + | |
85 | 89 | | |
86 | 90 | | |
87 | 91 | | |
88 | 92 | | |
89 | | - | |
| 93 | + | |
90 | 94 | | |
91 | 95 | | |
92 | 96 | | |
| |||
112 | 116 | | |
113 | 117 | | |
114 | 118 | | |
115 | | - | |
| 119 | + | |
116 | 120 | | |
117 | 121 | | |
118 | 122 | | |
119 | 123 | | |
120 | | - | |
| 124 | + | |
121 | 125 | | |
122 | 126 | | |
123 | 127 | | |
| |||
194 | 198 | | |
195 | 199 | | |
196 | 200 | | |
197 | | - | |
198 | | - | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
199 | 213 | | |
200 | | - | |
201 | | - | |
| 214 | + | |
| 215 | + | |
202 | 216 | | |
203 | 217 | | |
204 | 218 | | |
| |||
241 | 255 | | |
242 | 256 | | |
243 | 257 | | |
244 | | - | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
245 | 263 | | |
246 | 264 | | |
247 | 265 | | |
248 | | - | |
| 266 | + | |
249 | 267 | | |
250 | 268 | | |
251 | 269 | | |
252 | | - | |
| 270 | + | |
253 | 271 | | |
254 | 272 | | |
255 | 273 | | |
256 | | - | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
257 | 277 | | |
258 | 278 | | |
259 | 279 | | |
260 | 280 | | |
261 | 281 | | |
262 | 282 | | |
263 | 283 | | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
| 284 | + | |
273 | 285 | | |
274 | 286 | | |
275 | 287 | | |
| |||
0 commit comments