Skip to content

Commit b426551

Browse files
committed
Allow file for config source to be specified explicitly
This change allows a "file" config source to also specify the source path of the file to process. This means that when configuring containerd with the option --config-source=file=/foo/bar.toml the file /foo/bar.toml will be used as the source config instead of the output config file. Signed-off-by: Evan Lezar <[email protected]>
1 parent 7f12113 commit b426551

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"os"
2323
"os/exec"
24+
"strings"
2425

2526
"github.com/sirupsen/logrus"
2627

@@ -197,14 +198,26 @@ func (o Options) GetConfigLoaders(commandSourceFunc func(string, string) toml.Lo
197198
}
198199
var loaders []toml.Loader
199200
for _, configSource := range o.ConfigSources {
200-
switch configSource {
201+
parts := strings.SplitN(configSource, "=", 2)
202+
source := parts[0]
203+
switch source {
201204
case "file":
202-
loaders = append(loaders, toml.FromFile(o.TopLevelConfigPath))
205+
fileSourcePath := o.TopLevelConfigPath
206+
if len(parts) > 1 {
207+
fileSourcePath = parts[1]
208+
}
209+
loaders = append(loaders, toml.FromFile(fileSourcePath))
203210
case "command":
211+
if commandSourceFunc == nil {
212+
logrus.Warnf("Ignoring command config source")
213+
}
214+
if len(parts) > 1 {
215+
logrus.Warnf("Ignoring additional command argument %q", parts[1])
216+
}
204217
loaders = append(loaders, commandSourceFunc(o.HostRootMount, o.ExecutablePath))
205218
default:
206219
return nil, fmt.Errorf("unsupported config source %q", configSource)
207220
}
208221
}
209-
return loaders, nil
222+
210223
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,12 @@ func Flags(opts *Options) []cli.Flag {
118118
Hidden: true,
119119
},
120120
&cli.StringSliceFlag{
121-
Name: "config-source",
122-
Aliases: []string{"config-sources"},
123-
Usage: "Specify the config sources for the container runtime. Any combination of [command | file].",
121+
Name: "config-source",
122+
Aliases: []string{"config-sources"},
123+
Usage: "Specify the config sources for the container runtime. Any combination of " +
124+
"[command | file]. " +
125+
"When `file` is specifed, the absolute path to the file to be used as a config source can " +
126+
"be specified as `file=/path/to/source/config.toml",
124127
Value: []string{"command", "file"},
125128
Destination: &opts.ConfigSources,
126129
Sources: cli.EnvVars("RUNTIME_CONFIG_SOURCES", "RUNTIME_CONFIG_SOURCE"),

0 commit comments

Comments
 (0)