From 63929b0341599fd3b2fd6a41b4cd521d56d67c73 Mon Sep 17 00:00:00 2001 From: Henning Date: Thu, 7 Jan 2021 18:56:03 +0100 Subject: [PATCH] Compile kubernetes ingress annotation regex only once --- pkg/provider/kubernetes/ingress/annotations.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/provider/kubernetes/ingress/annotations.go b/pkg/provider/kubernetes/ingress/annotations.go index 8ec767464..bd7fc8e7c 100644 --- a/pkg/provider/kubernetes/ingress/annotations.go +++ b/pkg/provider/kubernetes/ingress/annotations.go @@ -13,6 +13,8 @@ const ( annotationsPrefix = "traefik.ingress.kubernetes.io/" ) +var annotationsRegex = regexp.MustCompile(`(.+)\.(\w+)\.(\d+)\.(.+)`) + // RouterConfig is the router's root configuration from annotations. type RouterConfig struct { Router *RouterIng `json:"router,omitempty"` @@ -86,8 +88,6 @@ func convertAnnotations(annotations map[string]string) map[string]string { return nil } - exp := regexp.MustCompile(`(.+)\.(\w+)\.(\d+)\.(.+)`) - result := make(map[string]string) for key, value := range annotations { @@ -97,8 +97,8 @@ func convertAnnotations(annotations map[string]string) map[string]string { newKey := strings.ReplaceAll(key, "ingress.kubernetes.io/", "") - if exp.MatchString(newKey) { - newKey = exp.ReplaceAllString(newKey, "$1.$2[$3].$4") + if annotationsRegex.MatchString(newKey) { + newKey = annotationsRegex.ReplaceAllString(newKey, "$1.$2[$3].$4") } result[newKey] = value