-
Notifications
You must be signed in to change notification settings - Fork 368
Allow update-ldcache hook to work when pivot-root is not supported #1174
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
base: main
Are you sure you want to change the base?
Conversation
Pull Request Test Coverage Report for Build 16070359030Details
💛 - Coveralls |
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.
Pull Request Overview
This PR adds support for containers using --no-pivot
by detecting when pivot_root
is unavailable and falling back to a move-mount (msMoveRoot
) strategy; it also refactors argument parsing and the root mount logic.
- Implement
msMoveRoot
inldconfig_linux.go
and stub it on non-Linux platforms. - Introduce a
--no-pivot
flag,noPivotRoot
detection, and switch in the pivot logic. - Refactor
mountProc
to useSecureJoin
andutils.MkdirAllInRoot
, and streamline handler argument parsing.
Reviewed Changes
Copilot reviewed 6 out of 104 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
internal/ldconfig/ldconfig_other.go | Add msMoveRoot stub for non-Linux builds |
internal/ldconfig/ldconfig_linux.go | Implement msMoveRoot , add mount masking, chroot helper, and noPivotRoot logic; refactor mountProc |
internal/ldconfig/ldconfig.go | Add --no-pivot flag in runner, new NewFromArgs constructor, and use l.directories fields |
go.mod | Add dependencies: github.com/moby/sys/mountinfo , github.com/prometheus/procfs |
cmd/nvidia-cdi-hook/update-ldcache/update-ldcache.go | Replace manual args unpacking with NewFromArgs and simplified call |
cmd/nvidia-cdi-hook/create-soname-symlinks/soname-symlinks.go | Replace manual args unpacking with NewFromArgs and simplified call |
Comments suppressed due to low confidence (3)
internal/ldconfig/ldconfig_linux.go:104
- [nitpick] The doc comment for
msMoveRoot
is incomplete. Consider expanding it to explain what the function does (e.g. "msMoveRoot moves the root filesystem in place when pivot_root isn't available").
// msMoveRoot is used
internal/ldconfig/ldconfig_linux.go:255
- [nitpick] The new
noPivotRoot
detection logic andmsMoveRoot
fallback are not covered by tests. Consider adding unit tests for different rootfs types and the fallback path to ensure behavior across environments.
if err := utils.MkdirAllInRoot(newroot, target, 0755); err != nil {
internal/ldconfig/ldconfig_linux.go:145
- The code references
unix.Mount
,unix.Unmount
, anderrors.Is
without importinggolang.org/x/sys/unix
anderrors
. Add the missing imports to ensure compilation.
if err := unix.Mount("", p, "", unix.MS_SLAVE|unix.MS_REC, ""); err != nil {
internal/ldconfig/ldconfig_linux.go
Outdated
|
||
if err := os.MkdirAll(target, 0755); err != nil { | ||
return fmt.Errorf("error creating directory: %w", err) | ||
target, err := securejoin.SecureJoin(newroot, "/proc") |
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.
Using an absolute path ("/proc"
) with SecureJoin
will discard newroot
. Use a relative subpath like "proc"
to ensure the directory is created under newroot
.
target, err := securejoin.SecureJoin(newroot, "/proc") | |
target, err := securejoin.SecureJoin(newroot, "proc") |
Copilot uses AI. Check for mistakes.
internal/ldconfig/ldconfig.go
Outdated
l := &Ldconfig{ | ||
ldconfigPath: ldconfigPath, | ||
inRoot: inRoot, | ||
// NewFromRunnerArgs creates an Ldconfig struct from the args passed to the Cmd |
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.
// NewFromRunnerArgs creates an Ldconfig struct from the args passed to the Cmd | |
// NewFromArgs creates an Ldconfig struct from the args passed to the cmd |
Or edit func name
This change updates the proc mount when updating ldconfig to use secure join to align with the other functions. Signed-off-by: Evan Lezar <[email protected]>
Signed-off-by: Evan Lezar <[email protected]>
This change updates the update-ldcache logic to use an alternative to pivot-root when this is not supported. This includes cases where the root filesystem is in a ramfs (e.g. when running from the kata-agent). Signed-off-by: Evan Lezar <[email protected]>
Signed-off-by: Evan Lezar <[email protected]>
The changes made to run the update-ldcache hook in an isolated namespace were implemented using a pivot_root. This is, however, not supported in all use cases -- most notably in kata-containers where runc is typically invoked with the --no-pivot option.
This change attempts to detect when pivot_root is not supported and use the same move mount operation as implemented by runc in this case.