Skip to content

Commit 58f54b9

Browse files
authored
Merge pull request #1029 from elezar/allow-runtime-path
Allow container runtime executable path to be specified
2 parents c4f46e7 + 8176ac4 commit 58f54b9

File tree

8 files changed

+43
-16
lines changed

8 files changed

+43
-16
lines changed

cmd/nvidia-ctk/runtime/configure/configure.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,11 @@ type config struct {
6868
dryRun bool
6969
runtime string
7070
configFilePath string
71+
executablePath string
7172
configSource string
7273
mode string
7374
hookFilePath string
7475

75-
runtimeConfigOverrideJSON string
76-
7776
nvidiaRuntime struct {
7877
name string
7978
path string
@@ -120,6 +119,11 @@ func (m command) build() *cli.Command {
120119
Usage: "path to the config file for the target runtime",
121120
Destination: &config.configFilePath,
122121
},
122+
&cli.StringFlag{
123+
Name: "executable-path",
124+
Usage: "The path to the runtime executable. This is used to extract the current config",
125+
Destination: &config.executablePath,
126+
},
123127
&cli.StringFlag{
124128
Name: "config-mode",
125129
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 {
208212
config.cdi.enabled = false
209213
}
210214

211-
if config.runtimeConfigOverrideJSON != "" && config.runtime != "containerd" {
212-
m.logger.Warningf("Ignoring runtime-config-override flag for %v", config.runtime)
213-
config.runtimeConfigOverrideJSON = ""
215+
if config.executablePath != "" && config.runtime == "docker" {
216+
m.logger.Warningf("Ignoring executable-path=%q flag for %v", config.executablePath, config.runtime)
217+
config.executablePath = ""
214218
}
215219

216220
switch config.configSource {
@@ -330,9 +334,9 @@ func (c *config) resolveConfigSource() (toml.Loader, error) {
330334
func (c *config) getCommandConfigSource() toml.Loader {
331335
switch c.runtime {
332336
case "containerd":
333-
return containerd.CommandLineSource("")
337+
return containerd.CommandLineSource("", c.executablePath)
334338
case "crio":
335-
return crio.CommandLineSource("")
339+
return crio.CommandLineSource("", c.executablePath)
336340
}
337341
return toml.Empty
338342
}

pkg/config/engine/containerd/containerd.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,11 @@ func (c *Config) GetRuntimeConfig(name string) (engine.RuntimeConfig, error) {
162162
}
163163

164164
// CommandLineSource returns the CLI-based containerd config loader
165-
func CommandLineSource(hostRoot string) toml.Loader {
166-
return toml.FromCommandLine(chrootIfRequired(hostRoot, "containerd", "config", "dump")...)
165+
func CommandLineSource(hostRoot string, executablePath string) toml.Loader {
166+
if executablePath == "" {
167+
executablePath = "containerd"
168+
}
169+
return toml.FromCommandLine(chrootIfRequired(hostRoot, executablePath, "config", "dump")...)
167170
}
168171

169172
func chrootIfRequired(hostRoot string, commandLine ...string) []string {

pkg/config/engine/crio/crio.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,12 @@ func (c *Config) GetRuntimeConfig(name string) (engine.RuntimeConfig, error) {
157157
func (c *Config) EnableCDI() {}
158158

159159
// CommandLineSource returns the CLI-based crio config loader
160-
func CommandLineSource(hostRoot string) toml.Loader {
160+
func CommandLineSource(hostRoot string, executablePath string) toml.Loader {
161+
if executablePath == "" {
162+
executablePath = "crio"
163+
}
161164
return toml.LoadFirst(
162-
toml.FromCommandLine(chrootIfRequired(hostRoot, "crio", "status", "config")...),
165+
toml.FromCommandLine(chrootIfRequired(hostRoot, executablePath, "status", "config")...),
163166
toml.FromCommandLine(chrootIfRequired(hostRoot, "crio-status", "config")...),
164167
)
165168
}

tools/container/container.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ const (
3838
type Options struct {
3939
Config string
4040
Socket string
41+
// ExecutablePath specifies the path to the container runtime executable.
42+
// This is used to extract the current config, for example.
43+
// If a HostRootMount is specified, this path is relative to the host root
44+
// mount.
45+
ExecutablePath string
4146
// EnabledCDI indicates whether CDI should be enabled.
4247
EnableCDI bool
4348
RuntimeName string

tools/container/nvidia-toolkit/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func validateFlags(c *cli.Context, o *options) error {
136136
if err := toolkit.ValidateOptions(&o.toolkitOptions, o.toolkitRoot()); err != nil {
137137
return err
138138
}
139-
if err := runtime.ValidateOptions(c, &o.runtimeOptions, o.runtime, o.toolkitRoot(), &o.toolkitOptions); err != nil {
139+
if err := o.runtimeOptions.Validate(c, o.runtime, o.toolkitRoot(), &o.toolkitOptions); err != nil {
140140
return err
141141
}
142142
return nil

tools/container/runtime/containerd/containerd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func getRuntimeConfig(o *container.Options, co *Options) (engine.Interface, erro
173173
containerd.WithPath(o.Config),
174174
containerd.WithConfigSource(
175175
toml.LoadFirst(
176-
containerd.CommandLineSource(o.HostRootMount),
176+
containerd.CommandLineSource(o.HostRootMount, o.ExecutablePath),
177177
toml.FromFile(o.Config),
178178
),
179179
),

tools/container/runtime/crio/crio.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func getRuntimeConfig(o *container.Options) (engine.Interface, error) {
202202
crio.WithPath(o.Config),
203203
crio.WithConfigSource(
204204
toml.LoadFirst(
205-
crio.CommandLineSource(o.HostRootMount),
205+
crio.CommandLineSource(o.HostRootMount, o.ExecutablePath),
206206
toml.FromFile(o.Config),
207207
),
208208
),

tools/container/runtime/runtime.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package runtime
1919
import (
2020
"fmt"
2121

22+
log "github.com/sirupsen/logrus"
2223
"github.com/urfave/cli/v2"
2324

2425
"github.com/NVIDIA/nvidia-container-toolkit/tools/container"
@@ -53,6 +54,12 @@ func Flags(opts *Options) []cli.Flag {
5354
Destination: &opts.Config,
5455
EnvVars: []string{"RUNTIME_CONFIG", "CONTAINERD_CONFIG", "DOCKER_CONFIG"},
5556
},
57+
&cli.StringFlag{
58+
Name: "executable-path",
59+
Usage: "The path to the runtime executable. This is used to extract the current config",
60+
Destination: &opts.ExecutablePath,
61+
EnvVars: []string{"RUNTIME_EXECUTABLE_PATH"},
62+
},
5663
&cli.StringFlag{
5764
Name: "socket",
5865
Usage: "Path to the runtime socket file",
@@ -104,15 +111,20 @@ func Flags(opts *Options) []cli.Flag {
104111
return flags
105112
}
106113

107-
// ValidateOptions checks whether the specified options are valid
108-
func ValidateOptions(c *cli.Context, opts *Options, runtime string, toolkitRoot string, to *toolkit.Options) error {
114+
// Validate checks whether the specified options are valid
115+
func (opts *Options) Validate(c *cli.Context, runtime string, toolkitRoot string, to *toolkit.Options) error {
109116
// We set this option here to ensure that it is available in future calls.
110117
opts.RuntimeDir = toolkitRoot
111118

112119
if !c.IsSet("enable-cdi-in-runtime") {
113120
opts.EnableCDI = to.CDI.Enabled
114121
}
115122

123+
if opts.ExecutablePath != "" && opts.RuntimeName == docker.Name {
124+
log.Warningf("Ignoring executable-path=%q flag for %v", opts.ExecutablePath, opts.RuntimeName)
125+
opts.ExecutablePath = ""
126+
}
127+
116128
// Apply the runtime-specific config changes.
117129
switch runtime {
118130
case containerd.Name:

0 commit comments

Comments
 (0)