首页 > 解决方案 > 是否可以在虚拟服务定义中组合 AND 和 OR 匹配?

问题描述

我正在尝试在 Istio (1.3.3) 中定义一个虚拟服务,它有多个匹配项,但在匹配项中,应该有 OR 功能。

例如:(伪代码)

  match
     header-key = value1
  OR header-key = value2
  OR header-key = value3
  OR ....
  OR header-key = value100

AND 

  match
     uri-prefix = prefix1
  OR uri-prefix = prefix2
  OR uri-prefix = prefix3
  OR uri-prefix = ...
  OR uri-prefix = prefix100

因此,对于每个 AND 块,应该至少有一个匹配的 OR 条件。

我已经尝试过匹配,但是如果满足所有条件中的 1 个,那么它是有效的,但我想要的是匹配 API 密钥之一并匹配 URI 前缀之一。

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: test
  namespace: demo
spec:
  hosts:
  - test1
  gateways:
  - test-gateway  
  http:
    - match:
        - headers:
            apikey:
              exact: 111
        - headers:
            apikey:
              exact: 222
        - headers:
            apikey:
              exact: 333
        - uri:
            prefix: /path1/
        - uri:
            prefix: /path2/
      rewrite:
        uri: /newpath/v1/
        authority: test2
      route:
        - destination:
            host: test2
    - fault:
        abort:
          httpStatus: 444
          percent: 100
      route:
      - destination:
          host: test2

标签: istio

解决方案


推荐阅读