Skip to content

Commit b332388

Browse files
committed
TOFIX: Fix docker arguments
Signed-off-by: Evan Lezar <[email protected]>
1 parent 92f9b06 commit b332388

File tree

3 files changed

+56
-14
lines changed

3 files changed

+56
-14
lines changed

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ func Flags(opts *Options) []cli.Flag {
5454
Destination: &opts.Config,
5555
Sources: cli.EnvVars("RUNTIME_CONFIG", "CONTAINERD_CONFIG", "DOCKER_CONFIG"),
5656
},
57+
&cli.StringFlag{
58+
Name: "drop-in-config",
59+
Usage: "Path to the NVIDIA-specific drop-in config file",
60+
Value: runtimeSpecificDefault,
61+
Destination: &opts.DropInConfig,
62+
Sources: cli.EnvVars("RUNTIME_DROP_IN_CONFIG"),
63+
},
5764
&cli.StringFlag{
5865
Name: "executable-path",
5966
Usage: "The path to the runtime executable. This is used to extract the current config",
@@ -120,12 +127,20 @@ func (opts *Options) Validate(logger logger.Interface, c *cli.Command, runtime s
120127
opts.EnableCDI = to.CDI.Enabled
121128
}
122129

123-
if opts.ExecutablePath != "" && opts.RuntimeName == docker.Name {
124-
logger.Warningf("Ignoring executable-path=%q flag for %v", opts.ExecutablePath, opts.RuntimeName)
125-
opts.ExecutablePath = ""
130+
switch runtime {
131+
case docker.Name:
132+
if opts.ExecutablePath != "" {
133+
logger.Warningf("Ignoring executable-path=%q flag for %v", opts.ExecutablePath, opts.RuntimeName)
134+
opts.ExecutablePath = ""
135+
}
136+
if opts.DropInConfig != "" && opts.DropInConfig != runtimeSpecificDefault {
137+
logger.Warningf("Ignorining drop-in-config=%q flag for %v", opts.DropInConfig, opts.RuntimeName)
138+
opts.DropInConfig = ""
139+
}
126140
}
127141

128142
// Apply the runtime-specific config changes.
143+
// TODO: Add the runtime-specific DropInConfigs here.
129144
switch runtime {
130145
case containerd.Name:
131146
if opts.Config == runtimeSpecificDefault {
@@ -151,6 +166,10 @@ func (opts *Options) Validate(logger logger.Interface, c *cli.Command, runtime s
151166
if opts.Config == runtimeSpecificDefault {
152167
opts.Config = docker.DefaultConfig
153168
}
169+
// Docker does not support drop-in configs.
170+
if opts.DropInConfig == runtimeSpecificDefault {
171+
opts.DropInConfig = ""
172+
}
154173
if opts.Socket == runtimeSpecificDefault {
155174
opts.Socket = docker.DefaultSocket
156175
}

cmd/nvidia-ctk-installer/main_test.go

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ func TestApp(t *testing.T) {
4040
hostRoot := filepath.Join(moduleRoot, "testdata", "lookup", "rootfs-1")
4141

4242
testCases := []struct {
43-
description string
44-
args []string
45-
expectedToolkitConfig string
46-
expectedRuntimeConfig string
43+
description string
44+
args []string
45+
expectedToolkitConfig string
46+
expectedRuntimeConfig string
47+
expectedDropInRuntimeConfig string
4748
}{
4849
{
4950
description: "no args",
@@ -285,7 +286,10 @@ swarm-resource = ""
285286
[nvidia-ctk]
286287
path = "{{ .toolkitRoot }}/toolkit/nvidia-ctk"
287288
`,
288-
expectedRuntimeConfig: `version = 2
289+
expectedRuntimeConfig: `imports = ["{{ .testRoot }}/config.d/*.toml"]
290+
version = 2
291+
`,
292+
expectedDropInRuntimeConfig: `version = 2
289293
290294
[plugins]
291295
@@ -371,7 +375,10 @@ swarm-resource = ""
371375
[nvidia-ctk]
372376
path = "{{ .toolkitRoot }}/toolkit/nvidia-ctk"
373377
`,
374-
expectedRuntimeConfig: `version = 2
378+
expectedRuntimeConfig: `imports = ["{{ .testRoot }}/config.d/*.toml"]
379+
version = 2
380+
`,
381+
expectedDropInRuntimeConfig: `version = 2
375382
376383
[plugins]
377384
@@ -418,6 +425,7 @@ swarm-resource = ""
418425

419426
cdiOutputDir := filepath.Join(testRoot, "/var/run/cdi")
420427
runtimeConfigFile := filepath.Join(testRoot, "config.file")
428+
runtimeDropInConfigFile := filepath.Join(testRoot, "config.d/config.toml")
421429

422430
toolkitRoot := filepath.Join(testRoot, "toolkit-test")
423431
toolkitConfigFile := filepath.Join(toolkitRoot, "toolkit/.config/nvidia-container-runtime/config.toml")
@@ -430,6 +438,7 @@ swarm-resource = ""
430438
"--no-daemon",
431439
"--cdi-output-dir=" + cdiOutputDir,
432440
"--config=" + runtimeConfigFile,
441+
"--drop-in-config=" + runtimeDropInConfigFile,
433442
"--create-device-nodes=none",
434443
"--driver-root-ctr-path=" + hostRoot,
435444
"--pid-file=" + filepath.Join(testRoot, "toolkit.pid"),
@@ -446,10 +455,24 @@ swarm-resource = ""
446455
require.NoError(t, err)
447456
require.EqualValues(t, strings.ReplaceAll(tc.expectedToolkitConfig, "{{ .toolkitRoot }}", toolkitRoot), string(toolkitConfigFileContents))
448457

449-
require.FileExists(t, runtimeConfigFile)
450-
runtimeConfigFileContents, err := os.ReadFile(runtimeConfigFile)
451-
require.NoError(t, err)
452-
require.EqualValues(t, strings.ReplaceAll(tc.expectedRuntimeConfig, "{{ .toolkitRoot }}", toolkitRoot), string(runtimeConfigFileContents))
458+
if len(tc.expectedRuntimeConfig) > 0 {
459+
require.FileExists(t, runtimeConfigFile)
460+
runtimeConfigFileContents, err := os.ReadFile(runtimeConfigFile)
461+
require.NoError(t, err)
462+
expected := strings.ReplaceAll(tc.expectedRuntimeConfig, "{{ .testRoot }}", testRoot)
463+
require.Equal(t, strings.ReplaceAll(expected, "{{ .toolkitRoot }}", toolkitRoot), string(runtimeConfigFileContents))
464+
} else {
465+
require.NoFileExists(t, runtimeConfigFile)
466+
}
467+
468+
if len(tc.expectedDropInRuntimeConfig) > 0 {
469+
require.FileExists(t, runtimeDropInConfigFile)
470+
runtimeDropInConfigFileContents, err := os.ReadFile(runtimeDropInConfigFile)
471+
require.NoError(t, err)
472+
require.Equal(t, strings.ReplaceAll(tc.expectedDropInRuntimeConfig, "{{ .toolkitRoot }}", toolkitRoot), string(runtimeDropInConfigFileContents))
473+
} else {
474+
require.NoFileExists(t, runtimeDropInConfigFile)
475+
}
453476
})
454477
}
455478

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ func (m command) configureConfigFile(config *config) error {
272272
case "crio":
273273
cfg, err = crio.New(
274274
crio.WithLogger(m.logger),
275-
crio.WithPath(config.configFilePath),
275+
crio.WithTopLevelConfigPath(config.configFilePath),
276276
crio.WithConfigSource(configSource),
277277
)
278278
case "docker":

0 commit comments

Comments
 (0)