@@ -21,13 +21,15 @@ import (
21
21
"fmt"
22
22
"path/filepath"
23
23
24
+ "github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
24
25
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine"
25
26
)
26
27
27
28
// A ConfigWithDropIn represents a pair of containerd configs.
28
29
// The first is the top-level config and the second is an in-memory drop-in config
29
30
// that only contains modifications made to the config.
30
31
type ConfigWithDropIn struct {
32
+ logger logger.Interface
31
33
topLevelConfig * topLevelConfig
32
34
engine.Interface
33
35
}
@@ -37,14 +39,17 @@ var _ engine.Interface = (*ConfigWithDropIn)(nil)
37
39
// A topLevelConfig stores the original on-disk top-level config.
38
40
// The path to the config is also stored to allow it to be modified if required.
39
41
type topLevelConfig struct {
42
+ logger logger.Interface
40
43
path string
41
44
containerToHostPathMap map [string ]string
42
45
config * Config
43
46
}
44
47
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 {
46
49
return & ConfigWithDropIn {
50
+ logger : logger ,
47
51
topLevelConfig : & topLevelConfig {
52
+ logger : logger ,
48
53
path : topLevelConfigPath ,
49
54
containerToHostPathMap : containerToHostPathMap ,
50
55
config : tlConfig ,
@@ -57,6 +62,9 @@ func NewConfigWithDropIn(topLevelConfigPath string, containerToHostPathMap map[s
57
62
// The top-level config is optionally updated to include the required imports
58
63
// to allow the drop-in-file to be created.
59
64
func (c * ConfigWithDropIn ) Save (dropInPath string ) (int64 , error ) {
65
+ if dropInPath == engine .SaveToSTDOUT {
66
+ c .logger .Infof ("Drop-in config:" )
67
+ }
60
68
bytesWritten , err := c .Interface .Save (dropInPath )
61
69
if err != nil {
62
70
return 0 , err
@@ -92,11 +100,10 @@ func (c *ConfigWithDropIn) RemoveRuntime(name string) error {
92
100
// If the config is empty, the file will be deleted.
93
101
func (c * topLevelConfig ) Save (dropInPath string ) (int64 , error ) {
94
102
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:" )
98
106
}
99
-
100
107
return c .config .Save (saveToPath )
101
108
}
102
109
@@ -129,6 +136,11 @@ func (c *topLevelConfig) removeImports(dropInFilename string) {
129
136
}
130
137
131
138
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
+ }
132
144
return c .asHostPath (filepath .Dir (dropInFilename )) + "/*.toml"
133
145
}
134
146
0 commit comments