Skip to content

Add default --root flag value to help #11711

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

Merged
merged 1 commit into from
May 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions runsc/config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,16 @@ const (
flagOCISeccomp = "oci-seccomp"
flagOverlay2 = "overlay2"
flagAllowFlagOverride = "allow-flag-override"

defaultRootDir = "/var/run/runsc"
xdgRuntimeDirEnvVar = "XDG_RUNTIME_DIR"
)

// RegisterFlags registers flags used to populate Config.
func RegisterFlags(flagSet *flag.FlagSet) {
// Although these flags are not part of the OCI spec, they are used by
// Docker, and thus should not be changed.
flagSet.String("root", "", "root directory for storage of container state.")
flagSet.String("root", "", fmt.Sprintf("root directory for storage of container state, defaults are $%s/runsc, %s.", xdgRuntimeDirEnvVar, defaultRootDir))
flagSet.String("log", "", "file path where internal debug information is written, default is stdout.")
flagSet.String("log-format", "text", "log format: text (default), json, or json-k8s.")
flagSet.Bool(flagDebug, false, "enable debug logging.")
Expand Down Expand Up @@ -252,9 +255,9 @@ func NewFromFlags(flagSet *flag.FlagSet) (*Config, error) {

if len(conf.RootDir) == 0 {
// If not set, set default root dir to something (hopefully) user-writeable.
conf.RootDir = "/var/run/runsc"
conf.RootDir = defaultRootDir
// NOTE: empty values for XDG_RUNTIME_DIR should be ignored.
if runtimeDir := os.Getenv("XDG_RUNTIME_DIR"); runtimeDir != "" {
if runtimeDir := os.Getenv(xdgRuntimeDirEnvVar); runtimeDir != "" {
conf.RootDir = filepath.Join(runtimeDir, "runsc")
}
}
Expand Down