From a44bf6b7553ff6efabe711ef3ef427d621a17d01 Mon Sep 17 00:00:00 2001 From: Ace Tang Date: Fri, 17 Aug 2018 15:15:37 +0800 Subject: [PATCH] Revert "fix: make iterateTLSConfig only work for TLS config" --- daemon/config/config.go | 11 +++++------ daemon/config/config_test.go | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/daemon/config/config.go b/daemon/config/config.go index 7a12ec5c3..ab8510bf7 100644 --- a/daemon/config/config.go +++ b/daemon/config/config.go @@ -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 { @@ -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 } diff --git a/daemon/config/config_test.go b/daemon/config/config_test.go index 85399bc11..9a813622d 100644 --- a/daemon/config/config_test.go +++ b/daemon/config/config_test.go @@ -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{}{}) }