@@ -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.
3031type 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.
3941type 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.
5964func (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.
93101func (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
131138func (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
0 commit comments