Skip to content

Commit

Permalink
static ipam: decide wrong cidr error msg
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Duarte Barroso <mdbarroso@redhat.com>
  • Loading branch information
maiqueb committed Jun 25, 2021
1 parent 0db5882 commit a786b12
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions plugins/ipam/static/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func LoadIPAMConfig(bytes []byte, envArgs string) (*IPAMConfig, string, error) {

ip, subnet, err := net.ParseCIDR(ipstr)
if err != nil {
return nil, "", err
return nil, "", fmt.Errorf("the 'ip' field is expected to be in CIDR notation, got: '%s'", ipstr)
}

addr := Address{
Expand Down Expand Up @@ -213,7 +213,8 @@ func LoadIPAMConfig(bytes []byte, envArgs string) (*IPAMConfig, string, error) {
for i := range n.IPAM.Addresses {
ip, addr, err := net.ParseCIDR(n.IPAM.Addresses[i].AddressStr)
if err != nil {
return nil, "", err
return nil, "", fmt.Errorf(
"the 'address' field is expected to be in CIDR notation, got: '%s'", n.IPAM.Addresses[i].AddressStr)
}
n.IPAM.Addresses[i].Address = *addr
n.IPAM.Addresses[i].Address.IP = ip
Expand Down
4 changes: 2 additions & 2 deletions plugins/ipam/static/static_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,8 @@ var _ = Describe("static Operations", func() {
_, _, err := testutils.CmdAddWithArgs(args, func() error {
return cmdAdd(args)
})
Expect(err).Should(
MatchError(fmt.Sprintf("invalid CIDR address: %s", ipStr)))
Expect(err).Should(MatchError(
fmt.Sprintf("the 'address' field is expected to be in CIDR notation, got: '%s'", ipStr)))
})
}
})
Expand Down

0 comments on commit a786b12

Please sign in to comment.