Skip to content

Commit

Permalink
Merge pull request #126 from hhyasdf/release/for-v0.3.2
Browse files Browse the repository at this point in the history
release for v0.3.2
  • Loading branch information
mars1024 authored Nov 30, 2021
2 parents 943f741 + a5191cf commit 0beeab2
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 35 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,11 @@ All notable changes to this project will be documented in this file.

### Fixed Issues
- Avoid permanent exit of arp proxy on large-scale clusters

## v0.3.2
### Improvements
- Short-circuit terminating pods before enqueuing in manager controller

### Fixed Issues
- Fix ipv6 address range calculation error
- Fix nil point dereference error while creating a vlan interface
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/mdlayher/ethernet v0.0.0-20190606142754-0394541c37b7
github.com/mdlayher/ndp v0.0.0-20200602162440-17ab9e3e5567
github.com/mdlayher/raw v0.0.0-20190606142536-fef19f00fc18
github.com/mikioh/ipaddr v0.0.0-20190404000644-d465c8ab6721
github.com/parnurzeal/gorequest v0.2.16
github.com/pkg/errors v0.8.1
github.com/prometheus/client_golang v1.0.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ github.com/mesos/mesos-go v0.0.9/go.mod h1:kPYCMQ9gsOXVAle1OsoY4I1+9kPu8GHkf88aV
github.com/mholt/certmagic v0.6.2-0.20190624175158-6a42ef9fe8c2/go.mod h1:g4cOPxcjV0oFq3qwpjSA30LReKD8AoIfwAY9VvG35NY=
github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/miekg/dns v1.1.4/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/mikioh/ipaddr v0.0.0-20190404000644-d465c8ab6721 h1:RlZweED6sbSArvlE924+mUcZuXKLBHA35U7LN621Bws=
github.com/mikioh/ipaddr v0.0.0-20190404000644-d465c8ab6721/go.mod h1:Ickgr2WtCLZ2MDGd4Gr0geeCH5HybhRJbonOgQpvSxc=
github.com/mindprince/gonvml v0.0.0-20190828220739-9ebdce4bb989/go.mod h1:2eu9pRWp8mo84xCg6KswZ+USQHjwgRhNp06sozOdsTY=
github.com/mistifyio/go-zfs v2.1.1+incompatible/go.mod h1:8AuVvqP/mXw1px98n46wfvcGfQ4ci2FwoAjKYxuo3Z4=
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
Expand Down
6 changes: 6 additions & 0 deletions pkg/controller/ipam/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ func (c *Controller) updatePod(oldObj, newObj interface{}) {
return
}

// short-circuit terminating pods because ip instances will be
// recycled asynchronously
if new.DeletionTimestamp != nil {
return
}

c.enqueuePod(new)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/daemon/containernetwork/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func EnsureVlanIf(nodeIfName string, vlanID *uint32) (string, error) {
return "", fmt.Errorf("failed to ensure bridge: %v", err)
}

