[SOLVED] VirtualService: match all except prefix?

Hi,

I would like to match a “all except prefix” for a VirtualService but I did not find an example…

I thought about using a regexp but saw this https://stackoverflow.com/a/61071071 and Regex negative lookahead not working in VirtualService HTTPMatchRequest · Issue #23416 · istio/istio · GitHub telling Google Re2 doesn’t support this.

Any idea how can I do?

Otherwise I could add another HTTPRule that matches those with the prefix to send nowhere, but how to do route to nowhere?

Thank you,

You can get that behavior using multiple http routes, just putting the one that you want to block as the first with a fault injected, and the catchall after. Like this:

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: nginx-fault
spec:
  hosts:
  - nginx
  http:
  - match:
    - uri:
        prefix: "/fault" # the prefix you want to drop
    fault:
      abort:
        percentage:
          value: 100
        httpStatus: 400 # Any return code you want
    route:
    - destination:
        host: none
  - route: # catchall rule
    - destination:
        host: nginx 
1 Like

Thank you @lucasslima ! Indeed it makes the trick even if it’s a bit uggly to get
image

And not something related to the httpStatus 404 I set ^^