Skip to content

Commit 6f0ffa7

Browse files
committed
Set config file path when running containerd config dump
Signed-off-by: Christopher Desiniotis <[email protected]>
1 parent be415a8 commit 6f0ffa7

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ type Options struct {
3939
DropInConfig string
4040
DropInConfigHostPath string
4141
// TopLevelConfigPath stores the path to the top-level config for the runtime.
42-
TopLevelConfigPath string
43-
Socket string
42+
TopLevelConfigPath string
43+
TopLevelConfigPathHostPath string
44+
Socket string
4445
// ExecutablePath specifies the path to the container runtime executable.
4546
// This is used to extract the current config, for example.
4647
// If a HostRootMount is specified, this path is relative to the host root

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func getRuntimeConfig(o *container.Options, co *Options) (engine.Interface, erro
176176
containerd.WithTopLevelConfigPath(o.TopLevelConfigPath),
177177
containerd.WithConfigSource(
178178
toml.LoadFirst(
179-
containerd.CommandLineSource(o.HostRootMount, o.ExecutablePath),
179+
containerd.CommandLineSource(o.HostRootMount, o.ExecutablePath, o.TopLevelConfigPath),
180180
toml.FromFile(o.TopLevelConfigPath),
181181
),
182182
),

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ func Flags(opts *Options) []cli.Flag {
5454
Destination: &opts.TopLevelConfigPath,
5555
Sources: cli.EnvVars("RUNTIME_CONFIG", "CONTAINERD_CONFIG", "DOCKER_CONFIG"),
5656
},
57+
&cli.StringFlag{
58+
Name: "config-host-path",
59+
Usage: "When running in a container, this is the path to the runtime config file (--config) on the host. " +
60+
"This is used to extract the current config.",
61+
Destination: &opts.TopLevelConfigPathHostPath,
62+
Sources: cli.EnvVars("RUNTIME_CONFIG_HOST_PATH"),
63+
},
5764
&cli.StringFlag{
5865
Name: "drop-in-config",
5966
Usage: "Path to the NVIDIA-specific drop-in config file",

cmd/nvidia-ctk/runtime/configure/configure.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ func (c *config) resolveConfigSource() (toml.Loader, error) {
368368
func (c *config) getCommandConfigSource() toml.Loader {
369369
switch c.runtime {
370370
case "containerd":
371-
return containerd.CommandLineSource("", c.executablePath)
371+
return containerd.CommandLineSource("", c.executablePath, c.configFilePath)
372372
case "crio":
373373
return crio.CommandLineSource("", c.executablePath)
374374
}

pkg/config/engine/containerd/containerd.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,18 @@ func (c *Config) GetRuntimeConfig(name string) (engine.RuntimeConfig, error) {
195195
}
196196

197197
// CommandLineSource returns the CLI-based containerd config loader
198-
func CommandLineSource(hostRoot string, executablePath string) toml.Loader {
198+
func CommandLineSource(hostRoot string, executablePath string, topLevelConfig string) toml.Loader {
199199
if executablePath == "" {
200200
executablePath = "containerd"
201201
}
202-
return toml.FromCommandLine(chrootIfRequired(hostRoot, executablePath, "config", "dump")...)
202+
203+
var commandLine []string
204+
if topLevelConfig != "" {
205+
commandLine = []string{executablePath, "--config", topLevelConfig, "config", "dump")}
206+
} else {
207+
commandLine = []string{executablePath, "config", "dump"}
208+
}
209+
return toml.FromCommandLine(chrootIfRequired(hostRoot, commandLine...)...)
203210
}
204211

205212
func chrootIfRequired(hostRoot string, commandLine ...string) []string {

0 commit comments

Comments
 (0)