File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ```release-note:bug
2+ api-gateway: allow http-routes to set `weight: 0` to disable traffic to particular service
3+ ```
Original file line number Diff line number Diff line change @@ -105,8 +105,19 @@ func (e *HTTPRouteConfigEntry) Normalize() error {
105105 rule .Matches [j ] = normalizeHTTPMatch (match )
106106 }
107107
108+ allServicesHaveZeroWeight := true
108109 for j , service := range rule .Services {
109110 rule .Services [j ] = e .normalizeHTTPService (service )
111+ if rule .Services [j ].Weight != 0 {
112+ allServicesHaveZeroWeight = false
113+ }
114+ }
115+ // Preserve historical behavior for routes that omit all service weights by
116+ // normalizing them to 1.
117+ if allServicesHaveZeroWeight {
118+ for j := range rule .Services {
119+ rule .Services [j ].Weight = 1
120+ }
110121 }
111122 e .Rules [i ] = rule
112123 }
@@ -123,7 +134,7 @@ func (e *HTTPRouteConfigEntry) Normalize() error {
123134func (e * HTTPRouteConfigEntry ) normalizeHTTPService (service HTTPService ) HTTPService {
124135 service .Merge (e .GetEnterpriseMeta ())
125136 service .Normalize ()
126- if service .Weight <= 0 {
137+ if service .Weight < 0 {
127138 service .Weight = 1
128139 }
129140 return service
Original file line number Diff line number Diff line change @@ -338,7 +338,7 @@ func TestHTTPRoute(t *testing.T) {
338338 }},
339339 },
340340 },
341- "rule normalizes service weight" : {
341+ "rule preserves zero service weight and normalizes negative service weight" : {
342342 entry : & HTTPRouteConfigEntry {
343343 Kind : HTTPRoute ,
344344 Name : "route-one" ,
@@ -355,6 +355,29 @@ func TestHTTPRoute(t *testing.T) {
355355 },
356356 }},
357357 },
358+ check : func (t * testing.T , entry ConfigEntry ) {
359+ route := entry .(* HTTPRouteConfigEntry )
360+ require .Equal (t , 0 , route .Rules [0 ].Services [0 ].Weight )
361+ require .Equal (t , 1 , route .Rules [0 ].Services [1 ].Weight )
362+ },
363+ },
364+ "rule normalizes all-zero service weights to defaults" : {
365+ entry : & HTTPRouteConfigEntry {
366+ Kind : HTTPRoute ,
367+ Name : "route-one" ,
368+ Rules : []HTTPRouteRule {{
369+ Services : []HTTPService {
370+ {
371+ Name : "test" ,
372+ Weight : 0 ,
373+ },
374+ {
375+ Name : "test2" ,
376+ Weight : 0 ,
377+ },
378+ },
379+ }},
380+ },
358381 check : func (t * testing.T , entry ConfigEntry ) {
359382 route := entry .(* HTTPRouteConfigEntry )
360383 require .Equal (t , 1 , route .Rules [0 ].Services [0 ].Weight )
You can’t perform that action at this time.
0 commit comments