Merge pull request #7293 from dokku/7292-remove-non-numeric

Strop non-numeric characters from certain ingress-nginx annotation values
This commit is contained in:
Jose Diaz-Gonzalez authored and GitHub committed 2024-10-21 21:39:41 -04:00
commit 1fe5b8927a
1 file changed
+21 -3
+21 -3
View File
@@ -9,6 +9,7 @@ import (
"net" "net"
"os" "os"
"path/filepath" "path/filepath"
"regexp"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
@@ -741,6 +742,7 @@ func getIngressAnnotations(appName string, processType string) (map[string]strin
type annotation struct { type annotation struct {
annotation string annotation string
getter func(appName string) string getter func(appName string) string
modifier func(value string) string
locationSnippet func(value string) string locationSnippet func(value string) string
serverSnippet func(value string) string serverSnippet func(value string) string
} }
@@ -748,6 +750,8 @@ func getIngressAnnotations(appName string, processType string) (map[string]strin
locationLines := []string{} locationLines := []string{}
serverLines := []string{} serverLines := []string{}
numericOnlyRegex := regexp.MustCompile("[^0-9]")
properties := map[string]annotation{ properties := map[string]annotation{
"access-log-path": { "access-log-path": {
getter: nginxvhosts.ComputedAccessLogPath, getter: nginxvhosts.ComputedAccessLogPath,
@@ -856,14 +860,23 @@ func getIngressAnnotations(appName string, processType string) (map[string]strin
"proxy-connect-timeout": { "proxy-connect-timeout": {
annotation: "nginx.ingress.kubernetes.io/proxy-connect-timeout", annotation: "nginx.ingress.kubernetes.io/proxy-connect-timeout",
getter: nginxvhosts.ComputedProxyConnectTimeout, getter: nginxvhosts.ComputedProxyConnectTimeout,
modifier: func(value string) string {
return numericOnlyRegex.ReplaceAllString(value, "")
},
}, },
"proxy-read-timeout": { "proxy-read-timeout": {
annotation: "nginx.ingress.kubernetes.io/proxy-read-timeout", annotation: "nginx.ingress.kubernetes.io/proxy-read-timeout",
getter: nginxvhosts.ComputedProxyReadTimeout, getter: nginxvhosts.ComputedProxyReadTimeout,
modifier: func(value string) string {
return numericOnlyRegex.ReplaceAllString(value, "")
},
}, },
"proxy-send-timeout": { "proxy-send-timeout": {
annotation: "nginx.ingress.kubernetes.io/proxy-send-timeout", annotation: "nginx.ingress.kubernetes.io/proxy-send-timeout",
getter: nginxvhosts.ComputedProxySendTimeout, getter: nginxvhosts.ComputedProxySendTimeout,
modifier: func(value string) string {
return numericOnlyRegex.ReplaceAllString(value, "")
},
}, },
"send-timeout": { "send-timeout": {
getter: nginxvhosts.ComputedSendTimeout, getter: nginxvhosts.ComputedSendTimeout,
@@ -923,12 +936,17 @@ func getIngressAnnotations(appName string, processType string) (map[string]strin
annotations := map[string]string{} annotations := map[string]string{}
for _, newKey := range properties { for _, newKey := range properties {
value := newKey.getter(appName)
if newKey.modifier != nil {
value = newKey.modifier(value)
}
if newKey.locationSnippet != nil { if newKey.locationSnippet != nil {
locationLines = append(locationLines, newKey.locationSnippet(newKey.getter(appName))) locationLines = append(locationLines, newKey.locationSnippet(value))
} else if newKey.serverSnippet != nil { } else if newKey.serverSnippet != nil {
serverLines = append(serverLines, newKey.serverSnippet(newKey.getter(appName))) serverLines = append(serverLines, newKey.serverSnippet(value))
} else if newKey.annotation != "" { } else if newKey.annotation != "" {
annotations[newKey.annotation] = newKey.getter(appName) annotations[newKey.annotation] = value
} }
} }