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:
Evan Lezar 2025-04-02 17:56:46 +02:00
parent 7833723be1
commit 1dbba17455
No known key found for this signature in database
5 changed files with 22 additions and 4 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

@ -53,6 +53,11 @@ 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: "container-runtime-executable-path",
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",

View File

@ -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,10 @@ 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",
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",
@ -330,7 +335,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 {