Skip to content

Commit

Permalink
Merge pull request #2111 from alibaba/revert-2057-config
Browse files Browse the repository at this point in the history
Revert "fix: make iterateTLSConfig only work for TLS config"
  • Loading branch information
allencloud authored Aug 17, 2018
2 parents 1b99698 + a44bf6b commit 5847b76
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
11 changes: 5 additions & 6 deletions daemon/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (cfg *Config) MergeConfigurations(flagSet *pflag.FlagSet) error {
}

fileFlags := make(map[string]interface{}, 0)
iterateTLSConfig(origin, fileFlags)
iterateConfig(origin, fileFlags)

// check if invalid or unknown flag exist in config file
if err = getUnknownFlags(flagSet, fileFlags); err != nil {
Expand Down Expand Up @@ -225,12 +225,11 @@ func (cfg *Config) delValue(flagSet *pflag.FlagSet, fileFlags map[string]interfa
return cfg
}

// iterateTLSConfig resolves key-value from config file iteratly.
// only for TLS config, and recursive once.
func iterateTLSConfig(origin map[string]interface{}, config map[string]interface{}) {
// iterateConfig resolves key-value from config file iteratly.
func iterateConfig(origin map[string]interface{}, config map[string]interface{}) {
for k, v := range origin {
if c, ok := v.(map[string]interface{}); ok && k == "TLS" {
iterateTLSConfig(c, config)
if c, ok := v.(map[string]interface{}); ok && k != "add-runtime" {
iterateConfig(c, config)
} else {
config[k] = v
}
Expand Down
35 changes: 32 additions & 3 deletions daemon/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,41 @@ import (
"github.com/stretchr/testify/assert"
)

func TestIterateTLSConfig(t *testing.T) {
func TestIterateConfig(t *testing.T) {
assert := assert.New(t)
origin := map[string]interface{}{
"a": "a",
"b": "b",
"c": "c",
"iter1": map[string]interface{}{
"i1": "i1",
"i2": "i2",
},
"iter11": map[string]interface{}{
"ii1": map[string]interface{}{
"iii1": "iii1",
"iii2": "iii2",
},
},
}

expect := map[string]interface{}{
"a": "a",
"b": "b",
"c": "c",
"i1": "i1",
"i2": "i2",
"iii1": "iii1",
"iii2": "iii2",
}

// test nil map will not cause panic
config := make(map[string]interface{})
iterateTLSConfig(nil, config)
iterateConfig(origin, config)
assert.Equal(config, expect)

// test nil map will not cause panic
config = make(map[string]interface{})
iterateConfig(nil, config)
assert.Equal(config, map[string]interface{}{})
}

Expand Down

0 comments on commit 5847b76

Please sign in to comment.