Skip to content

Commit 86509b4

Browse files
committed
Add none runtime to toolkit installer
This change adds a "none" runtime to the toolkit installer to enable use cases where the NVIDIA Container Toolkit is required without configuring the underlying runtime. Signed-off-by: Evan Lezar <[email protected]>
1 parent 4fbb11e commit 86509b4

File tree

2 files changed

+44
-19
lines changed

2 files changed

+44
-19
lines changed

cmd/nvidia-ctk-installer/container/runtime/runtime.go

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@ func Flags(opts *Options) []cli.Flag {
138138

139139
// Validate checks whether the specified options are valid
140140
func (opts *Options) Validate(logger logger.Interface, c *cli.Command, runtime string, toolkitRoot string, to *toolkit.Options) error {
141+
// Check that the specified runtime is supported.
142+
switch runtime {
143+
case containerd.Name:
144+
case crio.Name:
145+
case docker.Name:
146+
case string(None):
147+
// If the none runtime is selected, we bypass any additional validations.
148+
return nil
149+
default:
150+
return fmt.Errorf("invalid runtime %q; expected one of [containerd | crio | docker | none]", runtime)
151+
}
152+
141153
// We set this option here to ensure that it is available in future calls.
142154
opts.RuntimeDir = toolkitRoot
143155

@@ -212,40 +224,51 @@ func (opts *Options) Validate(logger logger.Interface, c *cli.Command, runtime s
212224
return nil
213225
}
214226

215-
func Setup(c *cli.Command, opts *Options, runtime string) error {
216-
switch runtime {
227+
type Runtime string
228+
229+
// A None runtime is used to disable runtime configuration.
230+
const None Runtime = "none"
231+
232+
func (r Runtime) Setup(c *cli.Command, opts *Options) error {
233+
switch string(r) {
217234
case containerd.Name:
218235
return containerd.Setup(c, &opts.Options, &opts.containerdOptions)
219236
case crio.Name:
220237
return crio.Setup(c, &opts.Options, &opts.crioOptions)
221238
case docker.Name:
222239
return docker.Setup(c, &opts.Options)
240+
case string(None):
241+
return nil
223242
default:
224-
return fmt.Errorf("undefined runtime %v", runtime)
243+
return fmt.Errorf("undefined runtime %v", r)
225244
}
226245
}
227246

228-
func Cleanup(c *cli.Command, opts *Options, runtime string) error {
229-
switch runtime {
247+
func (r Runtime) Cleanup(c *cli.Command, opts *Options, runtime string) error {
248+
switch string(r) {
230249
case containerd.Name:
231250
return containerd.Cleanup(c, &opts.Options, &opts.containerdOptions)
232251
case crio.Name:
233252
return crio.Cleanup(c, &opts.Options, &opts.crioOptions)
234253
case docker.Name:
235254
return docker.Cleanup(c, &opts.Options)
255+
case string(None):
256+
return nil
236257
default:
237258
return fmt.Errorf("undefined runtime %v", runtime)
238259
}
239260
}
240261

241-
func GetLowlevelRuntimePaths(opts *Options, runtime string) ([]string, error) {
262+
func (r Runtime) GetLowlevelRuntimePaths(opts *Options, runtime string) ([]string, error) {
242263
switch runtime {
243264
case containerd.Name:
244265
return containerd.GetLowlevelRuntimePaths(&opts.Options, &opts.containerdOptions)
245266
case crio.Name:
246267
return crio.GetLowlevelRuntimePaths(&opts.Options)
247268
case docker.Name:
248269
return docker.GetLowlevelRuntimePaths(&opts.Options)
270+
case string(None):
271+
return nil, nil
249272
default:
250273
return nil, fmt.Errorf("undefined runtime %v", runtime)
251274
}

cmd/nvidia-ctk-installer/main.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,18 @@ func (a *app) validateFlags(c *cli.Command, o *options) error {
175175
if o.toolkitInstallDir == "" {
176176
return fmt.Errorf("the install root must be specified")
177177
}
178-
if _, exists := availableRuntimes[o.runtime]; !exists {
179-
return fmt.Errorf("unknown runtime: %v", o.runtime)
180-
}
181178
if filepath.Base(o.pidFile) != toolkitPidFilename {
182179
return fmt.Errorf("invalid toolkit.pid path %v", o.pidFile)
183180
}
184181

185182
if err := a.toolkit.ValidateOptions(&o.toolkitOptions); err != nil {
186183
return err
187184
}
185+
188186
if err := o.runtimeOptions.Validate(a.logger, c, o.runtime, o.toolkitRoot(), &o.toolkitOptions); err != nil {
189187
return err
190188
}
189+
191190
return nil
192191
}
193192

@@ -201,6 +200,8 @@ func (a *app) Run(c *cli.Command, o *options) error {
201200
}
202201
defer a.shutdown(o.pidFile)
203202

203+
runtime := runtime.Runtime(o.runtime)
204+
204205
if len(o.toolkitOptions.ContainerRuntimeRuntimes) == 0 {
205206
lowlevelRuntimePaths, err := runtime.GetLowlevelRuntimePaths(&o.runtimeOptions, o.runtime)
206207
if err != nil {
@@ -216,21 +217,22 @@ func (a *app) Run(c *cli.Command, o *options) error {
216217
return fmt.Errorf("unable to install toolkit: %v", err)
217218
}
218219

219-
err = runtime.Setup(c, &o.runtimeOptions, o.runtime)
220+
err = runtime.Setup(c, &o.runtimeOptions)
220221
if err != nil {
221222
return fmt.Errorf("unable to setup runtime: %v", err)
222223
}
224+
if o.noDaemon {
225+
return nil
226+
}
223227

224-
if !o.noDaemon {
225-
err = a.waitForSignal()
226-
if err != nil {
227-
return fmt.Errorf("unable to wait for signal: %v", err)
228-
}
228+
err = a.waitForSignal()
229+
if err != nil {
230+
return fmt.Errorf("unable to wait for signal: %v", err)
231+
}
229232

230-
err = runtime.Cleanup(c, &o.runtimeOptions, o.runtime)
231-
if err != nil {
232-
return fmt.Errorf("unable to cleanup runtime: %v", err)
233-
}
233+
err = runtime.Cleanup(c, &o.runtimeOptions, o.runtime)
234+
if err != nil {
235+
return fmt.Errorf("unable to cleanup runtime: %v", err)
234236
}
235237

236238
return nil

0 commit comments

Comments
 (0)