Skip to content

Commit

Permalink
fix: manual static ip allocation and automatic allocation should use …
Browse files Browse the repository at this point in the history
…different ip validation
  • Loading branch information
oilbeater committed May 27, 2019
1 parent e7b47b1 commit f8e8b00
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pkg/util/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,17 @@ func ValidateLogicalSwitch(annotations map[string]string) error {

func ValidatePodNetwork(annotations map[string]string) error {
if ip := annotations[IpAddressAnnotation]; ip != "" {
_, _, err := net.ParseCIDR(ip)
if err != nil {
return fmt.Errorf("%s is not a valid %s", ip, IpAddressAnnotation)
if strings.Contains(ip, "/") {
_, _, err := net.ParseCIDR(ip)
if err != nil {
return fmt.Errorf("%s is not a valid %s", ip, IpAddressAnnotation)
}
} else {
if net.ParseIP(ip) == nil {
return fmt.Errorf("%s is not a valid %s", ip, IpAddressAnnotation)
}
}

}

mac := annotations[MacAddressAnnotation]
Expand All @@ -99,7 +106,7 @@ func ValidatePodNetwork(annotations map[string]string) error {
ipPool := annotations[IpPoolAnnotation]
if ipPool != "" {
for _, ip := range strings.Split(ipPool, ",") {
if net.ParseIP(ip) == nil {
if net.ParseIP(strings.TrimSpace(ip)) == nil {
return fmt.Errorf("%s in %s is not a valid address", ip, IpPoolAnnotation)
}
}
Expand Down

0 comments on commit f8e8b00

Please sign in to comment.