简体   繁体   English

如何将 EnvoyFilter 应用于 Sidecar Inbound 和 Gateway?

[英]How to apply EnvoyFilter to Sidecar Inbound and Gateway?

I want to configure an EnvoyFilter to run only on Gateway and Sidecar-Inbound.我想将 EnvoyFilter 配置为仅在 Gateway 和 Sidecar-Inbound 上运行。 Gateway and the Apps are in different namespaces.网关和应用程序位于不同的命名空间中。

If I specify the context as ANY, it will apply to Gateway, Sidecar-inbound and sidecar-outbound.如果我将上下文指定为 ANY,它将适用于 Gateway、Sidecar-inbound 和 sidecar-outbound。 However, I want it to apply only to Gateway and Sidecar-Inbound.但是,我希望它仅适用于 Gateway 和 Sidecar-Inbound。 how can I do that?我怎样才能做到这一点?

apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:  
  name: filter-0-mydebugger
  namespace: istio-system
spec:
  configPatches:
  - applyTo: HTTP_FILTER
    match:
      context: GATEWAY # AND SIDECAR-INBOUND HOW?
      listener:
        filterChain:
          filter:
            name: envoy.http_connection_manager
            subFilter:
              name: envoy.router
    patch:
      operation: INSERT_BEFORE
      value:
        name: envoy.lua.mydebugger
        typed_config:
          '@type': type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua
          inlineCode: |
            function envoy_on_request(request_handle)              
              request_handle:logInfo("HelloWorld")             
            end

If you see, I have set the context to GATEWAY.如果您看到,我已将上下文设置为 GATEWAY。 How can I specify multiple matches - Gateway and Sidecar-Inbound?如何指定多个匹配项 - 网关和 Sidecar-Inbound? (Without having to repeat/duplicate the patch section) (无需重复/复制补丁部分)

The context is an enum so you can't do something like [GATEWAY, SIDECAR_INBOUND] . context是一个枚举,所以你不能做类似[GATEWAY, SIDECAR_INBOUND]的事情。 Therefore, unfortunately you will need to create another element inside configPatches with an applyTo , match , and patch .因此,不幸的是,您需要在configPatches中使用applyTomatchpatch创建另一个元素。

However, with yaml you can use anchors( & ) and references( * ) to reuse blocks of code which makes the duplication easier.但是,使用 yaml,您可以使用锚点( & )和引用( * )来重用代码块,从而使复制更容易。

apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:  
  name: filter-0-mydebugger
  namespace: istio-system
spec:
  configPatches:
  - applyTo: HTTP_FILTER
    match: &mymatch # create an anchor for reuse
      context: GATEWAY 
      listener:
        filterChain:
          filter:
            name: envoy.http_connection_manager
            subFilter:
              name: envoy.router
    patch: &mypatch # create an anchor for reuse
      operation: INSERT_BEFORE
      value:
        name: envoy.lua.mydebugger
        typed_config:
          '@type': type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua
          inlineCode: |
            function envoy_on_request(request_handle)              
              request_handle:logInfo("HelloWorld")             
            end
  - applyTo: HTTP_FILTER
    match:
      <<: *mymatch # reuse the match
      context: SIDECAR_INBOUND # ... but override the context
    patch: *mypatch # reuse the patch without any overriding

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM