Skip to content

Commit 8e6f843

Browse files
authored
Handle unavailability of limits (#80)
Sometimes, the AWS API does not know about an instance type that should exist, so lets make sure to always do "something" and not block all pods and network activity.
1 parent 7d4634d commit 8e6f843

6 files changed

Lines changed: 31 additions & 10 deletions

File tree

aws/allocate.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package aws
22

33
import (
44
"fmt"
5+
"log"
56
"net"
67
"sort"
78
"time"
@@ -41,7 +42,7 @@ func (c *allocateClient) AllocateIPsOn(intf Interface, batchSize int64) ([]*Allo
4142

4243
limits, err := c.aws.ENILimits()
4344
if err != nil {
44-
return nil, err
45+
log.Printf("unable to determine AWS limits, using fallback %v", err)
4546
}
4647
available := limits.IPv4 - int64(len(intf.IPv4s))
4748

@@ -108,7 +109,7 @@ func (c *allocateClient) AllocateIPsFirstAvailableAtIndex(index int, batchSize i
108109
}
109110
limits, err := c.aws.ENILimits()
110111
if err != nil {
111-
return nil, err
112+
log.Printf("unable to determine AWS limits, using fallback %v", err)
112113
}
113114

114115
var candidates []Interface

aws/interface.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package aws
22

33
import (
44
"fmt"
5+
"log"
56
"net"
67
"os"
78
"sort"
@@ -59,7 +60,7 @@ func (c *interfaceClient) NewInterfaceOnSubnetAtIndex(index int, secGrps []strin
5960
// Subtract 1 to Account for primary IP
6061
limits, err := c.aws.ENILimits()
6162
if err != nil {
62-
return nil, err
63+
log.Printf("unable to determine AWS limits, using fallback %v", err)
6364
}
6465

6566
// batch size 0 conventionally means "request the limit"
@@ -175,7 +176,7 @@ func (c *interfaceClient) NewInterface(secGrps []string, requiredTags map[string
175176

176177
limits, err := c.aws.ENILimits()
177178
if err != nil {
178-
return nil, err
179+
log.Printf("unable to determine AWS limits, using fallback %v", err)
179180
}
180181
if int64(len(existingInterfaces)) >= limits.Adapters {
181182
return nil, fmt.Errorf("too many adapters on this instance already")

aws/limits.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ type LimitsClient interface {
2222
ENILimits() (*ENILimit, error)
2323
}
2424

25+
var defaultLimit = ENILimit{
26+
Adapters: 4,
27+
IPv4: 15,
28+
IPv6: 15,
29+
}
30+
2531
// ENILimitsForInstanceType returns the limits for ENI for an instance type
2632
func (c *awsclient) ENILimitsForInstanceType(itype string) (*ENILimit, error) {
2733
client, err := c.newEC2()
@@ -55,7 +61,7 @@ func (c *awsclient) ENILimitsForInstanceType(itype string) (*ENILimit, error) {
5561
func (c *awsclient) ENILimits() (*ENILimit, error) {
5662
id, err := c.getIDDoc()
5763
if err != nil || id == nil {
58-
return nil, errors.Wrap(err, "unable get instance identity doc")
64+
return &defaultLimit, errors.Wrap(err, "unable get instance identity doc")
5965
}
6066

6167
// Use the instance type in the cache key in case at some point the cache dir is persisted across reboots
@@ -68,7 +74,7 @@ func (c *awsclient) ENILimits() (*ENILimit, error) {
6874

6975
limit, err = c.ENILimitsForInstanceType(id.InstanceType)
7076
if err != nil {
71-
return nil, errors.Wrap(err, "unable get instance network limits")
77+
return &defaultLimit, errors.Wrap(err, "unable get instance network limits")
7278
}
7379

7480
cache.Store(key, 24*time.Hour, limit)

cmd/cni-ipvlan-vpc-k8s-tool/cni-ipvlan-vpc-k8s-tool.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,14 @@ func actionLimits(c *cli.Context) error {
174174

175175
func actionMaxPods(c *cli.Context) error {
176176
limit, err := aws.DefaultClient.ENILimits()
177+
retErr := c.Bool("return-error")
177178
if err != nil {
178-
return err
179+
if retErr {
180+
return err
181+
}
182+
fmt.Fprintf(os.Stderr, "unable to determine ENI limit due to '%v', defaulting max pods to 110", err)
183+
fmt.Printf("%d\n", 110)
184+
return nil
179185
}
180186
specifiedMax := int64(c.Int("max"))
181187
max := (limit.Adapters - 1) * limit.IPv4

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.13
55
require (
66
github.com/Microsoft/go-winio v0.4.11
77
github.com/alecthomas/units v0.0.0-20190910110746-680d30ca3117 // indirect
8-
github.com/aws/aws-sdk-go v1.28.1
8+
github.com/aws/aws-sdk-go v1.29.27
99
github.com/containernetworking/cni v0.6.0
1010
github.com/containernetworking/plugins v0.7.4
1111
github.com/coreos/go-iptables v0.4.0
@@ -19,11 +19,11 @@ require (
1919
github.com/j-keck/arping v0.0.0-20160618110441-2cf9dc699c56
2020
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af
2121
github.com/nightlyone/lockfile v0.0.0-20180618180623-0ad87eef1443
22-
github.com/pkg/errors v0.8.1
22+
github.com/pkg/errors v0.9.1
2323
github.com/urfave/cli v1.20.0
2424
github.com/vishvananda/netlink v1.0.0
2525
github.com/vishvananda/netns v0.0.0-20180720170159-13995c7128cc
26-
golang.org/x/net v0.0.0-20190620200207-3b0461eec859
26+
golang.org/x/net v0.0.0-20200202094626-16171245cfb2
2727
golang.org/x/sys v0.0.0-20190312061237-fead79001313
2828
gopkg.in/alecthomas/gometalinter.v2 v2.0.12 // indirect
2929
gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c // indirect

go.sum

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ github.com/alecthomas/units v0.0.0-20190910110746-680d30ca3117 h1:aUo+WrWZtRRfc6
88
github.com/alecthomas/units v0.0.0-20190910110746-680d30ca3117/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
99
github.com/aws/aws-sdk-go v1.28.1 h1:aWBD5EJrmGFuHFn9ZdaHqWWZGZYQ5Gzb3j9G0RppLpY=
1010
github.com/aws/aws-sdk-go v1.28.1/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
11+
github.com/aws/aws-sdk-go v1.29.27 h1:4A53lDDGtk4TvnXFzvcOO3Vx3tDqEPfwvChhhxTPN/M=
12+
github.com/aws/aws-sdk-go v1.29.27/go.mod h1:1KvfttTE3SPKMpo8g2c6jL3ZKfXtFvKscTgahTma5Xg=
1113
github.com/containernetworking/cni v0.6.0 h1:FXICGBZNMtdHlW65trpoHviHctQD3seWhRRcqp2hMOU=
1214
github.com/containernetworking/cni v0.6.0/go.mod h1:LGwApLUm2FpoOfxTDEeq8T9ipbpZ61X79hmU3w8FmsY=
1315
github.com/containernetworking/plugins v0.7.4 h1:ugkuXfg1Pdzm54U5DGMzreYIkZPSCmSq4rm5TIXVICA=
@@ -35,6 +37,7 @@ github.com/go-ini/ini v1.39.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3I
3537
github.com/go-lintpack/lintpack v0.5.2 h1:DI5mA3+eKdWeJ40nU4d6Wc26qmdG8RCi/btYq0TuRN0=
3638
github.com/go-lintpack/lintpack v0.5.2/go.mod h1:NwZuYi2nUHho8XEIZ6SIxihrnPoqBTDqfpXvXAN0sXM=
3739
github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8=
40+
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
3841
github.com/go-toolsmith/astcast v1.0.0 h1:JojxlmI6STnFVG9yOImLeGREv8W2ocNUM+iOhR6jE7g=
3942
github.com/go-toolsmith/astcast v1.0.0/go.mod h1:mt2OdQTeAQcY4DQgPSArJjHCcOwlX+Wl/kwN+LbLGQ4=
4043
github.com/go-toolsmith/astcopy v1.0.0 h1:OMgl1b1MEpjFQ1m5ztEO06rz5CUd3oBv9RF7+DyvdG8=
@@ -152,6 +155,8 @@ github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
152155
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
153156
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
154157
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
158+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
159+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
155160
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
156161
github.com/quasilyte/go-consistent v0.0.0-20190521200055-c6f3937de18c/go.mod h1:5STLWrekHfjyYwxBRVRXNOSewLJ3PWfDJd1VyTS21fI=
157162
github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
@@ -204,6 +209,8 @@ golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73r
204209
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
205210
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
206211
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
212+
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI=
213+
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
207214
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
208215
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
209216
golang.org/x/sys v0.0.0-20171026204733-164713f0dfce/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

0 commit comments

Comments
 (0)