-
Notifications
You must be signed in to change notification settings - Fork 763
defaults: use user-writable data root on darwin #4842
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably (most of) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,11 +16,17 @@ | |
|
|
||
| // This is a dummy file to allow usage of library functions | ||
| // on Darwin-based systems. | ||
| // All functions and variables are empty/no-ops | ||
| // Most functions and variables are stubs/no-ops | ||
|
|
||
| package defaults | ||
|
|
||
| import gocni "github.com/containerd/go-cni" | ||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
|
|
||
| gocni "github.com/containerd/go-cni" | ||
| ) | ||
|
|
||
| const ( | ||
| AppArmorProfileName = "" | ||
|
|
@@ -33,15 +39,24 @@ func CNIPath() string { | |
| } | ||
|
|
||
| func CNIRuntimeDir() (string, error) { | ||
| if os.Geteuid() != 0 { | ||
| return filepath.Join(xdgRuntimeDir(), "cni"), nil | ||
| } | ||
| return "/var/run/cni", nil | ||
| } | ||
|
|
||
| func CNINetConfPath() string { | ||
| if os.Geteuid() != 0 { | ||
| return filepath.Join(xdgConfigHome(), "cni", "net.d") | ||
| } | ||
| return gocni.DefaultNetDir | ||
| } | ||
|
|
||
| func DataRoot() string { | ||
| return "/var/lib/nerdctl" | ||
| if os.Geteuid() == 0 { | ||
| return "/var/lib/nerdctl" | ||
| } | ||
| return filepath.Join(xdgDataHome(), "nerdctl") | ||
| } | ||
|
|
||
| func CgroupManager() string { | ||
|
|
@@ -53,17 +68,66 @@ func CgroupnsMode() string { | |
| } | ||
|
|
||
| func NerdctlTOML() string { | ||
| if os.Geteuid() != 0 { | ||
| return filepath.Join(xdgConfigHome(), "nerdctl", "nerdctl.toml") | ||
| } | ||
| return "/etc/nerdctl/nerdctl.toml" | ||
| } | ||
|
|
||
| func HostsDirs() []string { | ||
| return []string{} | ||
| if os.Geteuid() != 0 { | ||
| xch := xdgConfigHome() | ||
| return []string{ | ||
| filepath.Join(xch, "containerd", "certs.d"), | ||
| filepath.Join(xch, "docker", "certs.d"), | ||
| } | ||
| } | ||
| return []string{"/etc/containerd/certs.d", "/etc/docker/certs.d"} | ||
| } | ||
|
|
||
| func HostGatewayIP() string { | ||
| return "" | ||
| } | ||
|
|
||
| func CDISpecDirs() []string { | ||
| if os.Geteuid() != 0 { | ||
| return []string{ | ||
| filepath.Join(xdgConfigHome(), "cdi"), | ||
| filepath.Join(xdgRuntimeDir(), "cdi"), | ||
| } | ||
| } | ||
| return []string{"/etc/cdi", "/var/run/cdi"} | ||
| } | ||
|
|
||
| func xdgConfigHome() string { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicated code: https://github.com/containerd/nerdctl/blob/main/pkg/rootlessutil/xdg_linux.go Should be consolidated to a single package (but not a single file). |
||
| if xch := os.Getenv("XDG_CONFIG_HOME"); xch != "" { | ||
| return xch | ||
| } | ||
| if home := os.Getenv("HOME"); home != "" { | ||
| return filepath.Join(home, ".config") | ||
| } | ||
| if home, err := os.UserHomeDir(); err == nil && home != "" { | ||
| return filepath.Join(home, ".config") | ||
| } | ||
| return "/etc" | ||
| } | ||
|
|
||
| func xdgDataHome() string { | ||
| if xdh := os.Getenv("XDG_DATA_HOME"); xdh != "" { | ||
| return xdh | ||
| } | ||
| if home := os.Getenv("HOME"); home != "" { | ||
| return filepath.Join(home, ".local", "share") | ||
| } | ||
| if home, err := os.UserHomeDir(); err == nil && home != "" { | ||
| return filepath.Join(home, ".local", "share") | ||
| } | ||
| return "/var/lib" | ||
| } | ||
|
|
||
| func xdgRuntimeDir() string { | ||
| if xdr := os.Getenv("XDG_RUNTIME_DIR"); xdr != "" { | ||
| return xdr | ||
| } | ||
| return fmt.Sprintf("/run/user/%d", os.Geteuid()) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inexistent on macOS |
||
| } | ||
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.
All the paths should be handled consistently, not just
DataRootThere 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.
Fixed in a5cdb0d. I applied the same root/non-root + XDG convention consistently to DataRoot, CNINetConfPath, CNIRuntimeDir, NerdctlTOML, HostsDirs, and CDISpecDirs.