diff --git a/pkg/controller/vmnetcfg/controller.go b/pkg/controller/vmnetcfg/controller.go index 7b7e428..f19c624 100644 --- a/pkg/controller/vmnetcfg/controller.go +++ b/pkg/controller/vmnetcfg/controller.go @@ -3,6 +3,7 @@ package vmnetcfg import ( "context" "fmt" + "net" "reflect" "github.com/rancher/wrangler/pkg/kv" @@ -16,7 +17,6 @@ import ( ctlnetworkv1 "github.com/harvester/vm-dhcp-controller/pkg/generated/controllers/network.harvesterhci.io/v1alpha1" "github.com/harvester/vm-dhcp-controller/pkg/ipam" "github.com/harvester/vm-dhcp-controller/pkg/metrics" - "github.com/harvester/vm-dhcp-controller/pkg/util" ) const controllerName = "vm-dhcp-vmnetcfg-controller" @@ -177,7 +177,7 @@ func (h *Handler) Allocate(vmNetCfg *networkv1.VirtualMachineNetworkConfig, stat // Allocate new IP - dIP := util.UnspecifiedIPAddress + dIP := net.IPv4zero.String() if nc.IPAddress != nil { dIP = *nc.IPAddress } @@ -329,7 +329,7 @@ func findIPAddressFromNetworkConfigStatusByMACAddress(ncStatuses []networkv1.Net return ncStatus.AllocatedIPAddress, nil } } - return util.UnspecifiedIPAddress, fmt.Errorf("could not find allocated ip for mac %s", macAddress) + return net.IPv4zero.String(), fmt.Errorf("could not find allocated ip for mac %s", macAddress) } func updateAllNetworkConfigState(ncStatuses []networkv1.NetworkConfigStatus) { diff --git a/pkg/ipam/ipam.go b/pkg/ipam/ipam.go index ac393dd..877322e 100644 --- a/pkg/ipam/ipam.go +++ b/pkg/ipam/ipam.go @@ -7,7 +7,6 @@ import ( "strconv" "sync" - "github.com/harvester/vm-dhcp-controller/pkg/util" "github.com/sirupsen/logrus" ) @@ -110,7 +109,7 @@ func (a *IPAllocator) AllocateIP(name string, ipAddress string) (string, error) return "", fmt.Errorf("network %s does not exist", name) } if ipAddress == "" { - ipAddress = util.UnspecifiedIPAddress + ipAddress = net.IPv4zero.String() } designatedIP := net.ParseIP(ipAddress) @@ -119,7 +118,7 @@ func (a *IPAllocator) AllocateIP(name string, ipAddress string) (string, error) ok := a.ipam[name].ipNet.Contains(designatedIP) if !ok { subnetMask, _ := a.ipam[name].ipNet.Mask.Size() - return util.UnspecifiedIPAddress, fmt.Errorf( + return net.IPv4zero.String(), fmt.Errorf( "designated ip %s is not in subnet %s/%d", designatedIP.String(), a.ipam[name].ipNet.IP.String(), @@ -128,7 +127,7 @@ func (a *IPAllocator) AllocateIP(name string, ipAddress string) (string, error) } if a.ipam[name].broadcast.Equal(designatedIP) { - return util.UnspecifiedIPAddress, fmt.Errorf("designated ip %s equals broadcast ip address %s", designatedIP.String(), a.ipam[name].broadcast.String()) + return net.IPv4zero.String(), fmt.Errorf("designated ip %s equals broadcast ip address %s", designatedIP.String(), a.ipam[name].broadcast.String()) } } @@ -136,7 +135,7 @@ func (a *IPAllocator) AllocateIP(name string, ipAddress string) (string, error) if !designatedIP.IsUnspecified() { if ip == designatedIP.String() { if isAllocated { - return util.UnspecifiedIPAddress, fmt.Errorf("designated ip %s is already allocated", designatedIP.String()) + return net.IPv4zero.String(), fmt.Errorf("designated ip %s is already allocated", designatedIP.String()) } else { a.ipam[name].ips[ip] = true return ip, nil @@ -150,7 +149,7 @@ func (a *IPAllocator) AllocateIP(name string, ipAddress string) (string, error) } } - return util.UnspecifiedIPAddress, fmt.Errorf("no more ip addresses left in network %s ipam", name) + return net.IPv4zero.String(), fmt.Errorf("no more ip addresses left in network %s ipam", name) } func (a *IPAllocator) DeallocateIP(name, ipAddress string) error { diff --git a/pkg/util/common.go b/pkg/util/common.go index 2a9cc6e..553c632 100644 --- a/pkg/util/common.go +++ b/pkg/util/common.go @@ -3,7 +3,3 @@ package util const ( ExcludedMark = "EXCLUDED" ) - -var ( - UnspecifiedIPAddress = "0.0.0.0" -)