diff --git a/internal/configs/annotations.go b/internal/configs/annotations.go index f620183083..120e440f10 100644 --- a/internal/configs/annotations.go +++ b/internal/configs/annotations.go @@ -148,20 +148,12 @@ func parseAnnotations(ingEx *IngressEx, baseCfgParams *ConfigParams, isPlus bool } } - if serverSnippets, exists, err := GetMapKeyAsStringSlice(ingEx.Ingress.Annotations, "nginx.org/server-snippets", ingEx.Ingress, "\n"); exists { - if err != nil { - glog.Error(err) - } else { - cfgParams.ServerSnippets = serverSnippets - } + if serverSnippets, exists := GetMapKeyAsStringSlice(ingEx.Ingress.Annotations, "nginx.org/server-snippets", ingEx.Ingress, "\n"); exists { + cfgParams.ServerSnippets = serverSnippets } - if locationSnippets, exists, err := GetMapKeyAsStringSlice(ingEx.Ingress.Annotations, "nginx.org/location-snippets", ingEx.Ingress, "\n"); exists { - if err != nil { - glog.Error(err) - } else { - cfgParams.LocationSnippets = locationSnippets - } + if locationSnippets, exists := GetMapKeyAsStringSlice(ingEx.Ingress.Annotations, "nginx.org/location-snippets", ingEx.Ingress, "\n"); exists { + cfgParams.LocationSnippets = locationSnippets } if proxyConnectTimeout, exists := ingEx.Ingress.Annotations["nginx.org/proxy-connect-timeout"]; exists { @@ -188,20 +180,12 @@ func parseAnnotations(ingEx *IngressEx, baseCfgParams *ConfigParams, isPlus bool } } - if proxyHideHeaders, exists, err := GetMapKeyAsStringSlice(ingEx.Ingress.Annotations, "nginx.org/proxy-hide-headers", ingEx.Ingress, ","); exists { - if err != nil { - glog.Error(err) - } else { - cfgParams.ProxyHideHeaders = proxyHideHeaders - } + if proxyHideHeaders, exists := GetMapKeyAsStringSlice(ingEx.Ingress.Annotations, "nginx.org/proxy-hide-headers", ingEx.Ingress, ","); exists { + cfgParams.ProxyHideHeaders = proxyHideHeaders } - if proxyPassHeaders, exists, err := GetMapKeyAsStringSlice(ingEx.Ingress.Annotations, "nginx.org/proxy-pass-headers", ingEx.Ingress, ","); exists { - if err != nil { - glog.Error(err) - } else { - cfgParams.ProxyPassHeaders = proxyPassHeaders - } + if proxyPassHeaders, exists := GetMapKeyAsStringSlice(ingEx.Ingress.Annotations, "nginx.org/proxy-pass-headers", ingEx.Ingress, ","); exists { + cfgParams.ProxyPassHeaders = proxyPassHeaders } if clientMaxBodySize, exists := ingEx.Ingress.Annotations["nginx.org/client-max-body-size"]; exists { diff --git a/internal/configs/configmaps.go b/internal/configs/configmaps.go index 5250efd36c..9de5e00fa2 100644 --- a/internal/configs/configmaps.go +++ b/internal/configs/configmaps.go @@ -58,20 +58,12 @@ func ParseConfigMap(cfgm *v1.ConfigMap, nginxPlus bool, hasAppProtect bool, hasA cfgParams.ProxySendTimeout = proxySendTimeout } - if proxyHideHeaders, exists, err := GetMapKeyAsStringSlice(cfgm.Data, "proxy-hide-headers", cfgm, ","); exists { - if err != nil { - glog.Error(err) - } else { - cfgParams.ProxyHideHeaders = proxyHideHeaders - } + if proxyHideHeaders, exists := GetMapKeyAsStringSlice(cfgm.Data, "proxy-hide-headers", cfgm, ","); exists { + cfgParams.ProxyHideHeaders = proxyHideHeaders } - if proxyPassHeaders, exists, err := GetMapKeyAsStringSlice(cfgm.Data, "proxy-pass-headers", cfgm, ","); exists { - if err != nil { - glog.Error(err) - } else { - cfgParams.ProxyPassHeaders = proxyPassHeaders - } + if proxyPassHeaders, exists := GetMapKeyAsStringSlice(cfgm.Data, "proxy-pass-headers", cfgm, ","); exists { + cfgParams.ProxyPassHeaders = proxyPassHeaders } if clientMaxBodySize, exists := cfgm.Data["client-max-body-size"]; exists { @@ -170,12 +162,8 @@ func ParseConfigMap(cfgm *v1.ConfigMap, nginxPlus bool, hasAppProtect bool, hasA } } - if setRealIPFrom, exists, err := GetMapKeyAsStringSlice(cfgm.Data, "set-real-ip-from", cfgm, ","); exists { - if err != nil { - glog.Error(err) - } else { - cfgParams.SetRealIPFrom = setRealIPFrom - } + if setRealIPFrom, exists := GetMapKeyAsStringSlice(cfgm.Data, "set-real-ip-from", cfgm, ","); exists { + cfgParams.SetRealIPFrom = setRealIPFrom } if realIPRecursive, exists, err := GetMapKeyAsBool(cfgm.Data, "real-ip-recursive", cfgm); exists { @@ -219,12 +207,8 @@ func ParseConfigMap(cfgm *v1.ConfigMap, nginxPlus bool, hasAppProtect bool, hasA } } - if logFormat, exists, err := GetMapKeyAsStringSlice(cfgm.Data, "log-format", cfgm, "\n"); exists { - if err != nil { - glog.Error(err) - } else { - cfgParams.MainLogFormat = logFormat - } + if logFormat, exists := GetMapKeyAsStringSlice(cfgm.Data, "log-format", cfgm, "\n"); exists { + cfgParams.MainLogFormat = logFormat } if logFormatEscaping, exists := cfgm.Data["log-format-escaping"]; exists { @@ -234,12 +218,8 @@ func ParseConfigMap(cfgm *v1.ConfigMap, nginxPlus bool, hasAppProtect bool, hasA } } - if streamLogFormat, exists, err := GetMapKeyAsStringSlice(cfgm.Data, "stream-log-format", cfgm, "\n"); exists { - if err != nil { - glog.Error(err) - } else { - cfgParams.MainStreamLogFormat = streamLogFormat - } + if streamLogFormat, exists := GetMapKeyAsStringSlice(cfgm.Data, "stream-log-format", cfgm, "\n"); exists { + cfgParams.MainStreamLogFormat = streamLogFormat } if streamLogFormatEscaping, exists := cfgm.Data["stream-log-format-escaping"]; exists { @@ -281,36 +261,20 @@ func ParseConfigMap(cfgm *v1.ConfigMap, nginxPlus bool, hasAppProtect bool, hasA cfgParams.ProxyMaxTempFileSize = proxyMaxTempFileSize } - if mainMainSnippets, exists, err := GetMapKeyAsStringSlice(cfgm.Data, "main-snippets", cfgm, "\n"); exists { - if err != nil { - glog.Error(err) - } else { - cfgParams.MainMainSnippets = mainMainSnippets - } + if mainMainSnippets, exists := GetMapKeyAsStringSlice(cfgm.Data, "main-snippets", cfgm, "\n"); exists { + cfgParams.MainMainSnippets = mainMainSnippets } - if mainHTTPSnippets, exists, err := GetMapKeyAsStringSlice(cfgm.Data, "http-snippets", cfgm, "\n"); exists { - if err != nil { - glog.Error(err) - } else { - cfgParams.MainHTTPSnippets = mainHTTPSnippets - } + if mainHTTPSnippets, exists := GetMapKeyAsStringSlice(cfgm.Data, "http-snippets", cfgm, "\n"); exists { + cfgParams.MainHTTPSnippets = mainHTTPSnippets } - if locationSnippets, exists, err := GetMapKeyAsStringSlice(cfgm.Data, "location-snippets", cfgm, "\n"); exists { - if err != nil { - glog.Error(err) - } else { - cfgParams.LocationSnippets = locationSnippets - } + if locationSnippets, exists := GetMapKeyAsStringSlice(cfgm.Data, "location-snippets", cfgm, "\n"); exists { + cfgParams.LocationSnippets = locationSnippets } - if serverSnippets, exists, err := GetMapKeyAsStringSlice(cfgm.Data, "server-snippets", cfgm, "\n"); exists { - if err != nil { - glog.Error(err) - } else { - cfgParams.ServerSnippets = serverSnippets - } + if serverSnippets, exists := GetMapKeyAsStringSlice(cfgm.Data, "server-snippets", cfgm, "\n"); exists { + cfgParams.ServerSnippets = serverSnippets } if _, exists, err := GetMapKeyAsInt(cfgm.Data, "worker-processes", cfgm); exists { @@ -373,23 +337,15 @@ func ParseConfigMap(cfgm *v1.ConfigMap, nginxPlus bool, hasAppProtect bool, hasA cfgParams.VirtualServerTemplate = &virtualServerTemplate } - if mainStreamSnippets, exists, err := GetMapKeyAsStringSlice(cfgm.Data, "stream-snippets", cfgm, "\n"); exists { - if err != nil { - glog.Error(err) - } else { - cfgParams.MainStreamSnippets = mainStreamSnippets - } + if mainStreamSnippets, exists := GetMapKeyAsStringSlice(cfgm.Data, "stream-snippets", cfgm, "\n"); exists { + cfgParams.MainStreamSnippets = mainStreamSnippets } - if resolverAddresses, exists, err := GetMapKeyAsStringSlice(cfgm.Data, "resolver-addresses", cfgm, ","); exists { - if err != nil { - glog.Error(err) + if resolverAddresses, exists := GetMapKeyAsStringSlice(cfgm.Data, "resolver-addresses", cfgm, ","); exists { + if nginxPlus { + cfgParams.ResolverAddresses = resolverAddresses } else { - if nginxPlus { - cfgParams.ResolverAddresses = resolverAddresses - } else { - glog.Warning("ConfigMap key 'resolver-addresses' requires NGINX Plus") - } + glog.Warning("ConfigMap key 'resolver-addresses' requires NGINX Plus") } } @@ -521,12 +477,8 @@ func ParseConfigMap(cfgm *v1.ConfigMap, nginxPlus bool, hasAppProtect bool, hasA } if hasAppProtectDos { - if appProtectDosLogFormat, exists, err := GetMapKeyAsStringSlice(cfgm.Data, "app-protect-dos-log-format", cfgm, "\n"); exists { - if err != nil { - glog.Error(err) - } else { - cfgParams.MainAppProtectDosLogFormat = appProtectDosLogFormat - } + if appProtectDosLogFormat, exists := GetMapKeyAsStringSlice(cfgm.Data, "app-protect-dos-log-format", cfgm, "\n"); exists { + cfgParams.MainAppProtectDosLogFormat = appProtectDosLogFormat } if appProtectDosLogFormatEscaping, exists := cfgm.Data["app-protect-dos-log-format-escaping"]; exists { diff --git a/internal/configs/parsing_helpers.go b/internal/configs/parsing_helpers.go index 3883056099..831c30f034 100644 --- a/internal/configs/parsing_helpers.go +++ b/internal/configs/parsing_helpers.go @@ -79,13 +79,12 @@ func GetMapKeyAsUint64(m map[string]string, key string, context apiObject, nonZe } // GetMapKeyAsStringSlice tries to find and parse a key in the map as string slice splitting it on delimiter. -func GetMapKeyAsStringSlice(m map[string]string, key string, _ apiObject, delimiter string) ([]string, bool, error) { +func GetMapKeyAsStringSlice(m map[string]string, key string, _ apiObject, delimiter string) ([]string, bool) { if str, exists := m[key]; exists { slice := strings.Split(str, delimiter) - return slice, exists, nil + return slice, exists } - - return nil, false, nil + return nil, false } // ParseLBMethod parses method and matches it to a corresponding load balancing method in NGINX. An error is returned if method is not valid. diff --git a/internal/configs/parsing_helpers_test.go b/internal/configs/parsing_helpers_test.go index e406208686..ac5cdd78f9 100644 --- a/internal/configs/parsing_helpers_test.go +++ b/internal/configs/parsing_helpers_test.go @@ -229,10 +229,7 @@ func TestGetMapKeyAsStringSlice(t *testing.T) { "key": "1.String,2.String,3.String", } - slice, exists, err := GetMapKeyAsStringSlice(configMap.Data, "key", &configMap, ",") - if err != nil { - t.Errorf("Unexpected error: %v", err) - } + slice, exists := GetMapKeyAsStringSlice(configMap.Data, "key", &configMap, ",") if !exists { t.Errorf("The key 'key' must exist in the configMap") } @@ -253,10 +250,7 @@ func TestGetMapKeyAsStringSliceMultilineSnippets(t *testing.T) { }`, } - slice, exists, err := GetMapKeyAsStringSlice(configMap.Data, "server-snippets", &configMap, "\n") - if err != nil { - t.Errorf("Unexpected error: %v", err) - } + slice, exists := GetMapKeyAsStringSlice(configMap.Data, "server-snippets", &configMap, "\n") if !exists { t.Errorf("The key 'server-snippets' must exist in the configMap") } @@ -272,7 +266,7 @@ func TestGetMapKeyAsStringSliceNotFound(t *testing.T) { configMap := configMap configMap.Data = map[string]string{} - _, exists, _ := GetMapKeyAsStringSlice(configMap.Data, "key", &configMap, ",") + _, exists := GetMapKeyAsStringSlice(configMap.Data, "key", &configMap, ",") if exists { t.Errorf("The key 'key' must not exist in the configMap") }