-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: optimize the modification of rollout to httproute header
Signed-off-by: zhangsetsail <[email protected]>
- Loading branch information
1 parent
5807b5b
commit 7b4d1a0
Showing
5 changed files
with
146 additions
and
4 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
36 changes: 36 additions & 0 deletions
36
pkg/trafficrouting/network/gateway/lua_configuration/trafficrouting_ingress/aliyun-alb.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,36 @@ | ||
annotations = {} | ||
if ( obj.annotations ) | ||
then | ||
annotations = obj.annotations | ||
end | ||
annotations["alb.ingress.kubernetes.io/canary"] = "true" | ||
annotations["alb.ingress.kubernetes.io/canary-by-cookie"] = nil | ||
annotations["alb.ingress.kubernetes.io/canary-by-header"] = nil | ||
annotations["alb.ingress.kubernetes.io/canary-by-header-pattern"] = nil | ||
annotations["alb.ingress.kubernetes.io/canary-by-header-value"] = nil | ||
annotations["alb.ingress.kubernetes.io/canary-weight"] = nil | ||
annotations["alb.ingress.kubernetes.io/order"] = "1" | ||
if ( obj.weight ~= "-1" ) | ||
then | ||
annotations["alb.ingress.kubernetes.io/canary-weight"] = obj.weight | ||
end | ||
if ( not obj.matches ) | ||
then | ||
return annotations | ||
end | ||
for _,match in ipairs(obj.matches) do | ||
local header = match.headers[1] | ||
if ( header.name == "canary-by-cookie" ) | ||
then | ||
annotations["alb.ingress.kubernetes.io/canary-by-cookie"] = header.value | ||
else | ||
annotations["alb.ingress.kubernetes.io/canary-by-header"] = header.name | ||
if ( header.type == "RegularExpression" ) | ||
then | ||
annotations["alb.ingress.kubernetes.io/canary-by-header-pattern"] = header.value | ||
else | ||
annotations["alb.ingress.kubernetes.io/canary-by-header-value"] = header.value | ||
end | ||
end | ||
end | ||
return annotations |
46 changes: 46 additions & 0 deletions
46
pkg/trafficrouting/network/gateway/lua_configuration/trafficrouting_ingress/higress.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,46 @@ | ||
annotations = {} | ||
-- obj.annotations is ingress annotations, it is recommended not to remove the part of the lua script, it must be kept | ||
if ( obj.annotations ) | ||
then | ||
annotations = obj.annotations | ||
end | ||
-- indicates the ingress is nginx canary api | ||
annotations["nginx.ingress.kubernetes.io/canary"] = "true" | ||
-- First, set all canary api to nil | ||
annotations["nginx.ingress.kubernetes.io/canary-by-cookie"] = nil | ||
annotations["nginx.ingress.kubernetes.io/canary-by-header"] = nil | ||
annotations["nginx.ingress.kubernetes.io/canary-by-header-pattern"] = nil | ||
annotations["nginx.ingress.kubernetes.io/canary-by-header-value"] = nil | ||
annotations["nginx.ingress.kubernetes.io/canary-weight"] = nil | ||
-- if rollout.spec.strategy.canary.steps.weight is nil, obj.weight will be -1, | ||
-- then we need remove the canary-weight annotation | ||
if ( obj.weight ~= "-1" ) | ||
then | ||
annotations["nginx.ingress.kubernetes.io/canary-weight"] = obj.weight | ||
end | ||
-- if don't contains headers, immediate return annotations | ||
if ( not obj.matches ) | ||
then | ||
return annotations | ||
end | ||
-- headers & cookie apis | ||
-- traverse matches | ||
for _,match in ipairs(obj.matches) do | ||
local header = match.headers[1] | ||
-- cookie | ||
if ( header.name == "canary-by-cookie" ) | ||
then | ||
annotations["nginx.ingress.kubernetes.io/canary-by-cookie"] = header.value | ||
else | ||
annotations["nginx.ingress.kubernetes.io/canary-by-header"] = header.name | ||
-- if regular expression | ||
if ( header.type == "RegularExpression" ) | ||
then | ||
annotations["nginx.ingress.kubernetes.io/canary-by-header-pattern"] = header.value | ||
else | ||
annotations["nginx.ingress.kubernetes.io/canary-by-header-value"] = header.value | ||
end | ||
end | ||
end | ||
-- must be return annotations | ||
return annotations |
46 changes: 46 additions & 0 deletions
46
pkg/trafficrouting/network/gateway/lua_configuration/trafficrouting_ingress/nginx.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,46 @@ | ||
annotations = {} | ||
-- obj.annotations is ingress annotations, it is recommended not to remove the part of the lua script, it must be kept | ||
if ( obj.annotations ) | ||
then | ||
annotations = obj.annotations | ||
end | ||
-- indicates the ingress is nginx canary api | ||
annotations["nginx.ingress.kubernetes.io/canary"] = "true" | ||
-- First, set all canary api to nil | ||
annotations["nginx.ingress.kubernetes.io/canary-by-cookie"] = nil | ||
annotations["nginx.ingress.kubernetes.io/canary-by-header"] = nil | ||
annotations["nginx.ingress.kubernetes.io/canary-by-header-pattern"] = nil | ||
annotations["nginx.ingress.kubernetes.io/canary-by-header-value"] = nil | ||
annotations["nginx.ingress.kubernetes.io/canary-weight"] = nil | ||
-- if rollout.spec.strategy.canary.steps.weight is nil, obj.weight will be -1, | ||
-- then we need remove the canary-weight annotation | ||
if ( obj.weight ~= "-1" ) | ||
then | ||
annotations["nginx.ingress.kubernetes.io/canary-weight"] = obj.weight | ||
end | ||
-- if don't contains headers, immediate return annotations | ||
if ( not obj.matches ) | ||
then | ||
return annotations | ||
end | ||
-- headers & cookie apis | ||
-- traverse matches | ||
for _,match in ipairs(obj.matches) do | ||
local header = match.headers[1] | ||
-- cookie | ||
if ( header.name == "canary-by-cookie" ) | ||
then | ||
annotations["nginx.ingress.kubernetes.io/canary-by-cookie"] = header.value | ||
else | ||
annotations["nginx.ingress.kubernetes.io/canary-by-header"] = header.name | ||
-- if regular expression | ||
if ( header.type == "RegularExpression" ) | ||
then | ||
annotations["nginx.ingress.kubernetes.io/canary-by-header-pattern"] = header.value | ||
else | ||
annotations["nginx.ingress.kubernetes.io/canary-by-header-value"] = header.value | ||
end | ||
end | ||
end | ||
-- must be return annotations | ||
return annotations |