mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-04-07 14:04:05 +00:00
Allow container runtime executable path to be specified
This change adds support for specifying the container runtime executable path. This can be used if, for example, there are two containerd executables and a specific one must be used. Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
7833723be1
commit
3a13747e10
@ -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
|
||||||
|
@ -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),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -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:
|
||||||
|
@ -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
|
||||||
|
@ -68,6 +68,7 @@ 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
|
||||||
@ -120,6 +121,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,6 +214,11 @@ func (m command) validateFlags(c *cli.Context, config *config) error {
|
|||||||
config.cdi.enabled = false
|
config.cdi.enabled = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.executablePath != "" && config.runtime != "containerd" {
|
||||||
|
m.logger.Warningf("Ignoring executable-path=%q flag for %v", config.executablePath, config.runtime)
|
||||||
|
config.executablePath = ""
|
||||||
|
}
|
||||||
|
|
||||||
if config.runtimeConfigOverrideJSON != "" && config.runtime != "containerd" {
|
if config.runtimeConfigOverrideJSON != "" && config.runtime != "containerd" {
|
||||||
m.logger.Warningf("Ignoring runtime-config-override flag for %v", config.runtime)
|
m.logger.Warningf("Ignoring runtime-config-override flag for %v", config.runtime)
|
||||||
config.runtimeConfigOverrideJSON = ""
|
config.runtimeConfigOverrideJSON = ""
|
||||||
@ -330,7 +341,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("")
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user