Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 44 additions & 8 deletions cmd/nvidia-ctk/runtime/configure/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,16 @@ const (
defaultCrioConfigFilePath = "/etc/crio/crio.conf"
defaultDockerConfigFilePath = "/etc/docker/daemon.json"

defaultContainerdDropInConfigFilePath = "/etc/containerd/config.d/99-nvidia.toml"
defaultCrioDropInConfigFilePath = "/etc/crio/conf.d/99-nvidia.toml"

defaultConfigSource = configSourceFile
configSourceCommand = "command"
configSourceFile = "file"

// TODO: We may want to spend some time unifying the handling of config
// files here with the Setup-Cleanup logic in nvidia-ctk-installer.
runtimeSpecificDefault = "RUNTIME_SPECIFIC_DEFAULT"
)

type command struct {
Expand All @@ -66,13 +73,14 @@ func NewCommand(logger logger.Interface) *cli.Command {
// config defines the options that can be set for the CLI through config files,
// environment variables, or command line config
type config struct {
dryRun bool
runtime string
configFilePath string
executablePath string
configSource string
mode string
hookFilePath string
dryRun bool
runtime string
configFilePath string
dropInConfigPath string
executablePath string
configSource string
mode string
hookFilePath string

nvidiaRuntime struct {
name string
Expand Down Expand Up @@ -118,6 +126,12 @@ func (m command) build() *cli.Command {
Usage: "path to the config file for the target runtime",
Destination: &config.configFilePath,
},
&cli.StringFlag{
Name: "drop-in-config",
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",
Value: runtimeSpecificDefault,
Destination: &config.dropInConfigPath,
},
&cli.StringFlag{
Name: "executable-path",
Usage: "The path to the runtime executable. This is used to extract the current config",
Expand Down Expand Up @@ -241,6 +255,25 @@ func (m command) validateFlags(config *config) error {
}
}

if config.dropInConfigPath == runtimeSpecificDefault {
switch config.runtime {
case "containerd":
config.dropInConfigPath = defaultContainerdDropInConfigFilePath
case "crio":
config.dropInConfigPath = defaultCrioDropInConfigFilePath
case "docker":
config.dropInConfigPath = ""
}
}

if config.dropInConfigPath != "" && config.runtime == "docker" {
return fmt.Errorf("runtime %v does not support drop-in configs", config.runtime)
}

if config.dropInConfigPath != "" && !filepath.IsAbs(config.dropInConfigPath) {
return fmt.Errorf("the drop-in-config path %q is not an absolute path", config.dropInConfigPath)
}

return nil
}

Expand Down Expand Up @@ -345,7 +378,10 @@ func (c *config) getCommandConfigSource() toml.Loader {
// getOutputConfigPath returns the configured config path or "" if dry-run is enabled
func (c *config) getOutputConfigPath() string {
if c.dryRun {
return ""
return engine.SaveToSTDOUT
}
if c.dropInConfigPath != "" {
return c.dropInConfigPath
}
return c.configFilePath
}
Expand Down
Loading