From c2d4d5be7c88251bbfeb69464848d1b9274be68d Mon Sep 17 00:00:00 2001 From: Megrez Lu Date: Tue, 14 May 2024 15:36:14 +0800 Subject: [PATCH] update istio lua script Signed-off-by: Megrez Lu --- .../VirtualService/trafficRouting.lua | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/lua_configuration/networking.istio.io/VirtualService/trafficRouting.lua b/lua_configuration/networking.istio.io/VirtualService/trafficRouting.lua index 1581c794..956d67f8 100644 --- a/lua_configuration/networking.istio.io/VirtualService/trafficRouting.lua +++ b/lua_configuration/networking.istio.io/VirtualService/trafficRouting.lua @@ -47,26 +47,40 @@ function GenerateRoutesWithMatches(spec, matches, stableService, canaryService) for _, match in ipairs(matches) do local route = {} route["match"] = {} + + local vsMatch = {} for key, value in pairs(match) do - local vsMatch = {} - vsMatch[key] = {} - for _, rule in ipairs(value) do + if key == "path" then + vsMatch["uri"] = {} + local rule = value if rule["type"] == "RegularExpression" then matchType = "regex" elseif rule["type"] == "Exact" then matchType = "exact" - elseif rule["type"] == "Prefix" then + elseif rule["type"] == "PathPrefix" then matchType = "prefix" end - if key == "headers" then - vsMatch[key][rule["name"]] = {} - vsMatch[key][rule["name"]][matchType] = rule.value - else - vsMatch[key][matchType] = rule.value + vsMatch["uri"][matchType] = rule.value + else + vsMatch[key] = {} + for _, rule in ipairs(value) do + if rule["type"] == "RegularExpression" then + matchType = "regex" + elseif rule["type"] == "Exact" then + matchType = "exact" + elseif rule["type"] == "Prefix" then + matchType = "prefix" + end + if key == "headers" or key == "queryParams" then + vsMatch[key][rule["name"]] = {} + vsMatch[key][rule["name"]][matchType] = rule.value + else + vsMatch[key][matchType] = rule.value + end end end - table.insert(route["match"], vsMatch) end + table.insert(route["match"], vsMatch) route.route = { { destination = {}