-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Fix process/config properties merging #4585
base: main
Are you sure you want to change the base?
Conversation
a12d2da
to
ed015c7
Compare
fa41079
to
b39f21b
Compare
This is one of the dark corners of runc / libcontainer, so let's shed some light on it. initConfig is a structure which is filled in [mostly] by newInitConfig, and one of its hidden aspects is it contains a process config which is the result of merge between the container and the process configs. Let's document how all this happens, where the fields are coming from, which one has a preference, and how it all works. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
They are passed in initConfig twice, so it does not make sense. NB: the alternative to that would be to remove Config field from initConfig, but it results in a much bigger patch and more maintenance down the road. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
In runtime-spec, capabilities property is optional, but libcontainer/capabilities panics when New(nil) is called. Because of this, there's a kludge in finalizeNamespace to ensure capabilities.New is not called with nil argument, and there's a TestProcessEmptyCaps to ensure runc won't panic. Let's fix this at the source, allowing libct/cap to work with nil capabilities. (The caller is fixed by the next commit.) Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
For all other properties that are available in both Config and Process, the merging is performed by newInitConfig. Let's do the same for Capabilities for the sake of code uniformity. Also, thanks to the previous commit, we no longer have to make sure we do not call capabilities.New(nil). Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Commit bfbd030 added IOPriority field into both Config and Process, but forgot to add a mechanism to actually use Process.IOPriority. As a result, runc exec does not set Process.IOPriority ever. Fix it, and a test case (which fails before the fix). Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Commit 770728e added Scheduler field into both Config and Process, but forgot to add a mechanism to actually use Process.Scheduler. As a result, runc exec does not set Process.Scheduler ever. Fix it, and a test case (which fails before the fix). Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
b39f21b
to
8bab6ac
Compare
|
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.
@kolyshkin thanks for tackling this, very nice cleanups!
Do we want to backport this to 1.2?
Left some minor questions, this mostly LGTM.
# shellcheck disable=SC2016 | ||
run chrt -p "$(cat pid.txt)" |
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 can't see why this run line will trigger that shelcheck: https://www.shellcheck.net/wiki/SC2016
Do you understand why?
We had tests before but they were not doing what we wanted, so I want to make sure we don't accidentally have a bug in the test again :)
"period": 1000000 | ||
} | ||
}' | ||
__runc exec -d --pid-file pid.txt --process <(echo "$proc") test_scheduler |
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.
Why __runc and not just runc?
runc exec (as well as libcontainer's
container.Run
/container.Start
) has an interesting feature of deriving various process' properties from the runtime spec for container init (theProcess
entry inconfig.json
aka spec).This is mostly implemented via merging
Config
andProcess
properties intoinitConfig
, which happens in libcontainer/container_linux.go, func newInitConfig. Note howinitConfig
fields are taken fromc.config
first (they are there from spec'sProcess
) and then are overwritten by properties of a particular process being run. TheseinitConfig
fields are then used to set up various process attributes.Alas, this functionality (of merging process and config properties) is
This PR is an attempt to improve the situation,