Jerald Baker
Jerald Baker

Reputation: 1361

How to apply EnvoyFilter to Sidecar Inbound and Gateway?

I want to configure an EnvoyFilter to run only on Gateway and 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. However, I want it to apply only to Gateway and 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. How can I specify multiple matches - Gateway and Sidecar-Inbound? (Without having to repeat/duplicate the patch section)

Upvotes: 1

Views: 1748

Answers (1)

viggnah
viggnah

Reputation: 1879

The context is an enum so you can't do something like [GATEWAY, SIDECAR_INBOUND]. Therefore, unfortunately you will need to create another element inside configPatches with an applyTo, match, and patch.

However, with yaml you can use anchors(&) and references(*) to reuse blocks of code which makes the duplication easier.

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

Upvotes: 2

Related Questions