We have a library that uses POSIX message queues to pass data between processes and requires having the msgqueue kernel parameter set to unlimited, otherwise the process will return an error too many open files. Usually we view/set this using ulimit -q and ulimit -q unlimited, but for some Kubernetes containers we want to be able to set this directly via go code.
We have already confirmed that the pod spec allows changing mqueue settings (via securityContext for Kubernetes 1.14+) and that the specific container can adjust resource setting:
...
kind: Deployment
...
spec:
template:
spec:
securityContext:
sysctls:
- name: fs.mqueue.msg_max
value: "10000"
- name: fs.mqueue.msgsize_max
value: "102400"
containers:
- name: testing
securityContext:
capabilities:
add:
- SYS_RESOURCE
...
Without those settings even ulimit -q unlimited would get an error:
bash: ulimit: POSIX message queues: cannot modify limit: Operation not permitted
But how would we use syscall.Setrlimit to adjust the limit value from our code?
Looks like the syscall package was frozen without the
RLIMIT_MSGQUEUE = 0xCconstant, and it also definessyscall.RLIM_INFINITY = -0x1which results in an error when attempting to use that value:So instead you have to manually define the constants
or switch to using the methods from https://godoc.org/golang.org/x/sys/unix:
also note that the limit values are set only for that process and it's children, so to confirm you have to either check
/proc/<pid>/limitsor call Getrlimit/ulimit from the code as well: