EnvoyFilterUsesRelativeOperation
当EnvoyFilter
没有优先级并且使用相对补丁操作(INVALID
、MERGE
、REMOVE
、INSERT_BEFORE
、INSERT_AFTER
、REPLACE
)时,会出现此消息。使用相对补丁操作意味着该操作依赖于在评估当前EnvoyFilter
过滤器时另一个过滤器是否存在。为了确保EnvoyFilters
按用户期望的顺序应用,应指定优先级或使用非相对操作(ADD
或INSERT_FIRST
)。
一个例子
考虑一个补丁操作为INSERT_BEFORE
的EnvoyFilter
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: test-relative
namespace: bookinfo
spec:
workloadSelector:
labels:
app: reviews2
configPatches:
# The first patch adds the Lua filter to the listener/http connection manager
- applyTo: HTTP_FILTER
match:
context: SIDECAR_INBOUND
listener:
portNumber: 8080
filterChain:
filter:
name: "envoy.filters.network.http_connection_manager"
subFilter:
name: "envoy.filters.http.router"
patch:
operation: INSERT_BEFORE
value: # Lua filter specification
name: envoy.lua
typed_config:
"@type": "type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua"
inlineCode: |
function envoy_on_request(request_handle)
-- Make an HTTP call to an upstream host with the following headers, body, and timeout.
local headers, body = request_handle:httpCall(
"lua_cluster",
{
[":method"] = "POST",
[":path"] = "/acl",
[":authority"] = "internal.org.net"
},
"authorize call",
5000)
end
如何解决
由于使用了INSERT_BEFORE
的相对操作,将其更改为INSERT_FIRST
的绝对操作可以解决此问题。
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: test-relative
namespace: bookinfo
spec:
workloadSelector:
labels:
app: reviews2
configPatches:
# The first patch adds the Lua filter to the listener/http connection manager
- applyTo: HTTP_FILTER
match:
context: SIDECAR_INBOUND
listener:
portNumber: 8080
filterChain:
filter:
name: "envoy.filters.network.http_connection_manager"
subFilter:
name: "envoy.filters.http.router"
patch:
operation: INSERT_FIRST
value: # Lua filter specification
name: envoy.lua
typed_config:
"@type": "type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua"
inlineCode: |
function envoy_on_request(request_handle)
-- Make an HTTP call to an upstream host with the following headers, body, and timeout.
local headers, body = request_handle:httpCall(
"lua_cluster",
{
[":method"] = "POST",
[":path"] = "/acl",
[":authority"] = "internal.org.net"
},
"authorize call",
5000)
end