mirror of
https://github.com/fluxcd/flagger.git
synced 2026-04-15 06:57:34 +00:00
Implement NGINX ingress header regex match
This commit is contained in:
+12
-4
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user