Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exlude invalid IPs when range crosses the third octet #29

Merged
merged 2 commits into from
Feb 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions pkg/ipam/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ func buildAddressesFromRange(ipRangeString string) ([]string, error) {
return nil, fmt.Errorf("unable to parse IP range [%s]", ranges[x])
}


firstIP := IPStr2Int(ipRange[0])
lastIP := IPStr2Int(ipRange[1])
if firstIP > lastIP {
Expand All @@ -255,7 +254,9 @@ func buildAddressesFromRange(ipRangeString string) ([]string, error) {
}

for ip := firstIP; ip <= lastIP; ip++ {
ips = append(ips, IPInt2Str(ip))
if ipInvalid(ip) {
ips = append(ips, IPInt2Str(ip))
}
}

klog.Infof("Rebuilding addresse cache, [%d] addresses exist", len(ips))
Expand All @@ -264,6 +265,14 @@ func buildAddressesFromRange(ipRangeString string) ([]string, error) {
//return ips, nil
}

func ipInvalid(ip uint) bool {
var lastOctet = ip & 0x000000ff
if lastOctet == 0x00 || lastOctet == 0xff {
return false
}
return true
}

func removeDuplicateAddresses(arr []string) []string {
addresses := map[string]bool{}
uniqueAddresses := []string{} // Keep all keys from the map into a slice.
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/loadBalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type kubevipLoadBalancerManager struct {
cloudConfigMap string
}

func newLoadBalancer(kubeClient *kubernetes.Clientset, ns, cm, serviceCidr string) cloudprovider.LoadBalancer {
func newLoadBalancer(kubeClient *kubernetes.Clientset, ns, cm string) cloudprovider.LoadBalancer {
k := &kubevipLoadBalancerManager{
kubeClient: kubeClient,
nameSpace: ns,
Expand Down