Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: check int type is empty #2235

Merged
merged 1 commit into from
Sep 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why split return mergeConfigurations into err = ... ; return err before?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because the caller will check the error, no need to check before return

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