Skip to content

Commit d9c2a77

Browse files
authored
Replace inet.af/netaddr with net/netip (#2987)
1 parent 14dda07 commit d9c2a77

File tree

5 files changed

+36
-50
lines changed

5 files changed

+36
-50
lines changed

go.mod

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ require (
1818
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac
1919
gomodules.xyz/jsonpatch/v2 v2.2.0
2020
helm.sh/helm/v3 v3.6.1
21-
inet.af/netaddr v0.0.0-20211027220019-c74959edd3b6
2221
k8s.io/api v0.21.4
2322
k8s.io/apimachinery v0.21.4
2423
k8s.io/cli-runtime v0.21.2
@@ -137,8 +136,6 @@ require (
137136
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
138137
go.uber.org/atomic v1.7.0 // indirect
139138
go.uber.org/multierr v1.6.0 // indirect
140-
go4.org/intern v0.0.0-20211027215823-ae77deb06f29 // indirect
141-
go4.org/unsafe/assume-no-moving-gc v0.0.0-20220617031537-928513b29760 // indirect
142139
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
143140
golang.org/x/net v0.1.0 // indirect
144141
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect

go.sum

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ github.com/docker/libtrust v0.0.0-20150114040149-fa567046d9b1/go.mod h1:cyGadeNE
201201
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
202202
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
203203
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
204-
github.com/dvyukov/go-fuzz v0.0.0-20210103155950-6a8e9d1f2415/go.mod h1:11Gm+ccJnvAhCNLlf5+cS9KjtbaD5I5zaZpFMsTHWTw=
205204
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
206205
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
207206
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
@@ -858,11 +857,6 @@ go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
858857
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
859858
go.uber.org/zap v1.19.0 h1:mZQZefskPPCMIBCSEH0v2/iUqqLrYtaeqwD6FUGUnFE=
860859
go.uber.org/zap v1.19.0/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI=
861-
go4.org/intern v0.0.0-20211027215823-ae77deb06f29 h1:UXLjNohABv4S58tHmeuIZDO6e3mHpW2Dx33gaNt03LE=
862-
go4.org/intern v0.0.0-20211027215823-ae77deb06f29/go.mod h1:cS2ma+47FKrLPdXFpr7CuxiTW3eyJbWew4qx0qtQWDA=
863-
go4.org/unsafe/assume-no-moving-gc v0.0.0-20211027215541-db492cf91b37/go.mod h1:FftLjUGFEDu5k8lt0ddY+HcrH/qU/0qk+H8j9/nTl3E=
864-
go4.org/unsafe/assume-no-moving-gc v0.0.0-20220617031537-928513b29760 h1:FyBZqvoA/jbNzuAWLQE2kG820zMAkcilx6BMjGbL/E4=
865-
go4.org/unsafe/assume-no-moving-gc v0.0.0-20220617031537-928513b29760/go.mod h1:FftLjUGFEDu5k8lt0ddY+HcrH/qU/0qk+H8j9/nTl3E=
866860
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
867861
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
868862
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
@@ -1249,8 +1243,6 @@ honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWh
12491243
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
12501244
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
12511245
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
1252-
inet.af/netaddr v0.0.0-20211027220019-c74959edd3b6 h1:acCzuUSQ79tGsM/O50VRFySfMm19IoMKL+sZztZkCxw=
1253-
inet.af/netaddr v0.0.0-20211027220019-c74959edd3b6/go.mod h1:y3MGhcFMlh0KZPMuXXow8mpjxxAk3yoDNsp4cQz54i8=
12541246
k8s.io/api v0.21.0/go.mod h1:+YbrhBBGgsxbF6o6Kj4KJPJnBmAKuXDeS3E18bgHNVU=
12551247
k8s.io/api v0.21.2/go.mod h1:Lv6UGJZ1rlMI1qusN8ruAp9PUBFyBwpEHAdG24vIsiU=
12561248
k8s.io/api v0.21.4 h1:WtDkzTAuI31WZKDPeIYpEUA+WeUfXAmA7gwj6nzFfbc=

pkg/networking/utils.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@ package networking
33
import (
44
awssdk "github.com/aws/aws-sdk-go/aws"
55
ec2sdk "github.com/aws/aws-sdk-go/service/ec2"
6-
"inet.af/netaddr"
76
"net/netip"
87
)
98

10-
// TODO: replace netaddr package with built-in netip package once golang 1.18 released: https://pkg.go.dev/net/netip@master#Prefix
11-
129
// ParseCIDRs will parse CIDRs in string format into parsed IPPrefix
13-
func ParseCIDRs(cidrs []string) ([]netaddr.IPPrefix, error) {
14-
var ipPrefixes []netaddr.IPPrefix
10+
func ParseCIDRs(cidrs []string) ([]netip.Prefix, error) {
11+
var ipPrefixes []netip.Prefix
1512
for _, cidr := range cidrs {
16-
ipPrefix, err := netaddr.ParseIPPrefix(cidr)
13+
ipPrefix, err := netip.ParsePrefix(cidr)
1714
if err != nil {
1815
return nil, err
1916
}
@@ -23,7 +20,7 @@ func ParseCIDRs(cidrs []string) ([]netaddr.IPPrefix, error) {
2320
}
2421

2522
// IsIPWithinCIDRs checks whether specific IP is in IPv4 CIDR or IPv6 CIDRs.
26-
func IsIPWithinCIDRs(ip netaddr.IP, cidrs []netaddr.IPPrefix) bool {
23+
func IsIPWithinCIDRs(ip netip.Addr, cidrs []netip.Prefix) bool {
2724
for _, cidr := range cidrs {
2825
if cidr.Contains(ip) {
2926
return true

pkg/networking/utils_test.go

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
ec2sdk "github.com/aws/aws-sdk-go/service/ec2"
66
"github.com/pkg/errors"
77
"github.com/stretchr/testify/assert"
8-
"inet.af/netaddr"
8+
99
"net/netip"
1010
"testing"
1111
)
@@ -17,34 +17,34 @@ func TestParseCIDRs(t *testing.T) {
1717
tests := []struct {
1818
name string
1919
args args
20-
want []netaddr.IPPrefix
20+
want []netip.Prefix
2121
wantErr error
2222
}{
2323
{
2424
name: "has one valid CIDR",
2525
args: args{
2626
cidrs: []string{"192.168.5.100/16"},
2727
},
28-
want: []netaddr.IPPrefix{
29-
netaddr.MustParseIPPrefix("192.168.5.100/16"),
28+
want: []netip.Prefix{
29+
netip.MustParsePrefix("192.168.5.100/16"),
3030
},
3131
},
3232
{
3333
name: "has multiple valid CIDRs",
3434
args: args{
3535
cidrs: []string{"192.168.5.100/16", "10.100.0.0/16"},
3636
},
37-
want: []netaddr.IPPrefix{
38-
netaddr.MustParseIPPrefix("192.168.5.100/16"),
39-
netaddr.MustParseIPPrefix("10.100.0.0/16"),
37+
want: []netip.Prefix{
38+
netip.MustParsePrefix("192.168.5.100/16"),
39+
netip.MustParsePrefix("10.100.0.0/16"),
4040
},
4141
},
4242
{
4343
name: "has one invalid CIDR",
4444
args: args{
4545
cidrs: []string{"192.168.5.100/16", "10.100.0.0"},
4646
},
47-
wantErr: errors.New("netaddr.ParseIPPrefix(\"10.100.0.0\"): no '/'"),
47+
wantErr: errors.New("netip.ParsePrefix(\"10.100.0.0\"): no '/'"),
4848
},
4949
{
5050
name: "empty CIDRs",
@@ -76,8 +76,8 @@ func TestParseCIDRs(t *testing.T) {
7676

7777
func TestIsIPWithinCIDRs(t *testing.T) {
7878
type args struct {
79-
ip netaddr.IP
80-
cidrs []netaddr.IPPrefix
79+
ip netip.Addr
80+
cidrs []netip.Prefix
8181
}
8282
tests := []struct {
8383
name string
@@ -87,47 +87,47 @@ func TestIsIPWithinCIDRs(t *testing.T) {
8787
{
8888
name: "ipv4 address within CIDRs",
8989
args: args{
90-
ip: netaddr.MustParseIP("192.168.1.42"),
91-
cidrs: []netaddr.IPPrefix{
92-
netaddr.MustParseIPPrefix("10.100.0.0/16"),
93-
netaddr.MustParseIPPrefix("192.168.0.0/16"),
94-
netaddr.MustParseIPPrefix("2600:1f14:f8c:2700::/56"),
90+
ip: netip.MustParseAddr("192.168.1.42"),
91+
cidrs: []netip.Prefix{
92+
netip.MustParsePrefix("10.100.0.0/16"),
93+
netip.MustParsePrefix("192.168.0.0/16"),
94+
netip.MustParsePrefix("2600:1f14:f8c:2700::/56"),
9595
},
9696
},
9797
want: true,
9898
},
9999
{
100100
name: "ipv4 address not within CIDRs",
101101
args: args{
102-
ip: netaddr.MustParseIP("172.16.1.42"),
103-
cidrs: []netaddr.IPPrefix{
104-
netaddr.MustParseIPPrefix("10.100.0.0/16"),
105-
netaddr.MustParseIPPrefix("192.168.0.0/16"),
106-
netaddr.MustParseIPPrefix("2600:1f14:f8c:2700::/56"),
102+
ip: netip.MustParseAddr("172.16.1.42"),
103+
cidrs: []netip.Prefix{
104+
netip.MustParsePrefix("10.100.0.0/16"),
105+
netip.MustParsePrefix("192.168.0.0/16"),
106+
netip.MustParsePrefix("2600:1f14:f8c:2700::/56"),
107107
},
108108
},
109109
want: false,
110110
},
111111
{
112112
name: "ipv6 address within CIDRs",
113113
args: args{
114-
ip: netaddr.MustParseIP("2600:1f14:f8c:2701:a740::"),
115-
cidrs: []netaddr.IPPrefix{
116-
netaddr.MustParseIPPrefix("10.100.0.0/16"),
117-
netaddr.MustParseIPPrefix("2700:1f14:f8c:2700::/56"),
118-
netaddr.MustParseIPPrefix("2600:1f14:f8c:2700::/56"),
114+
ip: netip.MustParseAddr("2600:1f14:f8c:2701:a740::"),
115+
cidrs: []netip.Prefix{
116+
netip.MustParsePrefix("10.100.0.0/16"),
117+
netip.MustParsePrefix("2700:1f14:f8c:2700::/56"),
118+
netip.MustParsePrefix("2600:1f14:f8c:2700::/56"),
119119
},
120120
},
121121
want: true,
122122
},
123123
{
124124
name: "ipv6 address not within CIDRs",
125125
args: args{
126-
ip: netaddr.MustParseIP("2800:1f14:f8c:2701:a740::"),
127-
cidrs: []netaddr.IPPrefix{
128-
netaddr.MustParseIPPrefix("10.100.0.0/16"),
129-
netaddr.MustParseIPPrefix("2700:1f14:f8c:2700::/56"),
130-
netaddr.MustParseIPPrefix("2600:1f14:f8c:2700::/56"),
126+
ip: netip.MustParseAddr("2800:1f14:f8c:2701:a740::"),
127+
cidrs: []netip.Prefix{
128+
netip.MustParsePrefix("10.100.0.0/16"),
129+
netip.MustParsePrefix("2700:1f14:f8c:2700::/56"),
130+
netip.MustParsePrefix("2600:1f14:f8c:2700::/56"),
131131
},
132132
},
133133
want: false,

pkg/targetgroupbinding/resource_manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7-
"inet.af/netaddr"
7+
"net/netip"
88
"time"
99

1010
"k8s.io/client-go/tools/record"
@@ -389,7 +389,7 @@ func (m *defaultResourceManager) registerPodEndpoints(ctx context.Context, tgARN
389389
Id: awssdk.String(endpoint.IP),
390390
Port: awssdk.Int64(endpoint.Port),
391391
}
392-
podIP, err := netaddr.ParseIP(endpoint.IP)
392+
podIP, err := netip.ParseAddr(endpoint.IP)
393393
if err != nil {
394394
return err
395395
}

0 commit comments

Comments
 (0)