Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion cmd/urunc/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ var createCommand = &cli.Command{
return err
}
if !cmd.Bool("reexec") {
uruncCfg, _ := unikontainers.LoadUruncConfig(unikontainers.UruncConfigPath) // ignore the error and use default config
uruncCfg, _ := unikontainers.LoadUruncConfig(unikontainers.ResolveUruncConfigPath()) // ignore the error and use default config
return createUnikontainer(cmd, uruncCfg)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/urunc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func main() {
return nil, err
}
// ignore error since ParseLogMetricsConfig will print a warning and return default values
cfg, _ := unikontainers.ParseLogMetricsConfig(unikontainers.UruncConfigPath)
cfg, _ := unikontainers.ParseLogMetricsConfig(unikontainers.ResolveUruncConfigPath())
err := configLogrus(cmd, cfg.Log)
if err != nil {
return nil, err
Expand Down
11 changes: 10 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@

## Configuration File Location

`urunc` looks for its configuration file at `/etc/urunc/config.toml`. If the file doesn't exist or contains invalid configuration, `urunc` will use sensible defaults and continue to operate normally.
`urunc` looks for its configuration file at `/etc/urunc/config.toml` by default. The location can be overridden with the `URUNC_CONFIG_FILE` environment variable, for example `URUNC_CONFIG_FILE=/var/etc/urunc/config.toml`. If the file doesn't exist or contains invalid configuration, `urunc` will use sensible defaults and continue to operate normally.

One way to set the variable is to replace the `containerd-shim-urunc-v2` binary that containerd invokes with a small wrapper script that sets it and execs the real shim. For example, move the real shim aside (e.g. to `containerd-shim-urunc-v2.real`) and save the following as `/usr/local/bin/containerd-shim-urunc-v2`:

```bash
#!/bin/bash
URUNC_CONFIG_FILE=/some/path/config.toml exec /usr/local/bin/containerd-shim-urunc-v2.real "$@"
```

where `/some/path/config.toml` is the configuration file to use and `/usr/local/bin/containerd-shim-urunc-v2.real` is the actual shim binary.

Comment thread
Anand-240 marked this conversation as resolved.
## Configuration File Format

Expand Down
2 changes: 1 addition & 1 deletion pkg/containerd-shim/guest_rootfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func chooseGuestRootfs(r *taskAPI.CreateTaskRequest) error {
}

annotations := config.Map()
uruncCfg, err := unikontainers.LoadUruncConfig(unikontainers.UruncConfigPath)
uruncCfg, err := unikontainers.LoadUruncConfig(unikontainers.ResolveUruncConfigPath())
if err != nil && uruncCfg == nil {
return err
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/unikontainers/urunc_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package unikontainers

import (
"os"
"strconv"
"strings"

Expand All @@ -24,6 +25,20 @@ import (

const UruncConfigPath = "/etc/urunc/config.toml"

// UruncConfigFileEnv is the environment variable that overrides the default
// location of the urunc configuration file.
const UruncConfigFileEnv = "URUNC_CONFIG_FILE"

// ResolveUruncConfigPath returns the path to the urunc configuration file. It
// uses the URUNC_CONFIG_FILE environment variable when it is set and falls back
// to UruncConfigPath (/etc/urunc/config.toml) otherwise.
func ResolveUruncConfigPath() string {
if path := os.Getenv(UruncConfigFileEnv); path != "" {
return path
}
return UruncConfigPath
}

type UruncLog struct {
Level string `toml:"level"`
Syslog bool `toml:"syslog"`
Expand Down
14 changes: 14 additions & 0 deletions pkg/unikontainers/urunc_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,3 +618,17 @@ path = "/usr/bin/mon"
assert.Equal(t, defaultMonitorsConfig(), config.Monitors)
})
}

// Note: these tests use t.Setenv and therefore must not call t.Parallel().
func TestResolveUruncConfigPath(t *testing.T) {
t.Run("env var unset returns default path", func(t *testing.T) {
t.Setenv(UruncConfigFileEnv, "")
assert.Equal(t, UruncConfigPath, ResolveUruncConfigPath())
})

t.Run("env var set overrides the path", func(t *testing.T) {
customPath := "/var/etc/urunc/config.toml"
t.Setenv(UruncConfigFileEnv, customPath)
assert.Equal(t, customPath, ResolveUruncConfigPath())
})
}
Loading