Skip to content

Instantly share code, notes, and snippets.

@Stono
Created October 15, 2021 15:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Stono/caa4a0c5f7207ddbd87bcd5d41ac2d4e to your computer and use it in GitHub Desktop.
Save Stono/caa4a0c5f7207ddbd87bcd5d41ac2d4e to your computer and use it in GitHub Desktop.
Adds a workload name header to outbound requests in istio
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