Created
October 15, 2021 15:15
-
-
Save Stono/caa4a0c5f7207ddbd87bcd5d41ac2d4e to your computer and use it in GitHub Desktop.
Adds a workload name header to outbound requests in istio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: networking.istio.io/v1alpha3 | |
kind: EnvoyFilter | |
metadata: | |
name: add-x-workload-header | |
namespace: istio-system | |
annotations: | |
name: Add Workload Header | |
description: Adds an x-workload-header | |
spec: | |
configPatches: | |
- applyTo: HTTP_FILTER | |
match: | |
context: SIDECAR_OUTBOUND | |
listener: | |
filterChain: | |
filter: | |
name: 'envoy.filters.network.http_connection_manager' | |
subFilter: | |
name: 'envoy.filters.http.router' | |
patch: | |
operation: INSERT_BEFORE | |
value: | |
name: envoy.lua | |
typed_config: | |
'@type': 'type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua' | |
inlineCode: | | |
function envoy_on_request(request_handle) | |
local function isempty(s) | |
return s == nil or s == '' | |
end | |
local request_headers = request_handle:headers() | |
local workload_name = os.getenv("ISTIO_META_WORKLOAD_NAME") | |
if isempty(workload_name) then | |
workload_name = os.getenv("CANONICAL_SERVICE") | |
end | |
if isempty(workload_name) then | |
workload_name = os.getenv("POD_NAMESPACE") | |
end | |
if not isempty(workload_name) then | |
request_handle:headers():replace("x-workload-name", workload_name) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment