custom trafficRouting
Signed-off-by: Kuromesi <blackfacepan@163.com>
This commit is contained in:
parent
e9d3196e32
commit
3c1c6ee6f8
|
|
@ -25,7 +25,6 @@ import (
|
|||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"github.com/openkruise/rollouts/api/v1alpha1"
|
||||
rolloutv1alpha1 "github.com/openkruise/rollouts/api/v1alpha1"
|
||||
"github.com/openkruise/rollouts/pkg/trafficrouting/network"
|
||||
"github.com/openkruise/rollouts/pkg/util"
|
||||
|
|
@ -59,7 +58,7 @@ type Config struct {
|
|||
CanaryService string
|
||||
StableService string
|
||||
// network providers need to be created
|
||||
TrafficConf []v1alpha1.NetworkRef
|
||||
TrafficConf []rolloutv1alpha1.NetworkRef
|
||||
OwnerRef metav1.OwnerReference
|
||||
}
|
||||
|
||||
|
|
@ -238,7 +237,7 @@ func (r *customController) executeLuaForCanary(spec interface{}, strategy *rollo
|
|||
return nil, fmt.Errorf("expect table output from Lua script, not %s", returnValue.Type().String())
|
||||
}
|
||||
|
||||
func (r *customController) getLuascript(ctx context.Context, ref v1alpha1.NetworkRef) string {
|
||||
func (r *customController) getLuascript(ctx context.Context, ref rolloutv1alpha1.NetworkRef) string {
|
||||
// get local lua script
|
||||
// luaScript.Provider: CRDGroupt/Kind
|
||||
group := strings.Split(ref.APIVersion, "/")[0]
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/openkruise/rollouts/api/v1alpha1"
|
||||
rolloutsv1alpha1 "github.com/openkruise/rollouts/api/v1alpha1"
|
||||
"github.com/openkruise/rollouts/pkg/util"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
|
|
@ -155,7 +154,7 @@ func TestInitialize(t *testing.T) {
|
|||
return Config{
|
||||
StableService: "echoserver",
|
||||
CanaryService: "echoserver-canary",
|
||||
TrafficConf: []v1alpha1.NetworkRef{
|
||||
TrafficConf: []rolloutsv1alpha1.NetworkRef{
|
||||
{
|
||||
APIVersion: "networking.istio.io/v1alpha3",
|
||||
Kind: "VirtualService",
|
||||
|
|
@ -346,7 +345,7 @@ func TestEnsureRoutes(t *testing.T) {
|
|||
RolloutName: "rollout-demo",
|
||||
StableService: "echoserver",
|
||||
CanaryService: "echoserver-canary",
|
||||
TrafficConf: []v1alpha1.NetworkRef{
|
||||
TrafficConf: []rolloutsv1alpha1.NetworkRef{
|
||||
{
|
||||
APIVersion: "networking.istio.io/v1alpha3",
|
||||
Kind: "VirtualService",
|
||||
|
|
@ -404,7 +403,7 @@ func TestFinalise(t *testing.T) {
|
|||
return Config{
|
||||
StableService: "echoserver",
|
||||
CanaryService: "echoserver-canary",
|
||||
TrafficConf: []v1alpha1.NetworkRef{
|
||||
TrafficConf: []rolloutsv1alpha1.NetworkRef{
|
||||
{
|
||||
APIVersion: "networking.istio.io/v1alpha3",
|
||||
Kind: "VirtualService",
|
||||
|
|
|
|||
|
|
@ -1,36 +0,0 @@
|
|||
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
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
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
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
function split(input, delimiter)
|
||||
local arr = {}
|
||||
string.gsub(input, '[^' .. delimiter ..']+', function(w) table.insert(arr, w) end)
|
||||
return arr
|
||||
end
|
||||
|
||||
annotations = obj.annotations
|
||||
annotations["nginx.ingress.kubernetes.io/canary"] = "true"
|
||||
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 ( obj.weight ~= "-1" )
|
||||
then
|
||||
annotations["nginx.ingress.kubernetes.io/canary-weight"] = obj.weight
|
||||
end
|
||||
if ( obj.requestHeaderModifier )
|
||||
then
|
||||
local str = ''
|
||||
for _,header in ipairs(obj.requestHeaderModifier.set) do
|
||||
str = str..string.format("%s %s", header.name, header.value)
|
||||
end
|
||||
annotations["mse.ingress.kubernetes.io/request-header-control-update"] = str
|
||||
end
|
||||
if ( not obj.matches )
|
||||
then
|
||||
return annotations
|
||||
end
|
||||
for _,match in ipairs(obj.matches) do
|
||||
header = match.headers[1]
|
||||
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 ( 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
|
||||
return annotations
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
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
|
||||
|
|
@ -5551,6 +5551,10 @@ var _ = SIGDescribe("Rollout", func() {
|
|||
})
|
||||
|
||||
})
|
||||
|
||||
KruiseDescribe("Custom network provider tests", func() {
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
func mergeEnvVar(original []v1.EnvVar, add v1.EnvVar) []v1.EnvVar {
|
||||
|
|
|
|||
Loading…
Reference in New Issue