mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-04-18 13:15:35 +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
1dbba17455
@ -38,6 +38,11 @@ const (
|
||||
type Options struct {
|
||||
Config 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.
|
||||
EnableCDI bool
|
||||
RuntimeName string
|
||||
|
@ -173,7 +173,7 @@ func getRuntimeConfig(o *container.Options, co *Options) (engine.Interface, erro
|
||||
containerd.WithPath(o.Config),
|
||||
containerd.WithConfigSource(
|
||||
toml.LoadFirst(
|
||||
containerd.CommandLineSource(o.HostRootMount),
|
||||
containerd.CommandLineSource(o.HostRootMount, o.ExecutablePath),
|
||||
toml.FromFile(o.Config),
|
||||
),
|
||||
),
|
||||
|
@ -53,6 +53,11 @@ func Flags(opts *Options) []cli.Flag {
|
||||
Destination: &opts.Config,
|
||||
EnvVars: []string{"RUNTIME_CONFIG", "CONTAINERD_CONFIG", "DOCKER_CONFIG"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "container-runtime-executable-path",
|
||||
Destination: &opts.ExecutablePath,
|
||||
EnvVars: []string{"RUNTIME_EXECUTABLE_PATH"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "socket",
|
||||
Usage: "Path to the runtime socket file",
|
||||
|
@ -68,6 +68,7 @@ type config struct {
|
||||
dryRun bool
|
||||
runtime string
|
||||
configFilePath string
|
||||
executablePath string
|
||||
configSource string
|
||||
mode string
|
||||
hookFilePath string
|
||||
@ -120,6 +121,10 @@ func (m command) build() *cli.Command {
|
||||
Usage: "path to the config file for the target runtime",
|
||||
Destination: &config.configFilePath,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "executable-path",
|
||||
Destination: &config.executablePath,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "config-mode",
|
||||
Usage: "the config mode for runtimes that support multiple configuration mechanisms",
|
||||
@ -330,7 +335,7 @@ func (c *config) resolveConfigSource() (toml.Loader, error) {
|
||||
func (c *config) getCommandConfigSource() toml.Loader {
|
||||
switch c.runtime {
|
||||
case "containerd":
|
||||
return containerd.CommandLineSource("")
|
||||
return containerd.CommandLineSource("", c.executablePath)
|
||||
case "crio":
|
||||
return crio.CommandLineSource("")
|
||||
}
|
||||
|
@ -162,8 +162,11 @@ func (c *Config) GetRuntimeConfig(name string) (engine.RuntimeConfig, error) {
|
||||
}
|
||||
|
||||
// CommandLineSource returns the CLI-based containerd config loader
|
||||
func CommandLineSource(hostRoot string) toml.Loader {
|
||||
return toml.FromCommandLine(chrootIfRequired(hostRoot, "containerd", "config", "dump")...)
|
||||
func CommandLineSource(hostRoot string, executablePath string) toml.Loader {
|
||||
if executablePath == "" {
|
||||
executablePath = "containerd"
|
||||
}
|
||||
return toml.FromCommandLine(chrootIfRequired(hostRoot, executablePath, "config", "dump")...)
|
||||
}
|
||||
|
||||
func chrootIfRequired(hostRoot string, commandLine ...string) []string {
|
||||
|
Loading…
Reference in New Issue
Block a user