From 38ef4ef4d889bfe1c5cddb20e3f86fce954e6fad Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Thu, 2 Apr 2020 01:34:29 +0300 Subject: [PATCH] Implement NGINX ingress header regex match --- pkg/router/ingress.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/router/ingress.go b/pkg/router/ingress.go index db31a30b..bf77eb2a 100644 --- a/pkg/router/ingress.go +++ b/pkg/router/ingress.go @@ -159,19 +159,23 @@ func (i *IngressRouter) SetRoutes( // A/B testing if len(canary.GetAnalysis().Match) > 0 { - var cookie, header, headerValue string + var cookie, header, headerValue, headerRegex string for _, m := range canary.GetAnalysis().Match { for k, v := range m.Headers { if k == "cookie" { cookie = v.Exact } else { header = k - headerValue = v.Exact + if v.Regex != "" { + headerRegex = v.Regex + } else { + headerValue = v.Exact + } } } } - iClone.Annotations = i.makeHeaderAnnotations(iClone.Annotations, header, headerValue, cookie) + iClone.Annotations = i.makeHeaderAnnotations(iClone.Annotations, header, headerValue, headerRegex, cookie) } else { // canary iClone.Annotations[i.GetAnnotationWithPrefix("canary-weight")] = fmt.Sprintf("%v", canaryWeight) @@ -208,7 +212,7 @@ func (i *IngressRouter) makeAnnotations(annotations map[string]string) map[strin } func (i *IngressRouter) makeHeaderAnnotations(annotations map[string]string, - header string, headerValue string, cookie string) map[string]string { + header string, headerValue string, headerRegex string, cookie string) map[string]string { res := make(map[string]string) for k, v := range annotations { if !strings.Contains(v, i.GetAnnotationWithPrefix("canary")) { @@ -231,6 +235,10 @@ func (i *IngressRouter) makeHeaderAnnotations(annotations map[string]string, res[i.GetAnnotationWithPrefix("canary-by-header-value")] = headerValue } + if headerRegex != "" { + res[i.GetAnnotationWithPrefix("canary-by-header-pattern")] = headerRegex + } + return res }