From 1dbba17455a578640cef88260c341862a3c2163c Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Wed, 2 Apr 2025 17:56:46 +0200 Subject: [PATCH] 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 --- cmd/nvidia-ctk-installer/container/container.go | 5 +++++ .../container/runtime/containerd/containerd.go | 2 +- cmd/nvidia-ctk-installer/container/runtime/runtime.go | 5 +++++ cmd/nvidia-ctk/runtime/configure/configure.go | 7 ++++++- pkg/config/engine/containerd/containerd.go | 7 +++++-- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/cmd/nvidia-ctk-installer/container/container.go b/cmd/nvidia-ctk-installer/container/container.go index 5e838608..f8184a42 100644 --- a/cmd/nvidia-ctk-installer/container/container.go +++ b/cmd/nvidia-ctk-installer/container/container.go @@ -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 diff --git a/cmd/nvidia-ctk-installer/container/runtime/containerd/containerd.go b/cmd/nvidia-ctk-installer/container/runtime/containerd/containerd.go index 9ece5306..e6eb835a 100644 --- a/cmd/nvidia-ctk-installer/container/runtime/containerd/containerd.go +++ b/cmd/nvidia-ctk-installer/container/runtime/containerd/containerd.go @@ -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), ), ), diff --git a/cmd/nvidia-ctk-installer/container/runtime/runtime.go b/cmd/nvidia-ctk-installer/container/runtime/runtime.go index 2920262c..37483be7 100644 --- a/cmd/nvidia-ctk-installer/container/runtime/runtime.go +++ b/cmd/nvidia-ctk-installer/container/runtime/runtime.go @@ -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", diff --git a/cmd/nvidia-ctk/runtime/configure/configure.go b/cmd/nvidia-ctk/runtime/configure/configure.go index aa8a496c..b0c8fcee 100644 --- a/cmd/nvidia-ctk/runtime/configure/configure.go +++ b/cmd/nvidia-ctk/runtime/configure/configure.go @@ -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("") } diff --git a/pkg/config/engine/containerd/containerd.go b/pkg/config/engine/containerd/containerd.go index 8c41e947..ca35c75d 100644 --- a/pkg/config/engine/containerd/containerd.go +++ b/pkg/config/engine/containerd/containerd.go @@ -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 {