-
Notifications
You must be signed in to change notification settings - Fork 102
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
determine if nbresuse is running in docker or pod #66
base: main
Are you sure you want to change the base?
Conversation
Get resources and usages in docker, and return the correct values i think
Determine if nbresuse running in docker
forgot import os module |
Thanks @xianglei. It's true the limits are for now not accurate when running in a container (not taking the cgroups limits into account). |
|
||
@staticmethod | ||
def __if_dockerized(): | ||
if os.path.exists('/.dockerenv'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a reliable way of detecting whether it is running in Docker? Does this file exist with other container engines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not present on Podman.
I found this stackoverflow question which provides a bit of background: https://superuser.com/questions/1021834/what-are-dockerenv-and-dockerinit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just checked with Kubernetes K3S too, it's also not present.
However it looks like /sys/fs/cgroup/memory/memory.limit_in_bytes
is set to <very large number> if there's no limit:
k3os-5708 [~]$ kubectl run tmp-shell --rm -i --tty --image busybox -- /bin/sh
If you don't see a command prompt, try pressing enter.
/ # cat /.dockerenv
cat: can't open '/.dockerenv': No such file or directory
/ # cat /sys/fs/cgroup/memory/memory.limit_in_bytes
9223372036854771712
k3os-5708 [~]$ kubectl run tmp-shell --rm -i --tty --image busybox --limits=memory=10Mi -- /bin/sh
If you don't see a command prompt, try pressing enter.
/ # cat /sys/fs/cgroup/memory/memory.limit_in_bytes
10485760
So one solution might be to see if /sys/fs/cgroup/memory/memory.limit_in_bytes
exists, and if so use min(/sys/fs/cgroup/memory/memory.limit_in_bytes, total-system-memory)
, and skip the container check completely?
It's also worth noting that cgroups2 is different, I haven't figured out how to find the memory limit there.
It looks like there are conflicts which cannot be resolved via UI, is this PR still relevant? |
Returns the correct memory & cpu values when nbresuse running in a docker or pod environment