Merge branch 'openkruise:master' into dev
This commit is contained in:
commit
8d76e22358
|
|
@ -140,13 +140,13 @@ func (r *gatewayController) buildDesiredHTTPRoute(rules []gatewayv1alpha2.HTTPRo
|
|||
// according to the Gateway API definition, weight and headers cannot be supported at the same time.
|
||||
// A/B Testing, according to headers. current only support one match
|
||||
} else if len(matches) > 0 {
|
||||
return r.buildCanaryHeaderHttpRoutes(rules, matches[0].Headers)
|
||||
return r.buildCanaryHeaderHttpRoutes(rules, matches)
|
||||
}
|
||||
// canary release, according to percentage of traffic routing
|
||||
return r.buildCanaryWeightHttpRoutes(rules, weight)
|
||||
}
|
||||
|
||||
func (r *gatewayController) buildCanaryHeaderHttpRoutes(rules []gatewayv1alpha2.HTTPRouteRule, headers []gatewayv1alpha2.HTTPHeaderMatch) []gatewayv1alpha2.HTTPRouteRule {
|
||||
func (r *gatewayController) buildCanaryHeaderHttpRoutes(rules []gatewayv1alpha2.HTTPRouteRule, matchs []rolloutv1alpha1.HttpRouteMatch) []gatewayv1alpha2.HTTPRouteRule {
|
||||
var desired []gatewayv1alpha2.HTTPRouteRule
|
||||
var canarys []gatewayv1alpha2.HTTPRouteRule
|
||||
for i := range rules {
|
||||
|
|
@ -164,10 +164,16 @@ func (r *gatewayController) buildCanaryHeaderHttpRoutes(rules []gatewayv1alpha2.
|
|||
canaryRef.Name = gatewayv1alpha2.ObjectName(r.conf.CanaryService)
|
||||
canaryRule.BackendRefs = []gatewayv1alpha2.HTTPBackendRef{*canaryRef}
|
||||
// set canary headers in httpRoute
|
||||
var newMatches []gatewayv1alpha2.HTTPRouteMatch
|
||||
for j := range canaryRule.Matches {
|
||||
match := &canaryRule.Matches[j]
|
||||
match.Headers = append(match.Headers, headers...)
|
||||
canaryRuleMatch := &canaryRule.Matches[j]
|
||||
for k := range matchs {
|
||||
canaryRuleMatchBase := *canaryRuleMatch
|
||||
canaryRuleMatchBase.Headers = append(canaryRuleMatchBase.Headers, matchs[k].Headers...)
|
||||
newMatches = append(newMatches, canaryRuleMatchBase)
|
||||
}
|
||||
}
|
||||
canaryRule.Matches = newMatches
|
||||
canarys = append(canarys, *canaryRule)
|
||||
}
|
||||
desired = append(desired, canarys...)
|
||||
|
|
|
|||
|
|
@ -155,6 +155,18 @@ func TestBuildDesiredHTTPRoute(t *testing.T) {
|
|||
Value: "true",
|
||||
},
|
||||
},
|
||||
}, {
|
||||
Headers: []gatewayv1alpha2.HTTPHeaderMatch{
|
||||
{
|
||||
Name: "user_id",
|
||||
Value: "234*",
|
||||
Type: &iType,
|
||||
},
|
||||
{
|
||||
Name: "canary",
|
||||
Value: "true",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
|
|
@ -183,6 +195,26 @@ func TestBuildDesiredHTTPRoute(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Path: &gatewayv1alpha2.HTTPPathMatch{
|
||||
Value: utilpointer.String("/store"),
|
||||
},
|
||||
Headers: []gatewayv1alpha2.HTTPHeaderMatch{
|
||||
{
|
||||
Name: "version",
|
||||
Value: "v2",
|
||||
},
|
||||
{
|
||||
Name: "user_id",
|
||||
Value: "234*",
|
||||
Type: &iType,
|
||||
},
|
||||
{
|
||||
Name: "canary",
|
||||
Value: "true",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Path: &gatewayv1alpha2.HTTPPathMatch{
|
||||
Value: utilpointer.String("/v2/store"),
|
||||
|
|
@ -199,6 +231,22 @@ func TestBuildDesiredHTTPRoute(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Path: &gatewayv1alpha2.HTTPPathMatch{
|
||||
Value: utilpointer.String("/v2/store"),
|
||||
},
|
||||
Headers: []gatewayv1alpha2.HTTPHeaderMatch{
|
||||
{
|
||||
Name: "user_id",
|
||||
Value: "234*",
|
||||
Type: &iType,
|
||||
},
|
||||
{
|
||||
Name: "canary",
|
||||
Value: "true",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
BackendRefs: []gatewayv1alpha2.HTTPBackendRef{
|
||||
{
|
||||
|
|
@ -230,6 +278,22 @@ func TestBuildDesiredHTTPRoute(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Path: &gatewayv1alpha2.HTTPPathMatch{
|
||||
Value: utilpointer.String("/storage"),
|
||||
},
|
||||
Headers: []gatewayv1alpha2.HTTPHeaderMatch{
|
||||
{
|
||||
Name: "user_id",
|
||||
Value: "234*",
|
||||
Type: &iType,
|
||||
},
|
||||
{
|
||||
Name: "canary",
|
||||
Value: "true",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
BackendRefs: []gatewayv1alpha2.HTTPBackendRef{
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue