This commit is contained in:
Evan Lezar 2025-04-03 07:18:53 +00:00 committed by GitHub
commit 35c0846695
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 36 additions and 12 deletions

View File

@ -38,6 +38,11 @@ const (
type Options struct { type Options struct {
Config string Config string
Socket string Socket string
// ExecutablePath specifies the path to the container runtime executable.
// This is used to extract the current config, for example.
// If a HostRootMount is specified, this path is relative to the host root
// mount.
ExecutablePath string
// EnabledCDI indicates whether CDI should be enabled. // EnabledCDI indicates whether CDI should be enabled.
EnableCDI bool EnableCDI bool
RuntimeName string RuntimeName string

View File

@ -173,7 +173,7 @@ func getRuntimeConfig(o *container.Options, co *Options) (engine.Interface, erro
containerd.WithPath(o.Config), containerd.WithPath(o.Config),
containerd.WithConfigSource( containerd.WithConfigSource(
toml.LoadFirst( toml.LoadFirst(
containerd.CommandLineSource(o.HostRootMount), containerd.CommandLineSource(o.HostRootMount, o.ExecutablePath),
toml.FromFile(o.Config), toml.FromFile(o.Config),
), ),
), ),

View File

@ -26,6 +26,7 @@ import (
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk-installer/container/runtime/crio" "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk-installer/container/runtime/crio"
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk-installer/container/runtime/docker" "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk-installer/container/runtime/docker"
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk-installer/container/toolkit" "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk-installer/container/toolkit"
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
) )
const ( const (
@ -53,6 +54,12 @@ func Flags(opts *Options) []cli.Flag {
Destination: &opts.Config, Destination: &opts.Config,
EnvVars: []string{"RUNTIME_CONFIG", "CONTAINERD_CONFIG", "DOCKER_CONFIG"}, EnvVars: []string{"RUNTIME_CONFIG", "CONTAINERD_CONFIG", "DOCKER_CONFIG"},
}, },
&cli.StringFlag{
Name: "executable-path",
Usage: "The path to the runtime executable. This is used to extract the current config",
Destination: &opts.ExecutablePath,
EnvVars: []string{"RUNTIME_EXECUTABLE_PATH"},
},
&cli.StringFlag{ &cli.StringFlag{
Name: "socket", Name: "socket",
Usage: "Path to the runtime socket file", Usage: "Path to the runtime socket file",
@ -104,8 +111,8 @@ func Flags(opts *Options) []cli.Flag {
return flags return flags
} }
// ValidateOptions checks whether the specified options are valid // Validate checks whether the specified options are valid
func ValidateOptions(c *cli.Context, opts *Options, runtime string, toolkitRoot string, to *toolkit.Options) error { func (opts *Options) Validate(logger logger.Interface, c *cli.Context, runtime string, toolkitRoot string, to *toolkit.Options) error {
// We set this option here to ensure that it is available in future calls. // We set this option here to ensure that it is available in future calls.
opts.RuntimeDir = toolkitRoot opts.RuntimeDir = toolkitRoot
@ -113,6 +120,11 @@ func ValidateOptions(c *cli.Context, opts *Options, runtime string, toolkitRoot
opts.EnableCDI = to.CDI.Enabled opts.EnableCDI = to.CDI.Enabled
} }
if opts.ExecutablePath != "" && opts.RuntimeName != containerd.Name {
logger.Warningf("Ignoring executable-path=%q flag for %v", opts.ExecutablePath, opts.RuntimeName)
opts.ExecutablePath = ""
}
// Apply the runtime-specific config changes. // Apply the runtime-specific config changes.
switch runtime { switch runtime {
case containerd.Name: case containerd.Name:

View File

@ -167,7 +167,7 @@ func (a *app) validateFlags(c *cli.Context, o *options) error {
if err := a.toolkit.ValidateOptions(&o.toolkitOptions); err != nil { if err := a.toolkit.ValidateOptions(&o.toolkitOptions); err != nil {
return err return err
} }
if err := runtime.ValidateOptions(c, &o.runtimeOptions, o.runtime, o.toolkitRoot(), &o.toolkitOptions); err != nil { if err := o.runtimeOptions.Validate(a.logger, c, o.runtime, o.toolkitRoot(), &o.toolkitOptions); err != nil {
return err return err
} }
return nil return nil

View File

@ -68,12 +68,11 @@ type config struct {
dryRun bool dryRun bool
runtime string runtime string
configFilePath string configFilePath string
executablePath string
configSource string configSource string
mode string mode string
hookFilePath string hookFilePath string
runtimeConfigOverrideJSON string
nvidiaRuntime struct { nvidiaRuntime struct {
name string name string
path string path string
@ -120,6 +119,11 @@ func (m command) build() *cli.Command {
Usage: "path to the config file for the target runtime", Usage: "path to the config file for the target runtime",
Destination: &config.configFilePath, Destination: &config.configFilePath,
}, },
&cli.StringFlag{
Name: "executable-path",
Usage: "The path to the runtime executable. This is used to extract the current config",
Destination: &config.executablePath,
},
&cli.StringFlag{ &cli.StringFlag{
Name: "config-mode", Name: "config-mode",
Usage: "the config mode for runtimes that support multiple configuration mechanisms", Usage: "the config mode for runtimes that support multiple configuration mechanisms",
@ -208,9 +212,9 @@ func (m command) validateFlags(c *cli.Context, config *config) error {
config.cdi.enabled = false config.cdi.enabled = false
} }
if config.runtimeConfigOverrideJSON != "" && config.runtime != "containerd" { if config.executablePath != "" && config.runtime != "containerd" {
m.logger.Warningf("Ignoring runtime-config-override flag for %v", config.runtime) m.logger.Warningf("Ignoring executable-path=%q flag for %v", config.executablePath, config.runtime)
config.runtimeConfigOverrideJSON = "" config.executablePath = ""
} }
switch config.configSource { switch config.configSource {
@ -330,7 +334,7 @@ func (c *config) resolveConfigSource() (toml.Loader, error) {
func (c *config) getCommandConfigSource() toml.Loader { func (c *config) getCommandConfigSource() toml.Loader {
switch c.runtime { switch c.runtime {
case "containerd": case "containerd":
return containerd.CommandLineSource("") return containerd.CommandLineSource("", c.executablePath)
case "crio": case "crio":
return crio.CommandLineSource("") return crio.CommandLineSource("")
} }

View File

@ -162,8 +162,11 @@ func (c *Config) GetRuntimeConfig(name string) (engine.RuntimeConfig, error) {
} }
// CommandLineSource returns the CLI-based containerd config loader // CommandLineSource returns the CLI-based containerd config loader
func CommandLineSource(hostRoot string) toml.Loader { func CommandLineSource(hostRoot string, executablePath string) toml.Loader {
return toml.FromCommandLine(chrootIfRequired(hostRoot, "containerd", "config", "dump")...) if executablePath == "" {
executablePath = "containerd"
}
return toml.FromCommandLine(chrootIfRequired(hostRoot, executablePath, "config", "dump")...)
} }
func chrootIfRequired(hostRoot string, commandLine ...string) []string { func chrootIfRequired(hostRoot string, commandLine ...string) []string {