Skip to content

Commit 82b3458

Browse files
committed
bugfix: check int type is empty
check int type is empty when do the merge. Signed-off-by: Rudy Zhang <[email protected]>
1 parent 270093c commit 82b3458

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

daemon/config/config.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/alibaba/pouch/pkg/utils"
1818
"github.com/alibaba/pouch/storage/volume"
1919

20+
"github.com/sirupsen/logrus"
2021
"github.com/spf13/pflag"
2122
)
2223

@@ -131,6 +132,10 @@ func (cfg *Config) GetCgroupDriver() string {
131132

132133
// Validate validates the user input config.
133134
func (cfg *Config) Validate() error {
135+
// for debug config file.
136+
b, _ := json.Marshal(cfg)
137+
logrus.Debugf("daemon config: (%s)", string(b))
138+
134139
// deduplicated elements in slice if there is any.
135140
cfg.Listen = utils.DeDuplicate(cfg.Listen)
136141
cfg.Labels = utils.DeDuplicate(cfg.Labels)
@@ -191,9 +196,7 @@ func (cfg *Config) MergeConfigurations(flagSet *pflag.FlagSet) error {
191196
}
192197

193198
// merge configurations from command line flags and config file
194-
err = mergeConfigurations(fileConfig, cfg.delValue(flagSet, fileFlags))
195-
return err
196-
199+
return mergeConfigurations(fileConfig, cfg.delValue(flagSet, fileFlags))
197200
}
198201

199202
// delValue deleles value in config, since we do not do conflict check for slice

pkg/utils/utils.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ func isEmptyValue(v reflect.Value) bool {
122122
switch v.Kind() {
123123
case reflect.Array, reflect.Map, reflect.Slice, reflect.String:
124124
return v.Len() == 0
125+
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
126+
return v.Int() == 0
125127
case reflect.Uintptr:
126128
return v.Uint() == 0
127129
case reflect.Float32, reflect.Float64:

pkg/utils/utils_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func TestMerge(t *testing.T) {
9191
}, {
9292
src: &simple{},
9393
dest: &simple{Sa: 1, Sb: "hello", Sc: true, Sd: map[string]string{"go": "gogo"}, Se: nestS{Na: 22}},
94-
expected: &simple{Sa: 0, Sb: "hello", Sc: false, Sd: map[string]string{"go": "gogo"}, Se: nestS{Na: 0}},
94+
expected: &simple{Sa: 1, Sb: "hello", Sc: false, Sd: map[string]string{"go": "gogo"}, Se: nestS{Na: 22}},
9595
ok: true,
9696
}, {
9797
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) {
101101
}, {
102102
src: &simple{Sa: 0, Sc: false, Sd: map[string]string{"go": "gogo"}, Se: nestS{Na: 11}, Sf: []string{"foo"}},
103103
dest: &simple{Sa: 2, Sb: "world", Sc: true, Sd: map[string]string{"go": "old"}, Se: nestS{Na: 22}, Sf: []string{"foo"}},
104-
expected: &simple{Sa: 0, Sb: "world", Sc: false, Sd: map[string]string{"go": "gogo"}, Se: nestS{Na: 11}, Sf: []string{"foo", "foo"}},
104+
expected: &simple{Sa: 2, Sb: "world", Sc: false, Sd: map[string]string{"go": "gogo"}, Se: nestS{Na: 11}, Sf: []string{"foo", "foo"}},
105105
ok: true,
106106
}, {
107107
src: &simple{Sd: map[string]string{"go": "gogo", "a": "b"}},

0 commit comments

Comments
 (0)