Skip to content

Commit ecbb5d5

Browse files
authored
fix: omit uris field when HTTPRoute path type is RegularExpression (backport apache/apisix-ingress-controller#2770) (#417)
1 parent 74aea55 commit ecbb5d5

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

internal/adc/translator/httproute.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,10 @@ func (t *Translator) translateGatewayHTTPRouteMatch(match *gatewayv1.HTTPRouteMa
741741
})
742742

743743
route.Vars = append(route.Vars, this)
744+
// APISIX Admin API requires uris to be a non-null array. Use "/*"
745+
// as a catch-all so APISIX accepts the route; the vars entry above
746+
// performs the actual regex filtering.
747+
route.Uris = []string{"/*"}
744748
default:
745749
return nil, errors.New("unknown path match type " + string(*match.Path.Type))
746750
}

test/e2e/gatewayapi/httproute.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,60 @@ spec:
942942
})
943943
})
944944

945+
It("HTTPRoute RegularExpression Match", func() {
946+
var regexRoute = fmt.Sprintf(`
947+
apiVersion: gateway.networking.k8s.io/v1
948+
kind: HTTPRoute
949+
metadata:
950+
name: httpbin
951+
spec:
952+
parentRefs:
953+
- name: %s
954+
hostnames:
955+
- httpbin.example
956+
rules:
957+
- matches:
958+
- path:
959+
type: RegularExpression
960+
value: /status/[0-9]+
961+
backendRefs:
962+
- name: httpbin-service-e2e-test
963+
port: 80
964+
`, s.Namespace())
965+
966+
By("create HTTPRoute with RegularExpression path type")
967+
s.ResourceApplied("HTTPRoute", "httpbin", regexRoute, 1)
968+
969+
By("access dataplane: path matching regex should succeed")
970+
s.RequestAssert(&scaffold.RequestAssert{
971+
Method: "GET",
972+
Path: "/status/200",
973+
Host: "httpbin.example",
974+
Check: scaffold.WithExpectedStatus(http.StatusOK),
975+
Timeout: time.Second * 30,
976+
Interval: time.Second * 2,
977+
})
978+
979+
s.RequestAssert(&scaffold.RequestAssert{
980+
Method: "GET",
981+
Path: "/status/201",
982+
Host: "httpbin.example",
983+
Check: scaffold.WithExpectedStatus(http.StatusCreated),
984+
Timeout: time.Second * 30,
985+
Interval: time.Second * 2,
986+
})
987+
988+
By("access dataplane: path not matching regex should return 404")
989+
s.RequestAssert(&scaffold.RequestAssert{
990+
Method: "GET",
991+
Path: "/status/ok",
992+
Host: "httpbin.example",
993+
Check: scaffold.WithExpectedStatus(http.StatusNotFound),
994+
Timeout: time.Second * 30,
995+
Interval: time.Second * 2,
996+
})
997+
})
998+
945999
It("HTTPRoute Method Match", func() {
9461000
By("create HTTPRoute")
9471001
s.ResourceApplied("HTTPRoute", "httpbin", fmt.Sprintf(methodRouteGETAndDELETEByAnything, s.Namespace()), 1)

0 commit comments

Comments
 (0)