diff --git a/docs/user-guide/nginx-configuration/configmap.md b/docs/user-guide/nginx-configuration/configmap.md index 272d1821d..f8a984c0b 100755 --- a/docs/user-guide/nginx-configuration/configmap.md +++ b/docs/user-guide/nginx-configuration/configmap.md @@ -58,7 +58,7 @@ The following table shows a configuration option's name, type, and the default v |[keep-alive-requests](#keep-alive-requests)|int|100| |[large-client-header-buffers](#large-client-header-buffers)|string|"4 8k"| |[log-format-escape-json](#log-format-escape-json)|bool|"false"| -|[log-format-upstream](#log-format-upstream)|string|`$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $request_length $request_time [$proxy_upstream_name] $upstream_addr $upstream_response_length $upstream_response_time $upstream_status $req_id`| +|[log-format-upstream](#log-format-upstream)|string|`$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $request_length $request_time [$proxy_upstream_name] [$proxy_alternative_upstream_name] $upstream_addr $upstream_response_length $upstream_response_time $upstream_status $req_id`| |[log-format-stream](#log-format-stream)|string|`[$time_local] $protocol $status $bytes_sent $bytes_received $session_time`| |[enable-multi-accept](#enable-multi-accept)|bool|"true"| |[max-worker-connections](#max-worker-connections)|int|16384| diff --git a/docs/user-guide/nginx-configuration/custom-template.md b/docs/user-guide/nginx-configuration/custom-template.md index 95f13bda9..0cbb540c4 100644 --- a/docs/user-guide/nginx-configuration/custom-template.md +++ b/docs/user-guide/nginx-configuration/custom-template.md @@ -2,7 +2,7 @@ The NGINX template is located in the file `/etc/nginx/template/nginx.tmpl`. -Using a [Volume](https://kubernetes.io/docs/concepts/storage/volumes/) it is possible to use a custom template. +Using a [Volume](https://kubernetes.io/docs/concepts/storage/volumes/) it is possible to use a custom template. This includes using a [Configmap](https://kubernetes.io/docs/concepts/storage/volumes/#example-pod-with-a-secret-a-downward-api-and-a-configmap) as source of the template ```yaml @@ -40,7 +40,6 @@ TODO: - buildAuthLocation: - buildAuthResponseHeaders: - buildResolvers: -- buildLogFormatUpstream: - buildDenyVariable: - buildUpstreamName: - buildForwardedFor: diff --git a/internal/ingress/controller/config/config.go b/internal/ingress/controller/config/config.go index 846735d42..2a322f9ec 100644 --- a/internal/ingress/controller/config/config.go +++ b/internal/ingress/controller/config/config.go @@ -17,7 +17,6 @@ limitations under the License. package config import ( - "fmt" "strconv" "time" @@ -779,17 +778,6 @@ func NewDefault() Configuration { return cfg } -// BuildLogFormatUpstream format the log_format upstream using -// proxy_protocol_addr as remote client address if UseProxyProtocol -// is enabled. -func (cfg Configuration) BuildLogFormatUpstream() string { - if cfg.LogFormatUpstream == logFormatUpstream { - return fmt.Sprintf(cfg.LogFormatUpstream, "$remote_addr") - } - - return cfg.LogFormatUpstream -} - // TemplateConfig contains the nginx configuration to render the file nginx.conf type TemplateConfig struct { ProxySetHeaders map[string]string diff --git a/internal/ingress/controller/config/config_test.go b/internal/ingress/controller/config/config_test.go deleted file mode 100644 index b27922fe7..000000000 --- a/internal/ingress/controller/config/config_test.go +++ /dev/null @@ -1,43 +0,0 @@ -/* -Copyright 2017 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package config - -import ( - "testing" -) - -func TestBuildLogFormatUpstream(t *testing.T) { - - testCases := []struct { - useProxyProtocol bool // use proxy protocol - curLogFormat string - expected string - }{ - {true, "my-log-format", "my-log-format"}, - {false, "john-log-format", "john-log-format"}, - } - - for _, testCase := range testCases { - cfg := NewDefault() - cfg.UseProxyProtocol = testCase.useProxyProtocol - cfg.LogFormatUpstream = testCase.curLogFormat - result := cfg.BuildLogFormatUpstream() - if result != testCase.expected { - t.Errorf(" expected %v but return %v", testCase.expected, result) - } - } -} diff --git a/internal/ingress/controller/template/template.go b/internal/ingress/controller/template/template.go index 7d8593de0..57966572a 100644 --- a/internal/ingress/controller/template/template.go +++ b/internal/ingress/controller/template/template.go @@ -151,7 +151,6 @@ var ( "buildUpstreamName": buildUpstreamName, "isLocationInLocationList": isLocationInLocationList, "isLocationAllowed": isLocationAllowed, - "buildLogFormatUpstream": buildLogFormatUpstream, "buildDenyVariable": buildDenyVariable, "getenv": os.Getenv, "contains": strings.Contains, @@ -462,16 +461,6 @@ func buildAuthResponseHeaders(headers []string) []string { return res } -func buildLogFormatUpstream(input interface{}) string { - cfg, ok := input.(config.Configuration) - if !ok { - klog.Errorf("expected a 'config.Configuration' type but %T was returned", input) - return "" - } - - return cfg.BuildLogFormatUpstream() -} - // buildProxyPass produces the proxy pass string, if the ingress has redirects // (specified through the nginx.ingress.kubernetes.io/rewrite-target annotation) // If the annotation nginx.ingress.kubernetes.io/add-base-url:"true" is specified it will diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl index 0dd97b75a..9018fe8ce 100755 --- a/rootfs/etc/nginx/template/nginx.tmpl +++ b/rootfs/etc/nginx/template/nginx.tmpl @@ -267,7 +267,7 @@ http { # $ingress_name # $service_name # $service_port - log_format upstreaminfo {{ if $cfg.LogFormatEscapeJSON }}escape=json {{ end }}'{{ buildLogFormatUpstream $cfg }}'; + log_format upstreaminfo {{ if $cfg.LogFormatEscapeJSON }}escape=json {{ end }}'{{ $cfg.LogFormatUpstream }}'; {{/* map urls that should not appear in access.log */}} {{/* http://nginx.org/en/docs/http/ngx_http_log_module.html#access_log */}}