Implement NGINX ingress header regex match

This commit is contained in:
stefanprodan
2020-04-02 01:34:29 +03:00
parent e99e8f22a2
commit 38ef4ef4d8
+12 -4
View File
@@ -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
}