diff --git a/docs/user-guide/nginx-configuration/configmap.md b/docs/user-guide/nginx-configuration/configmap.md index 0258d7954..c947c7a86 100755 --- a/docs/user-guide/nginx-configuration/configmap.md +++ b/docs/user-guide/nginx-configuration/configmap.md @@ -454,7 +454,7 @@ _**default:**_ 16384 ## max-worker-open-files Sets the [maximum number of files](http://nginx.org/en/docs/ngx_core_module.html#worker_rlimit_nofile) that can be opened by each worker process. -The default of 0 means "max open files (system's limit) / [worker-processes](#worker-processes) - 1024". +The default of 0 means "max open files (system's limit) - 1024". _**default:**_ 0 ## map-hash-bucket-size diff --git a/internal/ingress/controller/nginx.go b/internal/ingress/controller/nginx.go index 664d36b75..9fa139cb7 100644 --- a/internal/ingress/controller/nginx.go +++ b/internal/ingress/controller/nginx.go @@ -512,12 +512,7 @@ func (n NGINXController) generateTemplate(cfg ngx_config.Configuration, ingressC if cfg.MaxWorkerOpenFiles == 0 { // the limit of open files is per worker process // and we leave some room to avoid consuming all the FDs available - wp, err := strconv.Atoi(cfg.WorkerProcesses) - klog.V(3).InfoS("Worker processes", "count", wp) - if err != nil { - wp = 1 - } - maxOpenFiles := (rlimitMaxNumFiles() / wp) - 1024 + maxOpenFiles := rlimitMaxNumFiles() - 1024 klog.V(3).InfoS("Maximum number of open file descriptors", "value", maxOpenFiles) if maxOpenFiles < 1024 { // this means the value of RLIMIT_NOFILE is too low. diff --git a/test/e2e/settings/global_options.go b/test/e2e/settings/global_options.go new file mode 100644 index 000000000..ef0487cc5 --- /dev/null +++ b/test/e2e/settings/global_options.go @@ -0,0 +1,58 @@ +/* +Copyright 2020 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 ( + "fmt" + "strings" + "syscall" + + "github.com/onsi/ginkgo" + "k8s.io/ingress-nginx/test/e2e/framework" +) + +var _ = framework.IngressNginxDescribe("global-options", func() { + f := framework.NewDefaultFramework("global-options") + + ginkgo.It("should have worker_rlimit_nofile option", func() { + f.WaitForNginxConfiguration(func(server string) bool { + return strings.Contains(server, fmt.Sprintf("worker_rlimit_nofile %d;", rlimitMaxNumFiles()-1024)) + + }) + }) + + ginkgo.It("should have worker_rlimit_nofile option and be independent on amount of worker processes", func() { + f.SetNginxConfigMapData(map[string]string{ + "worker-processes": "11", + }) + + f.WaitForNginxConfiguration(func(server string) bool { + return strings.Contains(server, "worker_processes 11;") && + strings.Contains(server, fmt.Sprintf("worker_rlimit_nofile %d;", rlimitMaxNumFiles()-1024)) + }) + }) +}) + +// rlimitMaxNumFiles returns hard limit for RLIMIT_NOFILE +func rlimitMaxNumFiles() int { + var rLimit syscall.Rlimit + err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit) + if err != nil { + return 0 + } + return int(rLimit.Max) +}