Fix HTTP URI match conditions

This commit is contained in:
stefanprodan
2019-03-11 14:54:17 +02:00
parent 1cd0c49872
commit 881387e522
3 changed files with 17 additions and 4 deletions
+1 -1
View File
@@ -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)(;.*)?$"
+1 -1
View File
@@ -72,7 +72,7 @@ spec:
match:
- headers:
user-agent:
regex: "^(?!.*Chrome)(?=.*\bSafari\b).*$"
regex: "^(?!.*Chrome).*Safari.*"
- headers:
cookie:
regex: "^(.*?;)?(type=insider)(;.*)?$"
+15 -2
View File
@@ -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,
@@ -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,
@@ -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
}