diff --git a/agent/structs/config_entry_routes.go b/agent/structs/config_entry_routes.go index 801e22f18cbe..1235723f89f2 100644 --- a/agent/structs/config_entry_routes.go +++ b/agent/structs/config_entry_routes.go @@ -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 } diff --git a/agent/structs/config_entry_routes_test.go b/agent/structs/config_entry_routes_test.go index 83ab8c4d79e0..37c20390a311 100644 --- a/agent/structs/config_entry_routes_test.go +++ b/agent/structs/config_entry_routes_test.go @@ -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) }