// find the vlan interface to attach to bridge, create if not exist
// create the vlan interface if not exist
var vlanIf netlink.Link
if vlanIf, err = netlink.LinkByName(vlanIfName); err != nil {
if vlanIfName == nodeIfName {
Expand All @@ -90,7 +90,7 @@ func EnsureVlanIf(nodeIfName string, vlanID *uint32) (string, error) {
vif.ParentIndex = nodeIf.Attrs().Index
vif.Name = vlanIfName

err = netlink.LinkAdd(vlanIf)
err = netlink.LinkAdd(vif)
if err != nil {
return vlanIfName, err
}
Expand Down
44 changes: 11 additions & 33 deletions pkg/daemon/utils/ip_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ package utils

import (
"fmt"
"math/big"
"net"
"sort"

"github.com/mikioh/ipaddr"

"github.com/containernetworking/plugins/pkg/ip"
)

Expand Down Expand Up @@ -171,20 +172,16 @@ func (ir *IPRange) splitIPRangeToIPBlocks() []*net.IPNet {
}

func calculateIPLastZeroBits(ip net.IP) int {
zeroBits := 0
for {
nextPossibleZeroBits := zeroBits + 1
ipInt := ipToInt(ip)
ipUint64 := ipInt.Uint64()
testMaskBits := net.IPv4len * 8
if ip.To4() == nil {
testMaskBits = net.IPv6len * 8
}

if ipUint64 == (ipUint64>>nextPossibleZeroBits)<<nextPossibleZeroBits {
zeroBits = nextPossibleZeroBits
} else {
break
}
zeroBits := 0
for ; !ip.Mask(net.CIDRMask(zeroBits, testMaskBits)).Equal(ip); zeroBits++ {
}

return zeroBits
return testMaskBits - zeroBits
}

func findTheFirstLargestCidr(start, end net.IP) (*net.IPNet, net.IP) {
Expand Down Expand Up @@ -218,26 +215,7 @@ func findTheFirstLargestCidr(start, end net.IP) (*net.IPNet, net.IP) {
}
}

func ipToInt(ip net.IP) *big.Int {
if v := ip.To4(); v != nil {
return big.NewInt(0).SetBytes(v)
}
return big.NewInt(0).SetBytes(ip.To16())
}

func intToIP(i *big.Int) net.IP {
return i.Bytes()
}

func LastIP(cidr *net.IPNet) net.IP {
cidrPrefixLen, ipLen := cidr.Mask.Size()

if cidrPrefixLen == ipLen {
return cidr.IP
}

cidrEndIPInt := ipToInt(cidr.IP)
cidrEndIPInt.Add(cidrEndIPInt, big.NewInt(1<<(ipLen-cidrPrefixLen)-1))

return intToIP(cidrEndIPInt)
cur := ipaddr.NewCursor([]ipaddr.Prefix{*ipaddr.NewPrefix(cidr)})
return cur.Last().IP
}
58 changes: 58 additions & 0 deletions pkg/daemon/utils/ip_range_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ type TestSubnetSpec struct {
excludeIPs []net.IP

expectIPBlocks []*net.IPNet
lastIP net.IP
}

type TestIPSpec struct {
addr net.IP
lastZeroBits int
}

func TestFindSubnetExcludeIPBlocks(t *testing.T) {
Expand Down Expand Up @@ -260,6 +266,58 @@ func TestFindSubnetExcludeIPBlocks(t *testing.T) {
}
}

func TestLastIP(t *testing.T) {
testCases := []TestSubnetSpec{
{
cidr: &net.IPNet{
IP: net.ParseIP("192.168.3.0"),
Mask: net.CIDRMask(24, 32),
},
lastIP: net.ParseIP("192.168.3.255"),
}, {
cidr: &net.IPNet{
IP: net.ParseIP("2021:23::"),
Mask: net.CIDRMask(64, 128),
},
lastIP: net.ParseIP("2021:23::ffff:ffff:ffff:ffff"),
},
}

for index, test := range testCases {
lastIP := LastIP(test.cidr)

if !lastIP.Equal(test.lastIP) {
t.Fatalf("failed to parse case %v cidr %v, result last ip: %v", index, test.cidr.String(), lastIP)
}
}
}

func TestZeroBits(t *testing.T) {
testCases := []TestIPSpec{
{
addr: net.ParseIP("192.168.3.0"),
lastZeroBits: 8,
}, {
addr: net.ParseIP("2021:23::"),
lastZeroBits: 96,
}, {
addr: net.ParseIP("2021:23::ffff"),
lastZeroBits: 0,
}, {
addr: net.ParseIP("192.168.3.1"),
lastZeroBits: 0,
},
}

for index, test := range testCases {
lastZeroBits := calculateIPLastZeroBits(test.addr)

if lastZeroBits != test.lastZeroBits {
t.Fatalf("failed to parse case %v addr %v, result last zero bits: %v", index, test.addr, lastZeroBits)
}
}
}

func (ts *TestSubnetSpec) String() string {
return fmt.Sprintf("cidr: %v, includedIPRanges: %v, gateway: %v, excludeIPs: %v",
ts.cidr.String(), ts.includedRanges, ts.gateway.String(), ts.excludeIPs)
Expand Down

0 comments on commit 0beeab2

Please sign in to comment.