Skip to content

Commit

Permalink
NET-2903 Normalize weight for http routes
Browse files Browse the repository at this point in the history
  • Loading branch information
missylbytes committed Mar 2, 2023
1 parent 4f8594b commit 10ef73a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion agent/structs/config_entry_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ func (e *HTTPRouteConfigEntry) Normalize() error {

func normalizeHTTPService(service HTTPService) HTTPService {
service.EnterpriseMeta.Normalize()

if service.Weight <= 0 {
service.Weight = 1
}
return service
}

Expand Down
22 changes: 22 additions & 0 deletions agent/structs/config_entry_routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,28 @@ func TestHTTPRoute(t *testing.T) {
}},
},
},
"rule normalizes service weight": {
entry: &HTTPRouteConfigEntry{
Kind: HTTPRoute,
Name: "route-one",
Rules: []HTTPRouteRule{{
Services: []HTTPService{
{
Name: "test",
Weight: 0,
},
{
Name: "test2",
Weight: -1,
}},
}},
},
check: func(t *testing.T, entry ConfigEntry) {
route := entry.(*HTTPRouteConfigEntry)
require.Equal(t, 1, route.Rules[0].Services[0].Weight)
require.Equal(t, 1, route.Rules[0].Services[1].Weight)
},
},
}
testConfigEntryNormalizeAndValidate(t, cases)
}

0 comments on commit 10ef73a

Please sign in to comment.