Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DAG ignores routes with same prefix, same header name (":method") but different header value #2599

Closed
chintan8saaras opened this issue Jun 17, 2020 · 3 comments

Comments

@chintan8saaras
Copy link

What steps did you take and what happened:
In a use-case where there are two routes defined

(1) Method: GET, Prefix: /
(2) Method: POST, Prefix /

What did you expect to happen:

Such config should create two routes on Envoy

Anything else you would like to add:

Here is a patch with -
(1) A test that captures the failure
(2) Fix

LMK if I should create a PR for this fix.


diff --git a/internal/contour/route_test.go b/internal/contour/route_test.go
index 4a0171c..81172a6 100644
--- a/internal/contour/route_test.go
+++ b/internal/contour/route_test.go
@@ -1943,6 +1943,90 @@ func TestRouteVisit(t *testing.T) {
                    )),
            ),
        },
+       "httpproxy with multiple routes with same prefix and different header": {
+           objs: []interface{}{
+               &projcontour.HTTPProxy{
+                   ObjectMeta: metav1.ObjectMeta{
+                       Name:      "simple",
+                       Namespace: "default",
+                   },
+                   Spec: projcontour.HTTPProxySpec{
+                       VirtualHost: &projcontour.VirtualHost{
+                           Fqdn: "www.example.com",
+                       },
+                       Routes: []projcontour.Route{{
+                           Conditions: []projcontour.Condition{
+                               {
+                                   Prefix: "/",
+                               },
+                               {
+                                   Header: &projcontour.HeaderCondition{
+                                        Name:    ":method",
+                                       Exact: "GET",
+                                   },
+                               },
+                           },
+                           Services: []projcontour.Service{{
+                               Name: "backend",
+                               Port: 80,
+                           }},
+                       },
+                        {
+                           Conditions: []projcontour.Condition{
+                               {
+                                   Prefix: "/",
+                               },
+                               {
+                                   Header: &projcontour.HeaderCondition{
+                                        Name:    ":method",
+                                       Exact: "POST",
+                                   },
+                               },
+                           },
+                           Services: []projcontour.Service{{
+                               Name: "backend",
+                               Port: 80,
+                           }},
+                       }},
+                   },
+               },
+               &v1.Service{
+                   ObjectMeta: metav1.ObjectMeta{
+                       Name:      "backend",
+                       Namespace: "default",
+                   },
+                   Spec: v1.ServiceSpec{
+                       Ports: []v1.ServicePort{{
+                           Protocol:   "TCP",
+                           Port:       80,
+                           TargetPort: intstr.FromInt(8080),
+                       }},
+                   },
+               },
+           },
+           want: routeConfigurations(
+               envoy.RouteConfiguration("ingress_http",
+                   envoy.VirtualHost("www.example.com",
+                       &envoy_api_v2_route.Route{
+                           Match: routePrefix("/", dag.HeaderCondition{
+                                Name:      ":method",
+                               MatchType: "exact",
+                               Value:     "GET",
+                           }),
+                           Action: routecluster("default/backend/80/da39a3ee5e"),
+                       },
+                       &envoy_api_v2_route.Route{
+                           Match: routePrefix("/", dag.HeaderCondition{
+                                Name:      ":method",
+                               MatchType: "exact",
+                               Value:     "POST",
+                           }),
+                           Action: routecluster("default/backend/80/da39a3ee5e"),
+                       },
+                   )),
+           ),
+       },
+
        "httpproxy with route-level header manipulation": {
            objs: []interface{}{
                &projcontour.HTTPProxy{
diff --git a/internal/dag/dag.go b/internal/dag/dag.go
index 1de2d76..d4a8b3f 100644
--- a/internal/dag/dag.go
+++ b/internal/dag/dag.go
@@ -79,7 +79,7 @@ type HeaderCondition struct {
 }

 func (hc *HeaderCondition) String() string {
-   return "header: " + hc.Name
+    return "header: " + hc.Name + " value: " + hc.Value
 }

 // Route defines the properties of a route to a Cluster.

Environment:

  • Contour version:

Latest with this commit -

commit 5db62a956e1b07ffe8e7b6881e17faf10a7ac761
Author: Nick Young <ynick@vmware.com>
Date:   Wed Jun 17 15:50:23 2020 +1000

    Remove remaining IngressRoute code (#2593)

    Updates #2572.

    I've left type switches with only one (HTTPProxy) type intact for now, as we will need
    to add the Service-APIs types later, and some stuff will be moved or removed as
    part of the status updates.

    Also remove all the code from `internal/`.
    Remove the CRDs from code generation and YAML generation.

    Signed-off-by: Nick Young <ynick@vmware.com>
  • Kubernetes version: (use kubectl version):
  • Kubernetes installer & version:
  • Cloud provider or hardware configuration:
  • OS (e.g. from /etc/os-release):
@skriss
Copy link
Member

skriss commented Jun 17, 2020

@chintan8saaras looks like you noticed the same thing I did earlier today -- see #2597 and #2600

@jpeach
Copy link
Contributor

jpeach commented Jun 17, 2020

Duplicate of #2597

@jpeach jpeach marked this as a duplicate of #2597 Jun 17, 2020
@jpeach jpeach closed this as completed Jun 17, 2020
@chintan8saaras
Copy link
Author

😄 You beat me to it by a couple of hours ! Glad it got caught and fixed !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants