Merge configs section by section
Signed-off-by: Maksym Pavlenko <makpav@amazon.com>
This commit is contained in:
parent
8ebffecbc3
commit
24b9e2c1a0
@ -297,8 +297,27 @@ func resolveImports(parent string, imports []string) ([]string, error) {
|
||||
// 0 1 1
|
||||
// []{"1"} []{"2"} []{"1","2"}
|
||||
// []{"1"} []{} []{"1"}
|
||||
// Maps merged by keys, but values are replaced entirely.
|
||||
func mergeConfig(to, from *Config) error {
|
||||
return mergo.Merge(to, from, mergo.WithOverride, mergo.WithAppendSlice)
|
||||
err := mergo.Merge(to, from, mergo.WithOverride, mergo.WithAppendSlice)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Replace entire sections instead of merging map's values.
|
||||
for k, v := range from.Plugins {
|
||||
to.Plugins[k] = v
|
||||
}
|
||||
|
||||
for k, v := range from.StreamProcessors {
|
||||
to.StreamProcessors[k] = v
|
||||
}
|
||||
|
||||
for k, v := range from.ProxyPlugins {
|
||||
to.ProxyPlugins[k] = v
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// V1DisabledFilter matches based on ID
|
||||
|
@ -36,6 +36,7 @@ func TestMergeConfigs(t *testing.T) {
|
||||
State: "old_state",
|
||||
OOMScore: 1,
|
||||
Timeouts: map[string]string{"a": "1"},
|
||||
StreamProcessors: map[string]StreamProcessor{"1": {Path: "2", Returns: "4"}, "2": {Path: "5"}},
|
||||
}
|
||||
|
||||
b := &Config{
|
||||
@ -43,6 +44,7 @@ func TestMergeConfigs(t *testing.T) {
|
||||
RequiredPlugins: []string{"new_plugin1", "new_plugin2"},
|
||||
OOMScore: 2,
|
||||
Timeouts: map[string]string{"b": "2"},
|
||||
StreamProcessors: map[string]StreamProcessor{"1": {Path: "3"}},
|
||||
}
|
||||
|
||||
err := mergeConfig(a, b)
|
||||
@ -55,6 +57,7 @@ func TestMergeConfigs(t *testing.T) {
|
||||
assert.DeepEqual(t, a.RequiredPlugins, []string{"old_plugin", "new_plugin1", "new_plugin2"})
|
||||
assert.DeepEqual(t, a.DisabledPlugins, []string{"old_plugin"})
|
||||
assert.DeepEqual(t, a.Timeouts, map[string]string{"a": "1", "b": "2"})
|
||||
assert.DeepEqual(t, a.StreamProcessors, map[string]StreamProcessor{"1": {Path: "3"}, "2": {Path: "5"}})
|
||||
}
|
||||
|
||||
func TestResolveImports(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user