|
| 1 | +/* |
| 2 | +Copyright 2020 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package settings |
| 18 | + |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | + "strings" |
| 22 | + "syscall" |
| 23 | + |
| 24 | + "github.com/onsi/ginkgo" |
| 25 | + "k8s.io/ingress-nginx/test/e2e/framework" |
| 26 | +) |
| 27 | + |
| 28 | +var _ = framework.IngressNginxDescribe("global-options", func() { |
| 29 | + f := framework.NewDefaultFramework("global-options") |
| 30 | + |
| 31 | + ginkgo.It("should have worker_rlimit_nofile option", func() { |
| 32 | + f.WaitForNginxConfiguration(func(server string) bool { |
| 33 | + return strings.Contains(server, fmt.Sprintf("worker_rlimit_nofile %d;", rlimitMaxNumFiles()-1024)) |
| 34 | + |
| 35 | + }) |
| 36 | + }) |
| 37 | + |
| 38 | + ginkgo.It("should have worker_rlimit_nofile option and be independent on amount of worker processes", func() { |
| 39 | + f.SetNginxConfigMapData(map[string]string{ |
| 40 | + "worker-processes": "11", |
| 41 | + }) |
| 42 | + |
| 43 | + f.WaitForNginxConfiguration(func(server string) bool { |
| 44 | + return strings.Contains(server, "worker_processes 11;") && |
| 45 | + strings.Contains(server, fmt.Sprintf("worker_rlimit_nofile %d;", rlimitMaxNumFiles()-1024)) |
| 46 | + }) |
| 47 | + }) |
| 48 | +}) |
| 49 | + |
| 50 | +// rlimitMaxNumFiles returns hard limit for RLIMIT_NOFILE |
| 51 | +func rlimitMaxNumFiles() int { |
| 52 | + var rLimit syscall.Rlimit |
| 53 | + err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit) |
| 54 | + if err != nil { |
| 55 | + return 0 |
| 56 | + } |
| 57 | + return int(rLimit.Max) |
| 58 | +} |
0 commit comments