The pipe character does not seem to work in Istio's VirtualService
.
The example below is intended to route requests based on the user-agent
header. Requests from a mobile device should go to myapp
and requests from a desktop user should go to deskt-app
, handled by next match block. The <REGEX>
field works when I use this regex:
^.*\bMobile\b.*$
But the powers that be require a more sophisticated regex to identify mobile users. My routing breaks entirely when I use these:
^.*\b(iPhone|Pixel)\b.*$
^.*\b(iPhone|Pixel)+\b.*$
^.*\biPhone|Pixel\b.*$
Using a regex with a pipe (logical OR) I expect to be routed to myapp
when I have a user-agent
header that contains the word "iPhone" or "Pixel".
I get routed to deskt-app
.
How do I achieve a logical OR in an Istio VirtualService
regex pattern? And is that my problem or am I overlooking something obvious?
VirtualService
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
...
...
http:
- match:
- headers:
user-agent:
regex: "<REGEX>" <------
uri:
prefix: /foo/bar
route:
- destination:
host: myapp
port:
number: 80
- match:
- uri:
prefix: /foo/bar
route:
- destination:
host: deskt-app
port:
number: 80
EDIT: Github Issue
Your configuration is correct, so the issue must be with the Regex, or the contents of the user-agent are different, give this a try '^.*(iPhone|Pixel).*#x27;
Just verified that the configuration below routes correctly when the header contains android or iphone:
- match:
- headers:
user-agent:
regex: '^.*(Android|iPhone).*#x27;
And tested with:
[match] curl -H "user-agent: Mozilla/5.0 (Linux; U; iPhone 4.4.2; en-us;)" ...
[no match] curl -H "user-agent: Mozilla/5.0 (Linux; U; Iphne 4.4.2; en-us;)" ...