Skip to content

Commit

Permalink
fix: dup route names in multi httproute matches
Browse files Browse the repository at this point in the history
  • Loading branch information
shaneutt committed Mar 22, 2022
1 parent 1c05a64 commit c37ce02
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@

#### Fixed

- Fixed an issue where duplicated route names in `HTTPRoute` resources with
multiple matches would cause the Kong Admin API to collide the routes into
one, effectively dropping routes for services beyond the first.
[#2345](https:/Kong/kubernetes-ingress-controller/pull/2345)
- Status updates for `HTTPRoute` objects no longer mark the resource as
`ConditionRouteAccepted` until the object has been successfully configured
in Kong Gateway at least once, as long as `--update-status`
Expand Down
9 changes: 5 additions & 4 deletions internal/dataplane/parser/translate_httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func ingressRulesFromHTTPRoute(result *ingressRules, httproute *gatewayv1alpha2.

// each rule may represent a different set of backend services that will be accepting
// traffic, so we make separate routes and Kong services for every present rule.
for _, rule := range spec.Rules {
for ruleNumber, rule := range spec.Rules {
// TODO: add this to a generic HTTPRoute validation, and then we should probably
// simply be calling validation on each httproute object at the begininning
// of the topmost list.
Expand All @@ -74,7 +74,7 @@ func ingressRulesFromHTTPRoute(result *ingressRules, httproute *gatewayv1alpha2.
}

// determine the routes needed to route traffic to services for this rule
routes, err := generateKongRoutesFromHTTPRouteRule(httproute, rule)
routes, err := generateKongRoutesFromHTTPRouteRule(httproute, ruleNumber, rule)
if err != nil {
return err
}
Expand Down Expand Up @@ -112,7 +112,7 @@ func getHTTPRouteHostnamesAsSliceOfStringPointers(httproute *gatewayv1alpha2.HTT
// path prefix routing option for that service in addition to hostname routing.
// If an HTTPRoute is provided that has matches that include any unsupported matching
// configurations, this will produce an error and the route is considered invalid.
func generateKongRoutesFromHTTPRouteRule(httproute *gatewayv1alpha2.HTTPRoute, rule gatewayv1alpha2.HTTPRouteRule) ([]kongstate.Route, error) {
func generateKongRoutesFromHTTPRouteRule(httproute *gatewayv1alpha2.HTTPRoute, ruleNumber int, rule gatewayv1alpha2.HTTPRouteRule) ([]kongstate.Route, error) {
// gather the k8s object information and hostnames from the httproute
objectInfo := util.FromK8sObject(httproute)
hostnames := getHTTPRouteHostnamesAsSliceOfStringPointers(httproute)
Expand All @@ -127,9 +127,10 @@ func generateKongRoutesFromHTTPRouteRule(httproute *gatewayv1alpha2.HTTPRoute, r
// determine the name of the route, identify it as a route that belongs
// to a Kubernetes HTTPRoute object.
routeName := kong.String(fmt.Sprintf(
"httproute.%s.%s.%d",
"httproute.%s.%s.%d.%d",
httproute.Namespace,
httproute.Name,
ruleNumber,
matchNumber,
))

Expand Down

0 comments on commit c37ce02

Please sign in to comment.