Skip to content

Commit

Permalink
Trying to fix some strange bug with merging multiple configs in cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
smgladkovskiy committed Apr 30, 2020
1 parent 3b196eb commit 466f570
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
17 changes: 10 additions & 7 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ func ReadConfigs(cfgPath string) ([]byte, error) {
return nil, fmt.Errorf("no default config")
}

iSay("Existing config list: %+v", fileList)

fileListResult := make(map[string][]string)
configs := make(map[string]map[string]interface{})

Expand All @@ -76,9 +78,10 @@ func ReadConfigs(cfgPath string) ([]byte, error) {
continue
}

//iSay("file `%s` in folder `%s` config: %+v", file, folder, configFromFile[folder])

if _, ok := configs[folder]; !ok {
configs[folder] = configFromFile[folder]
continue
}

cc := configs[folder]
Expand All @@ -90,17 +93,17 @@ func ReadConfigs(cfgPath string) ([]byte, error) {
}
}

iSay("Config files: `%+v`", fileListResult)
iSay("Parsed config list: `%+v`", fileListResult)

config := configs["defaults"]

c, ok := configs[stage]
if ok {
_ = mergo.Merge(&config, c, mergo.WithOverride)

iSay("Stage `%s` config is loaded and merged with `defaults`", stage)
if c, ok := configs[stage]; ok {
if err := mergo.Merge(&config, c, mergo.WithOverride); err == nil {
iSay("Stage `%s` config is loaded and merged with `defaults`", stage)
}
}

//iSay("Resulted config: `%+v`", config)
return yaml.Marshal(config)
}

Expand Down
10 changes: 5 additions & 5 deletions reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ func TestReadConfigs(t *testing.T) {
Log: struct {
Level string `yaml:"level"`
Format string `yaml:"format"`
}{Level: "warn", Format: "json"},
Host: "localhost",
Port: "8080",
}{Level: "error", Format: "text"},
Host: "127.0.0.1",
Port: "8888",
}

assert.EqualValues(t, refConfig, config)
Expand Down Expand Up @@ -134,8 +134,8 @@ func TestReadConfigs(t *testing.T) {
Level string `yaml:"level"`
Format string `yaml:"format"`
}{Level: "warn", Format: "json"},
Host: "localhost",
Port: "8080",
Host: "127.0.0.1",
Port: "8888",
}

assert.EqualValues(t, refConfig, config)
Expand Down
4 changes: 2 additions & 2 deletions test/configuration/defaults/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ defaults:
log:
level: "warn"
format: "json"
host: "localhost"
port: "8080"
host: "127.0.0.1"
port: "8888"
4 changes: 4 additions & 0 deletions test/configuration/development/log.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
development:
log:
level: "error"
format: "text"
6 changes: 3 additions & 3 deletions test/deep/deeper/thedeepest/relative_path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func TestRelativePath(t *testing.T) {
Log: struct {
Level string `yaml:"level"`
Format string `yaml:"format"`
}{Level: "warn", Format: "json"},
Host: "localhost",
Port: "8080",
}{Level: "error", Format: "text"},
Host: "127.0.0.1",
Port: "8888",
}

assert.EqualValues(t, refConfig, config)
Expand Down

0 comments on commit 466f570

Please sign in to comment.