forked from openkruise/rollouts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,652 additions
and
18 deletions.
There are no files selected for viewing
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
95 changes: 95 additions & 0 deletions
95
lua_configuration/networking.istio.io/VirtualService/testdata/test_case.yaml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
rollout: | ||
apiVersion: rollouts.kruise.io/v1alpha1 | ||
kind: Rollout | ||
metadata: | ||
name: rollouts-demo | ||
namespace: demo | ||
annotations: | ||
rollouts.kruise.io/rolling-style: canary | ||
spec: | ||
disabled: false | ||
objectRef: | ||
workloadRef: | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
name: nginx-deployment | ||
strategy: | ||
canary: | ||
steps: | ||
- weight: 20 | ||
matches: | ||
- headers: | ||
- type: Exact | ||
name: user-agent | ||
value: pc | ||
- type: RegularExpression | ||
name: name | ||
value: ".*demo" | ||
- weight: 50 | ||
trafficRoutings: | ||
- service: nginx-service | ||
networkRefs: | ||
- apiVersion: networking.istio.io/v1alpha3 | ||
kind: VirtualService | ||
name: nginx-vs | ||
original: | ||
apiVersion: networking.istio.io/v1alpha3 | ||
kind: VirtualService | ||
metadata: | ||
name: nginx-vs | ||
namespace: demo | ||
spec: | ||
hosts: | ||
- "*" | ||
gateways: | ||
- nginx-gateway | ||
http: | ||
- route: | ||
- destination: | ||
host: nginx-service | ||
expected: | ||
- apiVersion: networking.istio.io/v1alpha3 | ||
kind: VirtualService | ||
metadata: | ||
name: nginx-vs | ||
namespace: demo | ||
spec: | ||
hosts: | ||
- "*" | ||
gateways: | ||
- nginx-gateway | ||
http: | ||
- match: | ||
- headers: | ||
user-agent: | ||
exact: pc | ||
name: | ||
regex: .*demo | ||
route: | ||
- destination: | ||
host: nginx-service | ||
weight: 80 | ||
- destination: | ||
host: nginx-service-canary | ||
weight: 20 | ||
- route: | ||
- destination: | ||
host: nginx-service | ||
- apiVersion: networking.istio.io/v1alpha3 | ||
kind: VirtualService | ||
metadata: | ||
name: nginx-vs | ||
namespace: demo | ||
spec: | ||
hosts: | ||
- "*" | ||
gateways: | ||
- nginx-gateway | ||
http: | ||
- route: | ||
- destination: | ||
host: nginx-service | ||
weight: 50 | ||
- destination: | ||
host: nginx-service-canary | ||
weight: 50 |
145 changes: 145 additions & 0 deletions
145
lua_configuration/networking.istio.io/VirtualService/trafficRouting.lua
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
-- obj = { | ||
-- matches = { | ||
-- { | ||
-- uri = { | ||
-- { | ||
-- name = "xxx", | ||
-- value = "xxx", | ||
-- type = "Prefix" | ||
-- } | ||
-- } | ||
-- } | ||
-- }, | ||
-- data = { | ||
-- spec = { | ||
-- hosts = { | ||
-- "reviews", | ||
-- }, | ||
-- http = { | ||
-- { | ||
-- route = { | ||
-- { | ||
-- destination = { | ||
-- host = "reviews", | ||
-- subset = "c1", | ||
-- port = { | ||
-- number = 80 | ||
-- } | ||
-- } | ||
-- } | ||
-- } | ||
-- } | ||
-- } | ||
-- }, | ||
-- }, | ||
|
||
-- stableService = "reviews", | ||
-- canaryService = "canary", | ||
-- stableWeight = 90, | ||
-- canaryWeight = 10 | ||
-- } | ||
|
||
spec = obj.data.spec | ||
|
||
-- find matched route of VirtualService spec with stable svc | ||
function FindMatchedRules(spec, stableService) | ||
local matchedRoutes = {} | ||
local rules = {} | ||
if (spec.http) then | ||
for _, http in ipairs(spec.http) do | ||
table.insert(rules, http) | ||
end | ||
end | ||
if (spec.tls) then | ||
for _, tls in ipairs(spec.tls) do | ||
table.insert(rules, tls) | ||
end | ||
end | ||
if (spec.tcp) then | ||
for _, tcp in ipairs(spec.tcp) do | ||
table.insert(rules, tcp) | ||
end | ||
end | ||
for _, rule in ipairs(rules) do | ||
for _, route in ipairs(rule.route) do | ||
if route.destination.host == stableService then | ||
table.insert(matchedRoutes, rule) | ||
end | ||
end | ||
end | ||
return matchedRoutes | ||
end | ||
|
||
-- generate routes with matches | ||
function GenerateMatchedRoutes(spec, matches, stableService, canaryService, stableWeight, canaryWeight) | ||
local route = {} | ||
route["match"] = {} | ||
for _, match in ipairs(matches) do | ||
for key, value in pairs(match) do | ||
local vsMatch = {} | ||
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" then | ||
vsMatch[key][rule["name"]] = {} | ||
vsMatch[key][rule["name"]][matchType] = rule.value | ||
else | ||
vsMatch[key][matchType] = rule.value | ||
end | ||
end | ||
table.insert(route["match"], vsMatch) | ||
end | ||
end | ||
route["route"] = { | ||
{ | ||
destination = { | ||
host = stableService, | ||
}, | ||
weight = stableWeight, | ||
}, | ||
{ | ||
destination = { | ||
host = canaryService, | ||
}, | ||
weight = canaryWeight, | ||
} | ||
} | ||
table.insert(spec.http, 1, route) | ||
end | ||
|
||
-- generate routes without matches | ||
function GenerateRoutes(spec, stableService, canaryService, stableWeight, canaryWeight) | ||
local matchedRules = FindMatchedRules(spec, stableService) | ||
for _, rule in ipairs(matchedRules) do | ||
local canary = { | ||
destination = { | ||
host = canaryService, | ||
}, | ||
weight = canaryWeight, | ||
} | ||
for _, route in ipairs(rule.route) do | ||
-- incase there are multiple versions traffic already | ||
if (route.weight) then | ||
route.weight = math.floor(route.weight * stableWeight / 100) | ||
else | ||
route.weight = math.floor(stableWeight / #rule.route) | ||
end | ||
end | ||
table.insert(rule.route, canary) | ||
end | ||
end | ||
|
||
if (obj.matches) then | ||
GenerateMatchedRoutes(spec, obj.matches, obj.stableService, obj.canaryService, obj.stableWeight, obj.canaryWeight) | ||
return obj.data | ||
end | ||
|
||
GenerateRoutes(spec, obj.stableService, obj.canaryService, obj.stableWeight, obj.canaryWeight) | ||
return obj.data | ||
|
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
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
Oops, something went wrong.