diff --git a/.gitignore b/.gitignore index e305aaa3..e06ff1df 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,5 @@ test/e2e/generated/bindata.go .vscode .DS_Store + +lua_configuration/networking.istio.io/**/testdata/*.lua diff --git a/lua_configuration/convert_test_case_to_lua_object.go b/lua_configuration/convert_test_case_to_lua_object.go index d97e959a..325fc687 100644 --- a/lua_configuration/convert_test_case_to_lua_object.go +++ b/lua_configuration/convert_test_case_to_lua_object.go @@ -100,11 +100,12 @@ func objectToTable(path string) error { Annotations: testCase.Original.GetAnnotations(), Spec: testCase.Original.Object["spec"], }, - Matches: step.TrafficRoutingStrategy.Matches, - CanaryWeight: *weight, - StableWeight: 100 - *weight, - CanaryService: canaryService, - StableService: stableService, + Matches: step.TrafficRoutingStrategy.Matches, + CanaryWeight: *weight, + StableWeight: 100 - *weight, + CanaryService: canaryService, + StableService: stableService, + RequestHeaderModifier: step.TrafficRoutingStrategy.RequestHeaderModifier, } uList[fmt.Sprintf("step_%d", i)] = data } @@ -128,11 +129,12 @@ func objectToTable(path string) error { Annotations: testCase.Original.GetAnnotations(), Spec: testCase.Original.Object["spec"], }, - Matches: matches, - CanaryWeight: *weight, - StableWeight: 100 - *weight, - CanaryService: canaryService, - StableService: stableService, + Matches: matches, + CanaryWeight: *weight, + StableWeight: 100 - *weight, + CanaryService: canaryService, + StableService: stableService, + RequestHeaderModifier: trafficRouting.Spec.Strategy.RequestHeaderModifier, } uList["steps_0"] = data } else { diff --git a/lua_configuration/networking.istio.io/VirtualService/testdata/rollout_with_three_steps.yaml b/lua_configuration/networking.istio.io/VirtualService/testdata/rollout_with_three_steps.yaml index 7550ebc1..e2e213b9 100644 --- a/lua_configuration/networking.istio.io/VirtualService/testdata/rollout_with_three_steps.yaml +++ b/lua_configuration/networking.istio.io/VirtualService/testdata/rollout_with_three_steps.yaml @@ -19,6 +19,10 @@ rollout: - type: RegularExpression name: name value: ".*demo" + requestHeaderModifier: + set: + - name: "header-foo" + value: "bar" - matches: - headers: - type: Exact @@ -66,6 +70,10 @@ expected: exact: pc name: regex: .*demo + headers: + request: + set: + header-foo: bar route: - destination: host: svc-demo-canary diff --git a/lua_configuration/networking.istio.io/VirtualService/testdata/traffic_routing_with_a_match.yaml b/lua_configuration/networking.istio.io/VirtualService/testdata/traffic_routing_with_a_match.yaml index cd5b99cd..514494d7 100644 --- a/lua_configuration/networking.istio.io/VirtualService/testdata/traffic_routing_with_a_match.yaml +++ b/lua_configuration/networking.istio.io/VirtualService/testdata/traffic_routing_with_a_match.yaml @@ -13,6 +13,10 @@ trafficRouting: - type: RegularExpression name: name value: ".*demo" + requestHeaderModifier: + set: + - name: "header-foo" + value: "bar" objectRef: - service: svc-demo customNetworkRefs: @@ -51,6 +55,10 @@ expected: exact: pc name: regex: .*demo + headers: + request: + set: + header-foo: bar route: - destination: host: svc-demo diff --git a/lua_configuration/networking.istio.io/VirtualService/testdata/traffic_routing_with_matches.yaml b/lua_configuration/networking.istio.io/VirtualService/testdata/traffic_routing_with_matches.yaml index 26c7d7db..eb5c4ed7 100644 --- a/lua_configuration/networking.istio.io/VirtualService/testdata/traffic_routing_with_matches.yaml +++ b/lua_configuration/networking.istio.io/VirtualService/testdata/traffic_routing_with_matches.yaml @@ -14,6 +14,10 @@ trafficRouting: - type: RegularExpression name: name value: ".*demo" + requestHeaderModifier: + set: + - name: "header-foo" + value: "bar" objectRef: - service: svc-demo customNetworkRefs: @@ -50,6 +54,10 @@ expected: - headers: name: regex: .*demo + headers: + request: + set: + header-foo: bar route: - destination: host: svc-demo diff --git a/lua_configuration/networking.istio.io/VirtualService/trafficRouting.lua b/lua_configuration/networking.istio.io/VirtualService/trafficRouting.lua index 956d67f8..57fed53e 100644 --- a/lua_configuration/networking.istio.io/VirtualService/trafficRouting.lua +++ b/lua_configuration/networking.istio.io/VirtualService/trafficRouting.lua @@ -43,7 +43,7 @@ function CalculateWeight(route, stableWeight, n) end -- generate routes with matches, insert a rule before other rules, only support http headers, cookies etc. -function GenerateRoutesWithMatches(spec, matches, stableService, canaryService) +function GenerateRoutesWithMatches(spec, matches, stableService, canaryService, requestHeaderModifier) for _, match in ipairs(matches) do local route = {} route["match"] = {} @@ -81,6 +81,23 @@ function GenerateRoutesWithMatches(spec, matches, stableService, canaryService) end end table.insert(route["match"], vsMatch) + if requestHeaderModifier then + route["headers"] = {} + route["headers"]["request"] = {} + for action, headers in pairs(requestHeaderModifier) do + if action == "set" or action == "add" then + route["headers"]["request"][action] = {} + for _, header in ipairs(headers) do + route["headers"]["request"][action][header["name"]] = header["value"] + end + elseif action == "remove" then + route["headers"]["request"]["remove"] = {} + for _, rHeader in ipairs(headers) do + table.insert(route["headers"]["request"]["remove"], rHeader) + end + end + end + end route.route = { { destination = {} @@ -130,7 +147,7 @@ end if (obj.matches and next(obj.matches) ~= nil) then - GenerateRoutesWithMatches(spec, obj.matches, obj.stableService, obj.canaryService) + GenerateRoutesWithMatches(spec, obj.matches, obj.stableService, obj.canaryService, obj.requestHeaderModifier) else GenerateRoutes(spec, obj.stableService, obj.canaryService, obj.stableWeight, obj.canaryWeight, "http") GenerateRoutes(spec, obj.stableService, obj.canaryService, obj.stableWeight, obj.canaryWeight, "tcp")