K8s Ambassador no handler for FilterPolicy

652 views Asked by At

I have configured the ambassador in my local and applied plugin filter, following is the filter config

apiVersion: getambassador.io/v1beta1
kind: Filter
metadata:
  name: "x-dc-filter"
spec:
  Plugin:
    name: "x-dc-plugin"

---
apiVersion: getambassador.io/v1beta1
kind: FilterPolicy
metadata:
  name: "x-dc-filter-policy"
spec:
  rules:
  - host: "*"
    path: "*"
    filters:               
    - name: "x-dc-filter"  

Have bundled the plugin .so file as part of ambassador docker image and verified the plugin is available in /etc/ambassador-plugins path in pod. On starting the ambassador got following logs from pod

Calling Metriton
2020-11-27 06:11:28 diagd 1.9.1 [P75TThreadPoolExecutor-0_1] INFO: B155B245-326B-4CA6-8ECF-A9034B478E5E: 127.0.0.1 "GET /ambassador/v0/diag/" 22ms 200 success
2020/11/27 06:11:35 aggregator: watch hook stderr: 2020-11-27 06:11:35 watch-hook WARNING: <Filter ambassador.default.1>: no handler for Filter, just saving
2020/11/27 06:11:35 aggregator: watch hook stderr: 2020-11-27 06:11:35 watch-hook WARNING: <FilterPolicy ambassador.default.2>: no handler for FilterPolicy, just saving
2020/11/27 06:11:35 aggregator: watch hook stderr:
2020/11/27 06:11:35 kubernetes:secret|default|*|*: signaling shutdown
2020/11/27 06:11:35 kubernetes:secret|default|*|*: exited
2020/11/27 06:11:35 kubernetes:service|default|*|*: signaling shutdown
2020/11/27 06:11:35 kubernetes:service|default|*|*: exited
2020-11-27 06:11:35 diagd 1.9.1 [P75TAEW] WARNING: <Filter ambassador.default.1>: no handler for Filter, just saving
2020-11-27 06:11:35 diagd 1.9.1 [P75TAEW] WARNING: <FilterPolicy ambassador.default.2>: no handler for FilterPolicy, just saving
2020-11-27 06:11:36 diagd 1.9.1 [P75TAEW] INFO: configuration updated (complete) from snapshot 3 (S8 L1 G8 C3)
time="2020-11-27 06:11:36" level=warning msg="license_secret_watch: empty decoded license data" func=github.com/datawire/apro/cmd/amb-sidecar/runner.runE.func4 file="github.com/datawire/apro/cmd/amb-sidecar/runner/main.go:300" MAIN=license_secret_watch
time="2020-11-27 06:11:36" level=warning msg="license_secret_watch: empty decoded license data" func=github.com/datawire/apro/cmd/amb-sidecar/runner.runE.func4 file="github.com/datawire/apro/cmd/amb-sidecar/runner/main.go:300" MAIN=license_secret_watch
2020/11/27 06:11:36 aggregator: watch hook stderr: 2020-11-27 06:11:36 watch-hook WARNING: <Filter ambassador.default.1>: no handler for Filter, just saving
2020/11/27 06:11:36 aggregator: watch hook stderr: 2020-11-27 06:11:36 watch-hook WARNING: <FilterPolicy ambassador.default.2>: no handler for FilterPolicy, just saving
2020/11/27 06:11:36 aggregator: watch hook stderr:
2020-11-27 06:11:37 diagd 1.9.1 [P75TAEW] WARNING: <Filter ambassador.default.1>: no handler for Filter, just saving
2020-11-27 06:11:37 diagd 1.9.1 [P75TAEW] WARNING: <FilterPolicy ambassador.default.2>: no handler for FilterPolicy, just saving
2020-11-27 06:11:37 diagd 1.9.1 [P75TAEW] INFO: configuration updated (complete) from snapshot 4 (S8 L1 G8 C3)
time="2020-11-27 06:11:37" level=warning msg="license_secret_watch: empty decoded license data" func=github.com/datawire/apro/cmd/amb-sidecar/runner.runE.func4 file="github.com/datawire/apro/cmd/amb-sidecar/runner/main.go:300" MAIN=license_secret_watch
time="2020-11-27 06:11:37" level=warning msg="license_secret_watch: empty decoded license data" func=github.com/datawire/apro/cmd/amb-sidecar/runner.runE.func4 file="github.com/datawire/apro/cmd/amb-sidecar/runner/main.go:300" MAIN=license_secret_watch
2020/11/27 06:11:38 aggregator: watch hook stderr: 2020-11-27 06:11:38 watch-hook WARNING: <Filter ambassador.default.1>: no handler for Filter, just saving
2020/11/27 06:11:38 aggregator: watch hook stderr: 2020-11-27 06:11:38 watch-hook WARNING: <FilterPolicy ambassador.default.2>: no handler for FilterPolicy, just saving
2020/11/27 06:11:38 aggregator: watch hook stderr:
2020-11-27 06:11:38 diagd 1.9.1 [P75TAEW] WARNING: <Filter ambassador.default.1>: no handler for Filter, just saving
2020-11-27 06:11:38 diagd 1.9.1 [P75TAEW] WARNING: <FilterPolicy ambassador.default.2>: no handler for FilterPolicy, just saving
2020-11-27 06:11:38 diagd 1.9.1 [P75TAEW] INFO: configuration updated (complete) from snapshot 5 (S8 L1 G8 C3)
time="2020-11-27 06:11:38" level=warning msg="license_secret_watch: empty decoded license data" func=github.com/datawire/apro/cmd/amb-sidecar/runner.runE.func4 file="github.com/datawire/apro/cmd/amb-sidecar/runner/main.go:300" MAIN=license_secret_watch
time="2020-11-27 06:11:38" level=warning msg="license_secret_watch: empty decoded license data" func=github.com/datawire/apro/cmd/amb-sidecar/runner.runE.func4 file="github.com/datawire/apro/cmd/amb-sidecar/runner/main.go:300" MAIN=license_secret_watch
2020-11-27 06:12:27 diagd 1.9.1 [P75TThreadPoolExecutor-0_0] INFO: 44A5439F-C2E4-46C8-9D57-F5F4B6654E72: 127.0.0.1 "GET /ambassador/v0/diag/" 22ms 200 success
2020-11-27 06:13:27 diagd 1.9.1 [P75TThreadPoolExecutor-0_0] INFO: 15FD78F9-B331-4D57-B838-FEB5CB066C82: 127.0.0.1 "GET /ambassador/v0/diag/" 16ms 200 success
2020-11-27 06:13:38 diagd 1.9.1 [P75TAEW] INFO: TIMER reconfiguration: 5, 0.121/0.260/0.406
1

