Skip to content

Commit 183b384

Browse files
author
Wei Tie
committed
Filter empty strings from uplinks and endpoints
1 parent 056f0a5 commit 183b384

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

netplugin/netd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func initNetPluginConfig(ctx *cli.Context) (*plugin.Config, error) {
9595
}
9696
logrus.Infof("Using netplugin VTEP IP: %v", vtepIP)
9797

98-
vlanUpLinks := strings.Split(ctx.String("vlan-uplinks"), ",")
98+
vlanUpLinks := utils.FilterEmpty(strings.Split(ctx.String("vlan-uplinks"), ","))
9999
if netConfigs.NetworkMode == "vlan" && len(vlanUpLinks) == 0 {
100100
return nil, fmt.Errorf("vlan-uplinks must be set when using VLAN mode")
101101
}

utils/configs.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func ValidateDBOptions(binary string, ctx *cli.Context) (*DBConfigs, error) {
195195
storeDriver = "consul"
196196
storeURLs = consulURLs
197197
}
198-
for _, endpoint := range strings.Split(storeURLs, ",") {
198+
for _, endpoint := range FilterEmpty(strings.Split(storeURLs, ",")) {
199199
_, err := url.Parse(endpoint)
200200
if err != nil {
201201
return nil, fmt.Errorf("invalid %s %v endpoint: %v", binary, storeDriver, endpoint)
@@ -206,6 +206,10 @@ func ValidateDBOptions(binary string, ctx *cli.Context) (*DBConfigs, error) {
206206
break
207207
}
208208

209+
if storeURL == "" {
210+
return nil, fmt.Errorf("invalid %s %s endpoints: empty", binary, storeDriver)
211+
}
212+
209213
return &DBConfigs{
210214
StoreDriver: storeDriver,
211215
StoreURL: storeURL,
@@ -262,3 +266,14 @@ func FlattenFlags(flagSlices ...[]cli.Flag) []cli.Flag {
262266
}
263267
return flags
264268
}
269+
270+
// FilterEmpty filters empty string from string slices
271+
func FilterEmpty(stringSlice []string) []string {
272+
var result []string
273+
for _, str := range stringSlice {
274+
if str != "" {
275+
result = append(result, str)
276+
}
277+
}
278+
return result
279+
}

0 commit comments

Comments
 (0)