Skip to content

Commit 09da5c9

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 8295a7b commit 09da5c9

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

cmd/nvidia-ctk-installer/container/container.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ type Options struct {
5353
SetAsDefault bool
5454
RestartMode string
5555
HostRootMount string
56+
57+
ConfigSources []string
5658
}
5759

5860
// Configure applies the options to the specified config

cmd/nvidia-ctk-installer/container/runtime/containerd/containerd.go

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

174174
func getRuntimeConfig(o *container.Options, co *Options) (engine.Interface, error) {
175+
var loaders []toml.Loader
176+
for _, configSource := range o.ConfigSources {
177+
switch configSource {
178+
case "file":
179+
loaders = append(loaders, toml.FromFile(o.TopLevelConfigPath))
180+
case "command":
181+
loaders = append(loaders, containerd.CommandLineSource(o.HostRootMount, o.ExecutablePath))
182+
default:
183+
return nil, fmt.Errorf("unsupported config source %q", configSource)
184+
}
185+
}
186+
175187
options := []containerd.Option{
176188
containerd.WithTopLevelConfigPath(o.TopLevelConfigPath),
177189
containerd.WithConfigSource(
178190
toml.LoadFirst(
179-
containerd.CommandLineSource(o.HostRootMount, o.ExecutablePath),
180-
toml.FromFile(o.TopLevelConfigPath),
191+
loaders...,
181192
),
182193
),
183194
containerd.WithRuntimeType(co.runtimeType),

cmd/nvidia-ctk-installer/container/runtime/runtime.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ func Flags(opts *Options) []cli.Flag {
117117
Sources: cli.EnvVars("NVIDIA_RUNTIME_SET_AS_DEFAULT", "CONTAINERD_SET_AS_DEFAULT", "DOCKER_SET_AS_DEFAULT"),
118118
Hidden: true,
119119
},
120+
&cli.StringSliceFlag{
121+
Name: "config-source",
122+
Usage: "specify the config sources",
123+
Destination: &opts.ConfigSources,
124+
Sources: cli.EnvVars("RUNTIME_CONFIG_SOURCES", "RUNTIME_CONFIG_SOURCE"),
125+
},
120126
}
121127

122128
flags = append(flags, containerd.Flags(&opts.containerdOptions)...)
@@ -167,6 +173,9 @@ func (opts *Options) Validate(logger logger.Interface, c *cli.Command, runtime s
167173
if opts.RestartMode == runtimeSpecificDefault {
168174
opts.RestartMode = containerd.DefaultRestartMode
169175
}
176+
if len(opts.ConfigSources) == 0 {
177+
opts.ConfigSources = []string{"command", "file"}
178+
}
170179
case crio.Name:
171180
if opts.TopLevelConfigPath == runtimeSpecificDefault {
172181
opts.TopLevelConfigPath = crio.DefaultConfig

0 commit comments

Comments
 (0)