Skip to content

Commit c51b2ea

Browse files
authored
Merge pull request #1300 from ArangoGutierrez/dropins_ctk_cmd
[no-relnote] add Dropins flag to nvidia-ctk cmd
2 parents e7c1283 + d4ff926 commit c51b2ea

File tree

5 files changed

+688
-17
lines changed

5 files changed

+688
-17
lines changed

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

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,16 @@ const (
4646
defaultCrioConfigFilePath = "/etc/crio/crio.conf"
4747
defaultDockerConfigFilePath = "/etc/docker/daemon.json"
4848

49+
defaultContainerdDropInConfigFilePath = "/etc/containerd/config.d/99-nvidia.toml"
50+
defaultCrioDropInConfigFilePath = "/etc/crio/conf.d/99-nvidia.toml"
51+
4952
defaultConfigSource = configSourceFile
5053
configSourceCommand = "command"
5154
configSourceFile = "file"
55+
56+
// TODO: We may want to spend some time unifying the handling of config
57+
// files here with the Setup-Cleanup logic in nvidia-ctk-installer.
58+
runtimeSpecificDefault = "RUNTIME_SPECIFIC_DEFAULT"
5259
)
5360

5461
type command struct {
@@ -66,13 +73,14 @@ func NewCommand(logger logger.Interface) *cli.Command {
6673
// config defines the options that can be set for the CLI through config files,
6774
// environment variables, or command line config
6875
type config struct {
69-
dryRun bool
70-
runtime string
71-
configFilePath string
72-
executablePath string
73-
configSource string
74-
mode string
75-
hookFilePath string
76+
dryRun bool
77+
runtime string
78+
configFilePath string
79+
dropInConfigPath string
80+
executablePath string
81+
configSource string
82+
mode string
83+
hookFilePath string
7684

7785
nvidiaRuntime struct {
7886
name string
@@ -118,6 +126,12 @@ func (m command) build() *cli.Command {
118126
Usage: "path to the config file for the target runtime",
119127
Destination: &config.configFilePath,
120128
},
129+
&cli.StringFlag{
130+
Name: "drop-in-config",
131+
Usage: "path to the NVIDIA-specific config file to create. When specified, runtime configurations are saved to this file instead of modifying the main config file",
132+
Value: runtimeSpecificDefault,
133+
Destination: &config.dropInConfigPath,
134+
},
121135
&cli.StringFlag{
122136
Name: "executable-path",
123137
Usage: "The path to the runtime executable. This is used to extract the current config",
@@ -241,6 +255,25 @@ func (m command) validateFlags(config *config) error {
241255
}
242256
}
243257

258+
if config.dropInConfigPath == runtimeSpecificDefault {
259+
switch config.runtime {
260+
case "containerd":
261+
config.dropInConfigPath = defaultContainerdDropInConfigFilePath
262+
case "crio":
263+
config.dropInConfigPath = defaultCrioDropInConfigFilePath
264+
case "docker":
265+
config.dropInConfigPath = ""
266+
}
267+
}
268+
269+
if config.dropInConfigPath != "" && config.runtime == "docker" {
270+
return fmt.Errorf("runtime %v does not support drop-in configs", config.runtime)
271+
}
272+
273+
if config.dropInConfigPath != "" && !filepath.IsAbs(config.dropInConfigPath) {
274+
return fmt.Errorf("the drop-in-config path %q is not an absolute path", config.dropInConfigPath)
275+
}
276+
244277
return nil
245278
}
246279

@@ -345,7 +378,10 @@ func (c *config) getCommandConfigSource() toml.Loader {
345378
// getOutputConfigPath returns the configured config path or "" if dry-run is enabled
346379
func (c *config) getOutputConfigPath() string {
347380
if c.dryRun {
348-
return ""
381+
return engine.SaveToSTDOUT
382+
}
383+
if c.dropInConfigPath != "" {
384+
return c.dropInConfigPath
349385
}
350386
return c.configFilePath
351387
}

0 commit comments

Comments
 (0)