Skip to content

Commit

Permalink
Merge pull request #2235 from rudyfly/config
Browse files Browse the repository at this point in the history
bugfix: check int type is empty
  • Loading branch information
Ace-Tang authored Sep 17, 2018
2 parents b926849 + 82b3458 commit 2e06d4e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
9 changes: 6 additions & 3 deletions daemon/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}},
Expand All @@ -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"}},
Expand Down

0 comments on commit 2e06d4e

Please sign in to comment.