There are 1 answers

0
sreekesh.s On BEST ANSWER

Abassador request mapping is working in following way

  1. Any request to ambassador gateway will first check for any matches available for request in mapping,
  2. If any mapping matches and then it invokes the filter if filter policy rule matches with the request.
  3. The filter plugin applies the logic and update the request
  4. After filter logic the request get mapped with any of the mapping and route to the actual service

So In order to avoid the above problem added following mapping

annotations:
    getambassador.io/config: |
      ---
      apiVersion: ambassador/v1
      kind:  Mapping
      name:  dc_1_mapping
      prefix: "/getHostName"
      rewrite: ""
      headers:
        X-Dc: odd
      service: testservice1:8081
      ---
        apiVersion: ambassador/v1
        kind:  Mapping
        name:  dc_2_mapping
        prefix: "/getHostName"
        headers:
          X-Dc: even
        service: testservice2:8082
        rewrite: ""
      ---
      apiVersion: ambassador/v1
      kind:  Mapping
      name:  dc_3_mapping
      prefix: "/getHostName"
      service: testservice3:8083
      rewrite: ""

Note: The X-dc-plugin filter mentioned in question just updates the request header X-Dc wit odd or even based on the id in query param.

Example flow:

Here if I send a request http://localhost/getHostName?id=2 this will be matching the last mapping and then route request to filter. The filter updates the header with even as id in query param is 2. Then ambassador again tries to match the request with the mapping above with header even and route the request to testService2:8082