Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enabling logic to find the correct value of the file limit #2156

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions internal/ingress/controller/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package controller

import (
"github.com/golang/glog"
"math"
"syscall"

api "k8s.io/api/core/v1"
"k8s.io/kubernetes/pkg/util/sysctl"
Expand Down Expand Up @@ -55,12 +57,36 @@ func sysctlSomaxconn() int {
// sysctlFSFileMax returns the value of fs.file-max, i.e.
// maximum number of open file descriptors
func sysctlFSFileMax() int {
fileMax, err := sysctl.New().GetSysctl("fs/file-max")
kernelFileMax, err := sysctl.New().GetSysctl("fs/file-max")
if err != nil {
glog.Errorf("unexpected error reading system maximum number of open file descriptors (fs.file-max): %v", err)
// returning 0 means don't render the value
return 0
glog.Warnf("unexpected error reading system maximum number of open file descriptors (fs.file-max): %v", err)
kernelFileMax = nil
}
glog.V(2).Infof("system fs.file-max=%v", fileMax)
return fileMax

if kernelFileMax != nil {
glog.V(2).Infof("system fs.file-max=%v", kernelFileMax)
}

var userLimit syscall.Rlimit
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &userLimit)
if err != nil {
glog.Warnf("unexpected error reading system maximum number of open file descriptors (RLIMIT_NOFILE): %v", err)
userLimit = nil
}

if kernelFileMax != nil && userLimit != nil {
return int(Min(kernelFileMax, userLimit.Max))
}

if kernelFileMax != nil {
return kernelFileMax
}

if userLimit != nil {
return int(userLimit.Max)
}

glog.Error("cannot read both (fs.file-max) and (RLIMIT_NOFILE)")
// returning 0 means don't render the value
return 0
}