K8s Ambassador 没有 FilterPolicy 的处理程序
K8s Ambassador no handler for FilterPolicy
我已经在本地配置了大使并应用了插件过滤器,以下是过滤器配置
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"
已将插件 .so 文件捆绑为大使 docker 图像的一部分,并验证插件在 pod 的 /etc/ambassador-plugins 路径中可用。在开始时,大使从 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
Abassador 请求映射按以下方式工作
- 对大使网关的任何请求都将首先检查映射中可用于请求的任何匹配项,
- 如果任何映射匹配,然后如果过滤器策略规则与请求匹配,它会调用过滤器。
- 过滤器插件应用逻辑并更新请求
- 在过滤逻辑之后,请求被映射到任何映射并路由到实际服务
所以为了避免上面的问题添加如下映射
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: ""
注意:问题中提到的 X-dc-plugin 过滤器只是根据查询参数中的 id 更新请求 header X-Dc 奇数或偶数。
示例流程:
在这里,如果我发送请求 http:///localhost/getHostName?id=2 这将匹配最后一个映射,然后将请求路由到过滤器。过滤器使用 even 更新 header,因为查询参数中的 id 为 2。然后大使再次尝试将请求与上面的映射匹配 header even 并将请求路由到 testService2:8082
我已经在本地配置了大使并应用了插件过滤器,以下是过滤器配置
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"
已将插件 .so 文件捆绑为大使 docker 图像的一部分,并验证插件在 pod 的 /etc/ambassador-plugins 路径中可用。在开始时,大使从 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
Abassador 请求映射按以下方式工作
- 对大使网关的任何请求都将首先检查映射中可用于请求的任何匹配项,
- 如果任何映射匹配,然后如果过滤器策略规则与请求匹配,它会调用过滤器。
- 过滤器插件应用逻辑并更新请求
- 在过滤逻辑之后,请求被映射到任何映射并路由到实际服务
所以为了避免上面的问题添加如下映射
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: ""
注意:问题中提到的 X-dc-plugin 过滤器只是根据查询参数中的 id 更新请求 header X-Dc 奇数或偶数。
示例流程:
在这里,如果我发送请求 http:///localhost/getHostName?id=2 这将匹配最后一个映射,然后将请求路由到过滤器。过滤器使用 even 更新 header,因为查询参数中的 id 为 2。然后大使再次尝试将请求与上面的映射匹配 header even 并将请求路由到 testService2:8082