Skip to content

Commit d4ff926

Browse files
committed
[no-relnote] Minor comments
Signed-off-by: Evan Lezar <[email protected]>
1 parent a6e6d1a commit d4ff926

File tree

4 files changed

+40
-19
lines changed

4 files changed

+40
-19
lines changed

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ const (
5252
defaultConfigSource = configSourceFile
5353
configSourceCommand = "command"
5454
configSourceFile = "file"
55+
56+
// TODO: We may want to spend some time unifying the handling of config
57+
// files here with the Setup-Cleanup logic in nvidia-ctk-installer.
58+
runtimeSpecificDefault = "RUNTIME_SPECIFIC_DEFAULT"
5559
)
5660

5761
type command struct {
@@ -125,6 +129,7 @@ func (m command) build() *cli.Command {
125129
&cli.StringFlag{
126130
Name: "drop-in-config",
127131
Usage: "path to the NVIDIA-specific config file to create. When specified, runtime configurations are saved to this file instead of modifying the main config file",
132+
Value: runtimeSpecificDefault,
128133
Destination: &config.dropInConfigPath,
129134
},
130135
&cli.StringFlag{
@@ -250,23 +255,25 @@ func (m command) validateFlags(config *config) error {
250255
}
251256
}
252257

253-
if config.dropInConfigPath == "" {
258+
if config.dropInConfigPath == runtimeSpecificDefault {
254259
switch config.runtime {
255260
case "containerd":
256261
config.dropInConfigPath = defaultContainerdDropInConfigFilePath
257262
case "crio":
258263
config.dropInConfigPath = defaultCrioDropInConfigFilePath
264+
case "docker":
265+
config.dropInConfigPath = ""
259266
}
260267
}
261268

262-
if config.dropInConfigPath != "" && !filepath.IsAbs(config.dropInConfigPath) {
263-
return fmt.Errorf("the drop-in-config path %q is not an absolute path", config.dropInConfigPath)
264-
}
265-
266269
if config.dropInConfigPath != "" && config.runtime == "docker" {
267270
return fmt.Errorf("runtime %v does not support drop-in configs", config.runtime)
268271
}
269272

273+
if config.dropInConfigPath != "" && !filepath.IsAbs(config.dropInConfigPath) {
274+
return fmt.Errorf("the drop-in-config path %q is not an absolute path", config.dropInConfigPath)
275+
}
276+
270277
return nil
271278
}
272279

@@ -371,16 +378,12 @@ func (c *config) getCommandConfigSource() toml.Loader {
371378
// getOutputConfigPath returns the configured config path or "" if dry-run is enabled
372379
func (c *config) getOutputConfigPath() string {
373380
if c.dryRun {
374-
return ""
381+
return engine.SaveToSTDOUT
375382
}
376-
var configFilePath string
377-
if c.runtime == "containerd" || c.runtime == "crio" {
378-
configFilePath = c.dropInConfigPath
379-
} else {
380-
configFilePath = c.configFilePath
383+
if c.dropInConfigPath != "" {
384+
return c.dropInConfigPath
381385
}
382-
383-
return configFilePath
386+
return c.configFilePath
384387
}
385388

386389
// configureOCIHook creates and configures the OCI hook for the NVIDIA runtime

pkg/config/engine/api.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616

1717
package engine
1818

19+
const (
20+
// SaveToSTDOUT is used to write the specified config to stdout instead of
21+
// to a file on disk.
22+
SaveToSTDOUT = ""
23+
)
24+
1925
// Interface defines the API for a runtime config updater.
2026
type Interface interface {
2127
AddRuntime(string, string, bool) error

pkg/config/engine/containerd/config_drop_in.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ import (
2121
"fmt"
2222
"path/filepath"
2323

24+
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
2425
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine"
2526
)
2627

2728
// A ConfigWithDropIn represents a pair of containerd configs.
2829
// The first is the top-level config and the second is an in-memory drop-in config
2930
// that only contains modifications made to the config.
3031
type ConfigWithDropIn struct {
32+
logger logger.Interface
3133
topLevelConfig *topLevelConfig
3234
engine.Interface
3335
}
@@ -37,14 +39,17 @@ var _ engine.Interface = (*ConfigWithDropIn)(nil)
3739
// A topLevelConfig stores the original on-disk top-level config.
3840
// The path to the config is also stored to allow it to be modified if required.
3941
type topLevelConfig struct {
42+
logger logger.Interface
4043
path string
4144
containerToHostPathMap map[string]string
4245
config *Config
4346
}
4447

45-
func NewConfigWithDropIn(topLevelConfigPath string, containerToHostPathMap map[string]string, tlConfig *Config, dropInConfig engine.Interface) *ConfigWithDropIn {
48+
func NewConfigWithDropIn(logger logger.Interface, topLevelConfigPath string, containerToHostPathMap map[string]string, tlConfig *Config, dropInConfig engine.Interface) *ConfigWithDropIn {
4649
return &ConfigWithDropIn{
50+
logger: logger,
4751
topLevelConfig: &topLevelConfig{
52+
logger: logger,
4853
path: topLevelConfigPath,
4954
containerToHostPathMap: containerToHostPathMap,
5055
config: tlConfig,
@@ -57,6 +62,9 @@ func NewConfigWithDropIn(topLevelConfigPath string, containerToHostPathMap map[s
5762
// The top-level config is optionally updated to include the required imports
5863
// to allow the drop-in-file to be created.
5964
func (c *ConfigWithDropIn) Save(dropInPath string) (int64, error) {
65+
if dropInPath == engine.SaveToSTDOUT {
66+
c.logger.Infof("Drop-in config:")
67+
}
6068
bytesWritten, err := c.Interface.Save(dropInPath)
6169
if err != nil {
6270
return 0, err
@@ -92,11 +100,10 @@ func (c *ConfigWithDropIn) RemoveRuntime(name string) error {
92100
// If the config is empty, the file will be deleted.
93101
func (c *topLevelConfig) Save(dropInPath string) (int64, error) {
94102
saveToPath := c.path
95-
// If dropInPath is empty, we write to STDOUT
96-
if dropInPath == "" {
97-
saveToPath = ""
103+
if dropInPath == engine.SaveToSTDOUT {
104+
saveToPath = engine.SaveToSTDOUT
105+
c.logger.Infof("Top-level config:")
98106
}
99-
100107
return c.config.Save(saveToPath)
101108
}
102109

@@ -129,6 +136,11 @@ func (c *topLevelConfig) removeImports(dropInFilename string) {
129136
}
130137

131138
func (c *topLevelConfig) importPattern(dropInFilename string) string {
139+
// TODO: If we make output to STDOUT a property of the config itself, then
140+
// we can actually generate the correct import statement.
141+
if dropInFilename == engine.SaveToSTDOUT {
142+
return "/etc/containerd/config.d/*.toml"
143+
}
132144
return c.asHostPath(filepath.Dir(dropInFilename)) + "/*.toml"
133145
}
134146

pkg/config/engine/containerd/containerd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func New(opts ...Option) (engine.Interface, error) {
141141
},
142142
}
143143

144-
cfg := NewConfigWithDropIn(b.topLevelConfigPath, b.containerToHostPathMap, topLevelConfig, dropInConfig)
144+
cfg := NewConfigWithDropIn(b.logger, b.topLevelConfigPath, b.containerToHostPathMap, topLevelConfig, dropInConfig)
145145
return cfg, nil
146146
}
147147
}

0 commit comments

Comments
 (0)