From aee62ebd2d6b5714a64f1ea910e810d03860199d Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 21 Oct 2024 20:22:04 -0400 Subject: [PATCH] fix: strip non-numeric characters from certain ingress-nginx annotation values The controller does not do so on our behalf and ends up falling back to the default values. Closes #7292 --- plugins/scheduler-k3s/functions.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/plugins/scheduler-k3s/functions.go b/plugins/scheduler-k3s/functions.go index f022dc8e6..d9ae2e092 100644 --- a/plugins/scheduler-k3s/functions.go +++ b/plugins/scheduler-k3s/functions.go @@ -9,6 +9,7 @@ import ( "net" "os" "path/filepath" + "regexp" "sort" "strconv" "strings" @@ -741,6 +742,7 @@ func getIngressAnnotations(appName string, processType string) (map[string]strin type annotation struct { annotation string getter func(appName string) string + modifier func(value string) string locationSnippet func(value string) string serverSnippet func(value string) string } @@ -748,6 +750,8 @@ func getIngressAnnotations(appName string, processType string) (map[string]strin locationLines := []string{} serverLines := []string{} + numericOnlyRegex := regexp.MustCompile("[^0-9]") + properties := map[string]annotation{ "access-log-path": { getter: nginxvhosts.ComputedAccessLogPath, @@ -856,14 +860,23 @@ func getIngressAnnotations(appName string, processType string) (map[string]strin "proxy-connect-timeout": { annotation: "nginx.ingress.kubernetes.io/proxy-connect-timeout", getter: nginxvhosts.ComputedProxyConnectTimeout, + modifier: func(value string) string { + return numericOnlyRegex.ReplaceAllString(value, "") + }, }, "proxy-read-timeout": { annotation: "nginx.ingress.kubernetes.io/proxy-read-timeout", getter: nginxvhosts.ComputedProxyReadTimeout, + modifier: func(value string) string { + return numericOnlyRegex.ReplaceAllString(value, "") + }, }, "proxy-send-timeout": { annotation: "nginx.ingress.kubernetes.io/proxy-send-timeout", getter: nginxvhosts.ComputedProxySendTimeout, + modifier: func(value string) string { + return numericOnlyRegex.ReplaceAllString(value, "") + }, }, "send-timeout": { getter: nginxvhosts.ComputedSendTimeout, @@ -923,12 +936,17 @@ func getIngressAnnotations(appName string, processType string) (map[string]strin annotations := map[string]string{} for _, newKey := range properties { + value := newKey.getter(appName) + if newKey.modifier != nil { + value = newKey.modifier(value) + } + if newKey.locationSnippet != nil { - locationLines = append(locationLines, newKey.locationSnippet(newKey.getter(appName))) + locationLines = append(locationLines, newKey.locationSnippet(value)) } else if newKey.serverSnippet != nil { - serverLines = append(serverLines, newKey.serverSnippet(newKey.getter(appName))) + serverLines = append(serverLines, newKey.serverSnippet(value)) } else if newKey.annotation != "" { - annotations[newKey.annotation] = newKey.getter(appName) + annotations[newKey.annotation] = value } }