diff --git a/tools/container/container.go b/tools/container/container.go index ce0dd8ec6..d214c3720 100644 --- a/tools/container/container.go +++ b/tools/container/container.go @@ -50,6 +50,8 @@ type Options struct { SetAsDefault bool RestartMode string HostRootMount string + + ConfigSources cli.StringSlice } // ParseArgs parses the command line arguments to the CLI diff --git a/tools/container/runtime/containerd/containerd.go b/tools/container/runtime/containerd/containerd.go index 528c7f4f8..7be95cc02 100644 --- a/tools/container/runtime/containerd/containerd.go +++ b/tools/container/runtime/containerd/containerd.go @@ -169,12 +169,23 @@ func GetLowlevelRuntimePaths(o *container.Options, co *Options) ([]string, error } func getRuntimeConfig(o *container.Options, co *Options) (engine.Interface, error) { + var loaders []toml.Loader + for _, source := range o.ConfigSources.Value() { + switch source { + case "file": + loaders = append(loaders, toml.FromFile(o.Config)) + case "command": + loaders = append(loaders, containerd.CommandLineSource(o.HostRootMount, o.ExecutablePath)) + default: + // TODO: log a warning here. + } + } + return containerd.New( containerd.WithPath(o.Config), containerd.WithConfigSource( toml.LoadFirst( - containerd.CommandLineSource(o.HostRootMount, o.ExecutablePath), - toml.FromFile(o.Config), + loaders..., ), ), containerd.WithRuntimeType(co.runtimeType), diff --git a/tools/container/runtime/runtime.go b/tools/container/runtime/runtime.go index 0042938c2..1490e9f86 100644 --- a/tools/container/runtime/runtime.go +++ b/tools/container/runtime/runtime.go @@ -103,6 +103,12 @@ func Flags(opts *Options) []cli.Flag { EnvVars: []string{"NVIDIA_RUNTIME_SET_AS_DEFAULT", "CONTAINERD_SET_AS_DEFAULT", "DOCKER_SET_AS_DEFAULT"}, Hidden: true, }, + &cli.StringSliceFlag{ + Name: "config-source", + Usage: "specify the config sources", + Destination: &opts.ConfigSources, + EnvVars: []string{"RUNTIME_CONFIG_SOURCES"}, + }, } flags = append(flags, containerd.Flags(&opts.containerdOptions)...) @@ -137,6 +143,9 @@ func (opts *Options) Validate(c *cli.Context, runtime string, toolkitRoot string if opts.RestartMode == runtimeSpecificDefault { opts.RestartMode = containerd.DefaultRestartMode } + if len(opts.ConfigSources.Value()) == 0 { + _ = opts.ConfigSources.Set("command,file") + } case crio.Name: if opts.Config == runtimeSpecificDefault { opts.Config = crio.DefaultConfig