Skip to content

Commit

Permalink
Fix HTTP URI match conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanprodan committed Mar 11, 2019
1 parent 1cd0c49 commit 881387e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/gitbook/how-it-works.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ You can enable A/B testing by specifying the HTTP match conditions and the numbe
match:
- headers:
user-agent:
regex: "^(?!.*Chrome)(?=.*\bSafari\b).*$"
regex: "^(?!.*Chrome).*Safari.*"
- headers:
cookie:
regex: "^(.*?;)?(user=test)(;.*)?$"
Expand Down
2 changes: 1 addition & 1 deletion docs/gitbook/usage/ab-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ spec:
match:
- headers:
user-agent:
regex: "^(?!.*Chrome)(?=.*\bSafari\b).*$"
regex: "^(?!.*Chrome).*Safari.*"
- headers:
cookie:
regex: "^(.*?;)?(type=insider)(;.*)?$"
Expand Down
17 changes: 15 additions & 2 deletions pkg/router/istio.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (ir *IstioRouter) Sync(canary *flaggerv1.Canary) error {
}

if len(canary.Spec.CanaryAnalysis.Match) > 0 {
canaryMatch := append(canary.Spec.Service.Match, canary.Spec.CanaryAnalysis.Match...)
canaryMatch := mergeMatchConditions(canary.Spec.CanaryAnalysis.Match, canary.Spec.Service.Match)
newSpec.Http = []istiov1alpha3.HTTPRoute{
{
Match: canaryMatch,
Expand Down Expand Up @@ -274,7 +274,7 @@ func (ir *IstioRouter) SetRoutes(
// fix routing (A/B testing)
if len(canary.Spec.CanaryAnalysis.Match) > 0 {
// merge the common routes with the canary ones
canaryMatch := append(canary.Spec.Service.Match, canary.Spec.CanaryAnalysis.Match...)
canaryMatch := mergeMatchConditions(canary.Spec.CanaryAnalysis.Match, canary.Spec.Service.Match)
vsCopy.Spec.Http = []istiov1alpha3.HTTPRoute{
{
Match: canaryMatch,
Expand Down Expand Up @@ -345,3 +345,16 @@ func addHeaders(canary *flaggerv1.Canary) (headers map[string]string) {

return
}

// mergeMatchConditions appends the URI match rules to canary conditions
func mergeMatchConditions(canary, defaults []istiov1alpha3.HTTPMatchRequest) []istiov1alpha3.HTTPMatchRequest {
for i := range canary {
for _, d := range defaults {
if d.Uri != nil {
canary[i].Uri = d.Uri
}
}
}

return canary
}

0 comments on commit 881387e

Please sign in to comment.