diff --git a/docs/user-guide/nginx-configuration/configmap.md b/docs/user-guide/nginx-configuration/configmap.md index e8e36c542e..80386e96bf 100644 --- a/docs/user-guide/nginx-configuration/configmap.md +++ b/docs/user-guide/nginx-configuration/configmap.md @@ -114,6 +114,7 @@ The following table shows a configuration option's name, type, and the default v |[jaeger-service-name](#jaeger-service-name)|string|"nginx"| |[jaeger-sampler-type](#jaeger-sampler-type)|string|"const"| |[jaeger-sampler-param](#jaeger-sampler-param)|string|"1"| +|[main-snippet](#main-snippet)|string|""| |[http-snippet](#http-snippet)|string|""| |[server-snippet](#server-snippet)|string|""| |[location-snippet](#location-snippet)|string|""| @@ -633,20 +634,21 @@ Specifies the sampler to be used when sampling traces. The available samplers ar Specifies the argument to be passed to the sampler constructor. Must be a number. For const this should be 0 to never sample and 1 to always sample. _**default:**_ 1 +## main-snippet + +Adds custom configuration to the main section of the nginx configuration. + ## http-snippet Adds custom configuration to the http section of the nginx configuration. -_**default:**_ "" ## server-snippet Adds custom configuration to all the servers in the nginx configuration. -_**default:**_ "" ## location-snippet Adds custom configuration to all the locations in the nginx configuration. -_**default:**_ "" ## custom-http-errors diff --git a/internal/ingress/controller/config/config.go b/internal/ingress/controller/config/config.go index cc666912d2..7ff7a32055 100644 --- a/internal/ingress/controller/config/config.go +++ b/internal/ingress/controller/config/config.go @@ -459,6 +459,9 @@ type Configuration struct { // Default: 1 JaegerSamplerParam string `json:"jaeger-sampler-param"` + // MainSnippet adds custom configuration to the main section of the nginx configuration + MainSnippet string `json:"main-snippet"` + // HTTPSnippet adds custom configuration to the http section of the nginx configuration HTTPSnippet string `json:"http-snippet"` diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl index fed5da7b87..cc01efe101 100644 --- a/rootfs/etc/nginx/template/nginx.tmpl +++ b/rootfs/etc/nginx/template/nginx.tmpl @@ -41,6 +41,10 @@ events { use epoll; } +{{ if not (empty $cfg.MainSnippet) }} +{{ $cfg.MainSnippet }} +{{ end }} + http { {{ if not $all.DisableLua }} lua_package_cpath "/usr/local/lib/lua/?.so;/usr/lib/lua-platform-path/lua/5.1/?.so;;"; diff --git a/test/e2e/settings/main_snippet.go b/test/e2e/settings/main_snippet.go new file mode 100644 index 0000000000..d71ec5c911 --- /dev/null +++ b/test/e2e/settings/main_snippet.go @@ -0,0 +1,43 @@ +/* +Copyright 2018 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 settings + +import ( + "strings" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + "k8s.io/ingress-nginx/test/e2e/framework" +) + +var _ = framework.IngressNginxDescribe("Main Snippet", func() { + f := framework.NewDefaultFramework("main-snippet") + mainSnippet := "main-snippet" + + It("should add value of main-snippet setting to nginx config", func() { + expectedComment := "# main snippet" + err := f.UpdateNginxConfigMapData(mainSnippet, expectedComment) + Expect(err).NotTo(HaveOccurred()) + + err = f.WaitForNginxConfiguration( + func(cfg string) bool { + return strings.Contains(cfg, expectedComment) + }) + Expect(err).NotTo(HaveOccurred()) + }) +})