1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
package config
import (
"path/filepath"
"github.com/containers/libpod/libpod/define"
"github.com/sirupsen/logrus"
)
// Merge merges the other config into the current one. Note that a field of the
// other config is only merged when it's not already set in the current one.
//
// Note that the StateType and the StorageConfig will NOT be changed.
func (c *Config) mergeConfig(other *Config) error {
// strings
c.CgroupManager = mergeStrings(c.CgroupManager, other.CgroupManager)
c.CNIConfigDir = mergeStrings(c.CNIConfigDir, other.CNIConfigDir)
c.CNIDefaultNetwork = mergeStrings(c.CNIDefaultNetwork, other.CNIDefaultNetwork)
c.DefaultMountsFile = mergeStrings(c.DefaultMountsFile, other.DefaultMountsFile)
c.DetachKeys = mergeStrings(c.DetachKeys, other.DetachKeys)
c.EventsLogFilePath = mergeStrings(c.EventsLogFilePath, other.EventsLogFilePath)
c.EventsLogger = mergeStrings(c.EventsLogger, other.EventsLogger)
c.ImageDefaultTransport = mergeStrings(c.ImageDefaultTransport, other.ImageDefaultTransport)
c.InfraCommand = mergeStrings(c.InfraCommand, other.InfraCommand)
c.InfraImage = mergeStrings(c.InfraImage, other.InfraImage)
c.InitPath = mergeStrings(c.InitPath, other.InitPath)
c.LockType = mergeStrings(c.LockType, other.LockType)
c.Namespace = mergeStrings(c.Namespace, other.Namespace)
c.NetworkCmdPath = mergeStrings(c.NetworkCmdPath, other.NetworkCmdPath)
c.OCIRuntime = mergeStrings(c.OCIRuntime, other.OCIRuntime)
c.SignaturePolicyPath = mergeStrings(c.SignaturePolicyPath, other.SignaturePolicyPath)
c.StaticDir = mergeStrings(c.StaticDir, other.StaticDir)
c.TmpDir = mergeStrings(c.TmpDir, other.TmpDir)
c.VolumePath = mergeStrings(c.VolumePath, other.VolumePath)
// string map of slices
c.OCIRuntimes = mergeStringMaps(c.OCIRuntimes, other.OCIRuntimes)
// string slices
c.CNIPluginDir = mergeStringSlices(c.CNIPluginDir, other.CNIPluginDir)
c.ConmonEnvVars = mergeStringSlices(c.ConmonEnvVars, other.ConmonEnvVars)
c.ConmonPath = mergeStringSlices(c.ConmonPath, other.ConmonPath)
c.HooksDir = mergeStringSlices(c.HooksDir, other.HooksDir)
c.RuntimePath = mergeStringSlices(c.RuntimePath, other.RuntimePath)
c.RuntimeSupportsJSON = mergeStringSlices(c.RuntimeSupportsJSON, other.RuntimeSupportsJSON)
c.RuntimeSupportsNoCgroups = mergeStringSlices(c.RuntimeSupportsNoCgroups, other.RuntimeSupportsNoCgroups)
// int64s
c.MaxLogSize = mergeInt64s(c.MaxLogSize, other.MaxLogSize)
// uint32s
c.NumLocks = mergeUint32s(c.NumLocks, other.NumLocks)
// bools
c.EnableLabeling = mergeBools(c.EnableLabeling, other.EnableLabeling)
c.EnablePortReservation = mergeBools(c.EnablePortReservation, other.EnablePortReservation)
c.NoPivotRoot = mergeBools(c.NoPivotRoot, other.NoPivotRoot)
c.SDNotify = mergeBools(c.SDNotify, other.SDNotify)
// state type
if c.StateType == define.InvalidStateStore {
c.StateType = other.StateType
}
// store options - need to check all fields since some configs might only
// set it partially
c.StorageConfig.RunRoot = mergeStrings(c.StorageConfig.RunRoot, other.StorageConfig.RunRoot)
c.StorageConfig.GraphRoot = mergeStrings(c.StorageConfig.GraphRoot, other.StorageConfig.GraphRoot)
c.StorageConfig.GraphDriverName = mergeStrings(c.StorageConfig.GraphDriverName, other.StorageConfig.GraphDriverName)
c.StorageConfig.GraphDriverOptions = mergeStringSlices(c.StorageConfig.GraphDriverOptions, other.StorageConfig.GraphDriverOptions)
if c.StorageConfig.UIDMap == nil {
c.StorageConfig.UIDMap = other.StorageConfig.UIDMap
}
if c.StorageConfig.GIDMap == nil {
c.StorageConfig.GIDMap = other.StorageConfig.GIDMap
}
// backwards compat *Set fields
c.StorageConfigRunRootSet = mergeBools(c.StorageConfigRunRootSet, other.StorageConfigRunRootSet)
c.StorageConfigGraphRootSet = mergeBools(c.StorageConfigGraphRootSet, other.StorageConfigGraphRootSet)
c.StorageConfigGraphDriverNameSet = mergeBools(c.StorageConfigGraphDriverNameSet, other.StorageConfigGraphDriverNameSet)
c.VolumePathSet = mergeBools(c.VolumePathSet, other.VolumePathSet)
c.StaticDirSet = mergeBools(c.StaticDirSet, other.StaticDirSet)
c.TmpDirSet = mergeBools(c.TmpDirSet, other.TmpDirSet)
return nil
}
// MergeDBConfig merges the configuration from the database.
func (c *Config) MergeDBConfig(dbConfig *DBConfig) error {
if !c.StorageConfigRunRootSet && dbConfig.StorageTmp != "" {
if c.StorageConfig.RunRoot != dbConfig.StorageTmp &&
c.StorageConfig.RunRoot != "" {
logrus.Debugf("Overriding run root %q with %q from database",
c.StorageConfig.RunRoot, dbConfig.StorageTmp)
}
c.StorageConfig.RunRoot = dbConfig.StorageTmp
}
if !c.StorageConfigGraphRootSet && dbConfig.StorageRoot != "" {
if c.StorageConfig.GraphRoot != dbConfig.StorageRoot &&
c.StorageConfig.GraphRoot != "" {
logrus.Debugf("Overriding graph root %q with %q from database",
c.StorageConfig.GraphRoot, dbConfig.StorageRoot)
}
c.StorageConfig.GraphRoot = dbConfig.StorageRoot
}
if !c.StorageConfigGraphDriverNameSet && dbConfig.GraphDriver != "" {
if c.StorageConfig.GraphDriverName != dbConfig.GraphDriver &&
c.StorageConfig.GraphDriverName != "" {
logrus.Errorf("User-selected graph driver %q overwritten by graph driver %q from database - delete libpod local files to resolve",
c.StorageConfig.GraphDriverName, dbConfig.GraphDriver)
}
c.StorageConfig.GraphDriverName = dbConfig.GraphDriver
}
if !c.StaticDirSet && dbConfig.LibpodRoot != "" {
if c.StaticDir != dbConfig.LibpodRoot && c.StaticDir != "" {
logrus.Debugf("Overriding static dir %q with %q from database", c.StaticDir, dbConfig.LibpodRoot)
}
c.StaticDir = dbConfig.LibpodRoot
}
if !c.TmpDirSet && dbConfig.LibpodTmp != "" {
if c.TmpDir != dbConfig.LibpodTmp && c.TmpDir != "" {
logrus.Debugf("Overriding tmp dir %q with %q from database", c.TmpDir, dbConfig.LibpodTmp)
}
c.TmpDir = dbConfig.LibpodTmp
c.EventsLogFilePath = filepath.Join(dbConfig.LibpodTmp, "events", "events.log")
}
if !c.VolumePathSet && dbConfig.VolumePath != "" {
if c.VolumePath != dbConfig.VolumePath && c.VolumePath != "" {
logrus.Debugf("Overriding volume path %q with %q from database", c.VolumePath, dbConfig.VolumePath)
}
c.VolumePath = dbConfig.VolumePath
}
return nil
}
func mergeStrings(a, b string) string {
if a == "" {
return b
}
return a
}
func mergeStringSlices(a, b []string) []string {
if len(a) == 0 && b != nil {
return b
}
return a
}
func mergeStringMaps(a, b map[string][]string) map[string][]string {
if len(a) == 0 && b != nil {
return b
}
return a
}
func mergeInt64s(a, b int64) int64 {
if a == 0 {
return b
}
return a
}
func mergeUint32s(a, b uint32) uint32 {
if a == 0 {
return b
}
return a
}
func mergeBools(a, b bool) bool {
if !a {
return b
}
return a
}
|