Skip to content

Commit 8334dde

Browse files
committed
Allow config sources to be specified for containerd
By default container extracts the current config by running the `containerd config dump` command and if that fails we read the existing config file. This change allows ordering of these sources to be defined as we do for the nvidia-ctk runtime configure command. Signed-off-by: Evan Lezar <[email protected]>
1 parent 5e8c141 commit 8334dde

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

tools/container/container.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ type Options struct {
5050
SetAsDefault bool
5151
RestartMode string
5252
HostRootMount string
53+
54+
ConfigSources cli.StringSlice
5355
}
5456

5557
// ParseArgs parses the command line arguments to the CLI

tools/container/runtime/containerd/containerd.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,23 @@ func GetLowlevelRuntimePaths(o *container.Options, co *Options) ([]string, error
169169
}
170170

171171
func getRuntimeConfig(o *container.Options, co *Options) (engine.Interface, error) {
172+
var loaders []toml.Loader
173+
for _, source := range o.ConfigSources.Value() {
174+
switch source {
175+
case "file":
176+
loaders = append(loaders, toml.FromFile(o.Config))
177+
case "command":
178+
loaders = append(loaders, containerd.CommandLineSource(o.HostRootMount, o.ExecutablePath))
179+
default:
180+
// TODO: log a warning here.
181+
}
182+
}
183+
172184
return containerd.New(
173185
containerd.WithPath(o.Config),
174186
containerd.WithConfigSource(
175187
toml.LoadFirst(
176-
containerd.CommandLineSource(o.HostRootMount, o.ExecutablePath),
177-
toml.FromFile(o.Config),
188+
loaders...,
178189
),
179190
),
180191
containerd.WithRuntimeType(co.runtimeType),

tools/container/runtime/runtime.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ func Flags(opts *Options) []cli.Flag {
103103
EnvVars: []string{"NVIDIA_RUNTIME_SET_AS_DEFAULT", "CONTAINERD_SET_AS_DEFAULT", "DOCKER_SET_AS_DEFAULT"},
104104
Hidden: true,
105105
},
106+
&cli.StringSliceFlag{
107+
Name: "config-source",
108+
Usage: "specify the config sources",
109+
Destination: &opts.ConfigSources,
110+
EnvVars: []string{"RUNTIME_CONFIG_SOURCES"},
111+
},
106112
}
107113

108114
flags = append(flags, containerd.Flags(&opts.containerdOptions)...)
@@ -137,6 +143,9 @@ func (opts *Options) Validate(c *cli.Context, runtime string, toolkitRoot string
137143
if opts.RestartMode == runtimeSpecificDefault {
138144
opts.RestartMode = containerd.DefaultRestartMode
139145
}
146+
if len(opts.ConfigSources.Value()) == 0 {
147+
_ = opts.ConfigSources.Set("command,file")
148+
}
140149
case crio.Name:
141150
if opts.Config == runtimeSpecificDefault {
142151
opts.Config = crio.DefaultConfig

0 commit comments

Comments
 (0)