From 82b3458befbf63b727eb896b648de3c34c942cbd Mon Sep 17 00:00:00 2001 From: Rudy Zhang Date: Tue, 11 Sep 2018 20:25:52 +0800 Subject: [PATCH] bugfix: check int type is empty check int type is empty when do the merge. Signed-off-by: Rudy Zhang --- daemon/config/config.go | 9 ++++++--- pkg/utils/utils.go | 2 ++ pkg/utils/utils_test.go | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/daemon/config/config.go b/daemon/config/config.go index 0d3021647..79d7f11f8 100644 --- a/daemon/config/config.go +++ b/daemon/config/config.go @@ -17,6 +17,7 @@ import ( "github.com/alibaba/pouch/pkg/utils" "github.com/alibaba/pouch/storage/volume" + "github.com/sirupsen/logrus" "github.com/spf13/pflag" ) @@ -131,6 +132,10 @@ func (cfg *Config) GetCgroupDriver() string { // Validate validates the user input config. func (cfg *Config) Validate() error { + // for debug config file. + b, _ := json.Marshal(cfg) + logrus.Debugf("daemon config: (%s)", string(b)) + // deduplicated elements in slice if there is any. cfg.Listen = utils.DeDuplicate(cfg.Listen) cfg.Labels = utils.DeDuplicate(cfg.Labels) @@ -191,9 +196,7 @@ func (cfg *Config) MergeConfigurations(flagSet *pflag.FlagSet) error { } // merge configurations from command line flags and config file - err = mergeConfigurations(fileConfig, cfg.delValue(flagSet, fileFlags)) - return err - + return mergeConfigurations(fileConfig, cfg.delValue(flagSet, fileFlags)) } // delValue deleles value in config, since we do not do conflict check for slice diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 705dd7d6f..7b9a1b9b2 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -122,6 +122,8 @@ func isEmptyValue(v reflect.Value) bool { switch v.Kind() { case reflect.Array, reflect.Map, reflect.Slice, reflect.String: return v.Len() == 0 + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + return v.Int() == 0 case reflect.Uintptr: return v.Uint() == 0 case reflect.Float32, reflect.Float64: diff --git a/pkg/utils/utils_test.go b/pkg/utils/utils_test.go index b9f1a7ce8..6cb7c7a52 100644 --- a/pkg/utils/utils_test.go +++ b/pkg/utils/utils_test.go @@ -91,7 +91,7 @@ func TestMerge(t *testing.T) { }, { src: &simple{}, dest: &simple{Sa: 1, Sb: "hello", Sc: true, Sd: map[string]string{"go": "gogo"}, Se: nestS{Na: 22}}, - expected: &simple{Sa: 0, Sb: "hello", Sc: false, Sd: map[string]string{"go": "gogo"}, Se: nestS{Na: 0}}, + expected: &simple{Sa: 1, Sb: "hello", Sc: false, Sd: map[string]string{"go": "gogo"}, Se: nestS{Na: 22}}, ok: true, }, { src: &simple{Sa: 1, Sc: true, Sd: map[string]string{"go": "gogo"}, Se: nestS{Na: 11}, Sf: []string{"foo"}}, @@ -101,7 +101,7 @@ func TestMerge(t *testing.T) { }, { src: &simple{Sa: 0, Sc: false, Sd: map[string]string{"go": "gogo"}, Se: nestS{Na: 11}, Sf: []string{"foo"}}, dest: &simple{Sa: 2, Sb: "world", Sc: true, Sd: map[string]string{"go": "old"}, Se: nestS{Na: 22}, Sf: []string{"foo"}}, - expected: &simple{Sa: 0, Sb: "world", Sc: false, Sd: map[string]string{"go": "gogo"}, Se: nestS{Na: 11}, Sf: []string{"foo", "foo"}}, + expected: &simple{Sa: 2, Sb: "world", Sc: false, Sd: map[string]string{"go": "gogo"}, Se: nestS{Na: 11}, Sf: []string{"foo", "foo"}}, ok: true, }, { src: &simple{Sd: map[string]string{"go": "gogo", "a": "b"}},