diff --git a/plugins/ipam/k8s.go b/plugins/ipam/k8s.go index edad637..7644bad 100644 --- a/plugins/ipam/k8s.go +++ b/plugins/ipam/k8s.go @@ -73,12 +73,6 @@ func NewK8sClient(namespace string, subnetNames []string) K8sClient { } func (k K8sClient) createIpamIP(ipaddr net.IP, mac net.HardwareAddr) error { - ip, err := ipamv1alpha1.IPAddrFromString(ipaddr.String()) - if err != nil { - err = errors.Wrapf(err, "Failed to parse IP %s", ip) - return err - } - // select the subnet matching the CIDR of the request subnetMatch := false for _, subnetName := range k.SubnetNames { @@ -90,7 +84,7 @@ func (k K8sClient) createIpamIP(ipaddr net.IP, mac net.HardwareAddr) error { subnetMatch = true var ipamIP *ipamv1alpha1.IP - ipamIP, err = k.prepareCreateIpamIP(subnetName, ipaddr, mac) + ipamIP, err := k.prepareCreateIpamIP(subnetName, ipaddr, mac) if err != nil { return err } @@ -105,7 +99,7 @@ func (k K8sClient) createIpamIP(ipaddr net.IP, mac net.HardwareAddr) error { } if !subnetMatch { - log.Warningf("No matching subnet found for IP %s/%s", k.Namespace, ip) + log.Warningf("No matching subnet found for IP %s/%s", k.Namespace, ipaddr) } return nil @@ -138,6 +132,11 @@ func (k K8sClient) getMatchingSubnet(subnetName string, ipaddr net.IP) *ipamv1al func (k K8sClient) prepareCreateIpamIP(subnetName string, ipaddr net.IP, mac net.HardwareAddr) (*ipamv1alpha1.IP, error) { ip, err := ipamv1alpha1.IPAddrFromString(ipaddr.String()) + if err != nil { + err = errors.Wrapf(err, "Failed to parse IP %s", ipaddr) + return nil, err + } + // a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and // must start and end with an alphanumeric character. // 2001:abcd:abcd::1 will become 2001-abcd-abcd-0000-0000-0000-0000-00001