From 7e0efbef347ae608b9cfbc88e88db7d2940a1e6c Mon Sep 17 00:00:00 2001 From: Claes Mogren Date: Tue, 26 Jun 2018 17:02:24 -0700 Subject: [PATCH] Fix fmt, vet and ineffassign issues --- README.md | 9 + ipamd/datastore/data_store_test.go | 18 +- ipamd/ipamd.go | 12 +- ipamd/ipamd_test.go | 26 +- main.go | 8 +- pkg/awsutils/awsutils.go | 4 +- pkg/awsutils/awsutils_test.go | 14 +- pkg/awsutils/vpc_ip_resource_limit.go | 460 +++++++++++++------------- pkg/k8sapi/discovery.go | 12 +- pkg/mocks/network_mocks.go | 0 pkg/networkutils/network.go | 8 +- pkg/utils/errors.go | 2 +- pkg/utils/utils.go | 5 +- 13 files changed, 293 insertions(+), 285 deletions(-) delete mode 100644 pkg/mocks/network_mocks.go diff --git a/README.md b/README.md index bfb6359148..f909e86f3d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,15 @@ # amazon-vpc-cni-k8s Networking plugin for pod networking in [Kubernetes](https://kubernetes.io/) using [Elastic Network Interfaces](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html) on AWS. +[![BuildStatus Widget]][BuildStatus Result] +[![GoReport Widget]][GoReport Status] + + +[BuildStatus Result]: https://travis-ci.org/aws/amazon-vpc-cni-k8s +[BuildStatus Widget]: https://travis-ci.org/aws/amazon-vpc-cni-k8s.svg?branch=master + +[GoReport Status]: https://goreportcard.com/report/github.com/aws/amazon-vpc-cni-k8s +[GoReport Widget]: https://goreportcard.com/badge/github.com/aws/amazon-vpc-cni-k8s ## Setup Download the latest version of the [yaml](./config/) and apply it the cluster. ``` diff --git a/ipamd/datastore/data_store_test.go b/ipamd/datastore/data_store_test.go index 117c0c7354..3416872717 100644 --- a/ipamd/datastore/data_store_test.go +++ b/ipamd/datastore/data_store_test.go @@ -134,9 +134,8 @@ func TestGetENIIPPools(t *testing.T) { assert.NoError(t, err) assert.Equal(t, len(eniIPPool), 2) - eniIPPool, err = ds.GetENIIPPools("dummy-eni") + _, err = ds.GetENIIPPools("dummy-eni") assert.Error(t, err) - } func TestDelENIIPv4Address(t *testing.T) { @@ -193,11 +192,14 @@ func TestPodIPv4Address(t *testing.T) { ip, _, err := ds.AssignPodIPv4Address(&podInfo) assert.NoError(t, err) - assert.Equal(t, ip, "1.1.1.1") - assert.Equal(t, ds.total, 3) - assert.Equal(t, len(ds.eniIPPools["eni-1"].IPv4Addresses), 2) - assert.Equal(t, ds.eniIPPools["eni-1"].AssignedIPv4Addresses, 1) + assert.Equal(t, "1.1.1.1", ip) + assert.Equal(t, 3, ds.total) + assert.Equal(t, 2, len(ds.eniIPPools["eni-1"].IPv4Addresses)) + assert.Equal(t, 1, ds.eniIPPools["eni-1"].AssignedIPv4Addresses) + ip, _, err = ds.AssignPodIPv4Address(&podInfo) + assert.NoError(t, err) + assert.Equal(t, "1.1.1.1", ip) podsInfos := ds.GetPodInfos() assert.Equal(t, len(*podsInfos), 1) @@ -217,7 +219,7 @@ func TestPodIPv4Address(t *testing.T) { IP: "1.1.2.10", } - ip, _, err = ds.AssignPodIPv4Address(&podInfo) + _, _, err = ds.AssignPodIPv4Address(&podInfo) assert.Error(t, err) podInfo = k8sapi.K8SPodInfo{ @@ -277,7 +279,7 @@ func TestPodIPv4Address(t *testing.T) { Namespace: "ns-2", } - ip, deviceNum, err := ds.UnAssignPodIPv4Address(&podInfo) + _, deviceNum, err := ds.UnAssignPodIPv4Address(&podInfo) assert.NoError(t, err) assert.Equal(t, ds.total, 3) assert.Equal(t, ds.assigned, 2) diff --git a/ipamd/ipamd.go b/ipamd/ipamd.go index 2d6af4ecfb..3e568832de 100644 --- a/ipamd/ipamd.go +++ b/ipamd/ipamd.go @@ -157,7 +157,7 @@ func (c *IPAMContext) nodeInit() error { enis, err := c.awsClient.GetAttachedENIs() if err != nil { - log.Error("Failed to retrive ENI info") + log.Error("Failed to retrieve ENI info") return errors.New("ipamd init: failed to retrieve attached ENIs info") } @@ -455,7 +455,7 @@ func (c *IPAMContext) addENIaddressesToDataStore(ec2Addrs []*ec2.NetworkInterfac return primaryIP } -// returns all addresses on eni, the primary adderss on eni, error +// returns all addresses on eni, the primary address on eni, error func (c *IPAMContext) getENIaddresses(eni string) ([]*ec2.NetworkInterfacePrivateIpAddress, string, error) { ec2Addrs, _, err := c.awsClient.DescribeENI(eni) if err != nil { @@ -525,7 +525,7 @@ func logPoolStats(total, used, currentMaxAddrsPerENI, maxAddrsPerENI int) { total, used, currentMaxAddrsPerENI, maxAddrsPerENI) } -//nodeIPPoolTooLow returns true if IP pool is below low threshhold +//nodeIPPoolTooLow returns true if IP pool is below low threshold func (c *IPAMContext) nodeIPPoolTooLow() bool { warmENITarget := getWarmENITarget() total, used := c.dataStore.GetStats() @@ -535,7 +535,7 @@ func (c *IPAMContext) nodeIPPoolTooLow() bool { return (available <= c.currentMaxAddrsPerENI*warmENITarget) } -// NodeIPPoolTooHigh returns true if IP pool is above high threshhold +// NodeIPPoolTooHigh returns true if IP pool is above high threshold func (c *IPAMContext) nodeIPPoolTooHigh() bool { warmENITarget := getWarmENITarget() total, used := c.dataStore.GetStats() @@ -640,7 +640,7 @@ func (c *IPAMContext) eniIPPoolReconcile(ipPool map[string]*datastore.AddressInf if err != nil { log.Errorf("Failed to reconcile IP %s on eni %s", localIP, eni) ipamdErrInc("ipReconcileAdd", err) - // contine instead of bailout due to one ip + // continue instead of bailout due to one ip continue } reconcileCnt.With(prometheus.Labels{"fn": "eniIPPoolReconcileAdd"}).Inc() @@ -655,7 +655,7 @@ func (c *IPAMContext) eniIPPoolReconcile(ipPool map[string]*datastore.AddressInf if err != nil { log.Errorf("Failed to reconcile and delete IP %s on eni %s, %v", existingIP, eni, err) ipamdErrInc("ipReconcileDel", err) - // contine instead of bailout due to one ip + // continue instead of bailout due to one ip continue } reconcileCnt.With(prometheus.Labels{"fn": "eniIPPoolReconcileDel"}).Inc() diff --git a/ipamd/ipamd_test.go b/ipamd/ipamd_test.go index 22bdc1de79..ea18077217 100644 --- a/ipamd/ipamd_test.go +++ b/ipamd/ipamd_test.go @@ -107,9 +107,9 @@ func TestNodeInit(t *testing.T) { testAddr2 := ipaddr02 primary := true eniResp := []*ec2.NetworkInterfacePrivateIpAddress{ - &ec2.NetworkInterfacePrivateIpAddress{ + { PrivateIpAddress: &testAddr1, Primary: &primary}, - &ec2.NetworkInterfacePrivateIpAddress{ + { PrivateIpAddress: &testAddr2, Primary: &primary}} mockAWS.EXPECT().GetPrimaryENI().Return(primaryENIid) mockAWS.EXPECT().DescribeENI(primaryENIid).Return(eniResp, &attachmentID, nil) @@ -122,9 +122,9 @@ func TestNodeInit(t *testing.T) { testAddr12 := ipaddr12 primary = false eniResp = []*ec2.NetworkInterfacePrivateIpAddress{ - &ec2.NetworkInterfacePrivateIpAddress{ + { PrivateIpAddress: &testAddr11, Primary: &primary}, - &ec2.NetworkInterfacePrivateIpAddress{ + { PrivateIpAddress: &testAddr12, Primary: &primary}} mockAWS.EXPECT().GetPrimaryENI().Return(primaryENIid) mockAWS.EXPECT().DescribeENI(secENIid).Return(eniResp, &attachmentID, nil) @@ -132,7 +132,7 @@ func TestNodeInit(t *testing.T) { mockAWS.EXPECT().GetLocalIPv4().Return(ipaddr01) k8sName := "/k8s_POD_" + "pod1" + "_" + "default" + "_" + "pod-uid" + "_0" - mockK8S.EXPECT().K8SGetLocalPodIPs().Return([]*k8sapi.K8SPodInfo{&k8sapi.K8SPodInfo{Name: "pod1", + mockK8S.EXPECT().K8SGetLocalPodIPs().Return([]*k8sapi.K8SPodInfo{{Name: "pod1", Namespace: "default", UID: "pod-uid", IP: ipaddr02}}, nil) var dockerList = make(map[string]*docker.ContainerInfo, 0) @@ -165,14 +165,14 @@ func TestIncreaseIPPool(t *testing.T) { mockAWS.EXPECT().AllocAllIPAddress(eni2) mockAWS.EXPECT().GetAttachedENIs().Return([]awsutils.ENIMetadata{ - awsutils.ENIMetadata{ + { ENIID: primaryENIid, MAC: primaryMAC, DeviceNumber: primaryDevice, SubnetIPv4CIDR: primarySubnet, LocalIPv4s: []string{ipaddr01, ipaddr02}, }, - awsutils.ENIMetadata{ + { ENIID: secENIid, MAC: secMAC, DeviceNumber: secDevice, @@ -189,9 +189,9 @@ func TestIncreaseIPPool(t *testing.T) { mockAWS.EXPECT().DescribeENI(eni2).Return( []*ec2.NetworkInterfacePrivateIpAddress{ - &ec2.NetworkInterfacePrivateIpAddress{ + { PrivateIpAddress: &testAddr11, Primary: &primary}, - &ec2.NetworkInterfacePrivateIpAddress{ + { PrivateIpAddress: &testAddr12, Primary: &primary}}, &attachmentID, nil) mockAWS.EXPECT().GetPrimaryENI().Return(primaryENIid) @@ -215,7 +215,7 @@ func TestNodeIPPoolReconcile(t *testing.T) { mockContext.dataStore = datastore.NewDataStore() mockAWS.EXPECT().GetAttachedENIs().Return([]awsutils.ENIMetadata{ - awsutils.ENIMetadata{ + { ENIID: primaryENIid, MAC: primaryMAC, DeviceNumber: primaryDevice, @@ -234,9 +234,9 @@ func TestNodeIPPoolReconcile(t *testing.T) { mockAWS.EXPECT().DescribeENI(primaryENIid).Return( []*ec2.NetworkInterfacePrivateIpAddress{ - &ec2.NetworkInterfacePrivateIpAddress{ + { PrivateIpAddress: &testAddr1, Primary: &primary}, - &ec2.NetworkInterfacePrivateIpAddress{ + { PrivateIpAddress: &testAddr2, Primary: ¬Primary}}, &attachmentID, nil) mockAWS.EXPECT().GetPrimaryENI().Return(primaryENIid) @@ -248,7 +248,7 @@ func TestNodeIPPoolReconcile(t *testing.T) { // remove 1 IP mockAWS.EXPECT().GetAttachedENIs().Return([]awsutils.ENIMetadata{ - awsutils.ENIMetadata{ + { ENIID: primaryENIid, MAC: primaryMAC, DeviceNumber: primaryDevice, diff --git a/main.go b/main.go index 67b6f05c52..035c7f7187 100644 --- a/main.go +++ b/main.go @@ -48,16 +48,16 @@ func _main() int { discoverController := k8sapi.NewController(kubeClient) go discoverController.DiscoverK8SPods() - aws_k8s_agent, err := ipamd.New(discoverController) + awsK8sAgent, err := ipamd.New(discoverController) if err != nil { log.Error("initialization failure", err) return 1 } - go aws_k8s_agent.StartNodeIPPoolManager() - go aws_k8s_agent.SetupHTTP() - aws_k8s_agent.RunRPCHandler() + go awsK8sAgent.StartNodeIPPoolManager() + go awsK8sAgent.SetupHTTP() + awsK8sAgent.RunRPCHandler() return 0 } diff --git a/pkg/awsutils/awsutils.go b/pkg/awsutils/awsutils.go index 7865ff92bb..02e77836fd 100644 --- a/pkg/awsutils/awsutils.go +++ b/pkg/awsutils/awsutils.go @@ -342,7 +342,7 @@ func (cache *EC2InstanceMetadataCache) setPrimaryENI() error { if err != nil { awsAPIErrInc("GetMetadata", err) log.Errorf("Failed to retrieve owner ID from instance metadata %v", err) - return errors.Wrap(err, "set primary eni: failed to retrive ownerID") + return errors.Wrap(err, "set primary eni: failed to retrieve ownerID") } log.Debugf("Found account ID: %s", ownerID) cache.accountID = ownerID @@ -694,7 +694,7 @@ func (cache *EC2InstanceMetadataCache) FreeENI(eniName string) error { _, attachID, err := cache.DescribeENI(eniName) if err != nil { awsUtilsErrInc("FreeENIDescribeENIFailed", err) - log.Errorf("Failed to retrive eni %s attachment id %d", eniName, err) + log.Errorf("Failed to retrieve eni %s attachment id %d", eniName, err) return errors.Wrap(err, "free eni: failed to retrieve eni's attachment id") } diff --git a/pkg/awsutils/awsutils_test.go b/pkg/awsutils/awsutils_test.go index 52232bb461..113880c5a9 100644 --- a/pkg/awsutils/awsutils_test.go +++ b/pkg/awsutils/awsutils_test.go @@ -306,7 +306,7 @@ func TestAWSGetFreeDeviceNumberNoDevice(t *testing.T) { ec2ENIs = append(ec2ENIs, ec2ENI) } result := &ec2.DescribeInstancesOutput{ - Reservations: []*ec2.Reservation{&ec2.Reservation{Instances: []*ec2.Instance{&ec2.Instance{NetworkInterfaces: ec2ENIs}}}}} + Reservations: []*ec2.Reservation{{Instances: []*ec2.Instance{{NetworkInterfaces: ec2ENIs}}}}} mockEC2.EXPECT().DescribeInstances(gomock.Any()).Return(result, nil) ins := &EC2InstanceMetadataCache{ec2SVC: mockEC2} @@ -341,7 +341,7 @@ func TestAllocENI(t *testing.T) { ec2ENIs = append(ec2ENIs, ec2ENI) result := &ec2.DescribeInstancesOutput{ - Reservations: []*ec2.Reservation{&ec2.Reservation{Instances: []*ec2.Instance{&ec2.Instance{NetworkInterfaces: ec2ENIs}}}}} + Reservations: []*ec2.Reservation{{Instances: []*ec2.Instance{{NetworkInterfaces: ec2ENIs}}}}} mockEC2.EXPECT().DescribeInstances(gomock.Any()).Return(result, nil) attachmentID := "eni-attach-58ddda9d" @@ -377,7 +377,7 @@ func TestAllocENINoFreeDevice(t *testing.T) { ec2ENIs = append(ec2ENIs, ec2ENI) } result := &ec2.DescribeInstancesOutput{ - Reservations: []*ec2.Reservation{&ec2.Reservation{Instances: []*ec2.Instance{&ec2.Instance{NetworkInterfaces: ec2ENIs}}}}} + Reservations: []*ec2.Reservation{{Instances: []*ec2.Instance{{NetworkInterfaces: ec2ENIs}}}}} mockEC2.EXPECT().DescribeInstances(gomock.Any()).Return(result, nil) @@ -413,7 +413,7 @@ func TestAllocENIMaxReached(t *testing.T) { ec2ENIs = append(ec2ENIs, ec2ENI) result := &ec2.DescribeInstancesOutput{ - Reservations: []*ec2.Reservation{&ec2.Reservation{Instances: []*ec2.Instance{&ec2.Instance{NetworkInterfaces: ec2ENIs}}}}} + Reservations: []*ec2.Reservation{{Instances: []*ec2.Instance{{NetworkInterfaces: ec2ENIs}}}}} mockEC2.EXPECT().DescribeInstances(gomock.Any()).Return(result, nil) mockEC2.EXPECT().AttachNetworkInterface(gomock.Any()).Return(nil, errors.New("AttachmentLimitExceeded")) @@ -431,7 +431,7 @@ func TestFreeENI(t *testing.T) { attachmentID := eniAttachID attachment := &ec2.NetworkInterfaceAttachment{AttachmentId: &attachmentID} result := &ec2.DescribeNetworkInterfacesOutput{ - NetworkInterfaces: []*ec2.NetworkInterface{&ec2.NetworkInterface{Attachment: attachment}}} + NetworkInterfaces: []*ec2.NetworkInterface{{Attachment: attachment}}} mockEC2.EXPECT().DescribeNetworkInterfaces(gomock.Any()).Return(result, nil) mockEC2.EXPECT().DetachNetworkInterface(gomock.Any()).Return(nil, nil) mockEC2.EXPECT().DeleteNetworkInterface(gomock.Any()).Return(nil, nil) @@ -448,7 +448,7 @@ func TestFreeENIRetry(t *testing.T) { attachmentID := eniAttachID attachment := &ec2.NetworkInterfaceAttachment{AttachmentId: &attachmentID} result := &ec2.DescribeNetworkInterfacesOutput{ - NetworkInterfaces: []*ec2.NetworkInterface{&ec2.NetworkInterface{Attachment: attachment}}} + NetworkInterfaces: []*ec2.NetworkInterface{{Attachment: attachment}}} mockEC2.EXPECT().DescribeNetworkInterfaces(gomock.Any()).Return(result, nil) // retry 2 times @@ -468,7 +468,7 @@ func TestFreeENIRetryMax(t *testing.T) { attachmentID := eniAttachID attachment := &ec2.NetworkInterfaceAttachment{AttachmentId: &attachmentID} result := &ec2.DescribeNetworkInterfacesOutput{ - NetworkInterfaces: []*ec2.NetworkInterface{&ec2.NetworkInterface{Attachment: attachment}}} + NetworkInterfaces: []*ec2.NetworkInterface{{Attachment: attachment}}} mockEC2.EXPECT().DescribeNetworkInterfaces(gomock.Any()).Return(result, nil) mockEC2.EXPECT().DetachNetworkInterface(gomock.Any()).Return(nil, nil) diff --git a/pkg/awsutils/vpc_ip_resource_limit.go b/pkg/awsutils/vpc_ip_resource_limit.go index 678c4da05b..be401436bc 100644 --- a/pkg/awsutils/vpc_ip_resource_limit.go +++ b/pkg/awsutils/vpc_ip_resource_limit.go @@ -16,239 +16,239 @@ package awsutils // InstanceENIsAvailable contains a mapping of instance types to the number of ENIs available which is described at // https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html#AvailableIpPerENI var InstanceENIsAvailable = map[string]int{ - "c1.medium": 2, - "c1.xlarge": 4, - "c3.large": 3, - "c3.xlarge": 4, - "c3.2xlarge": 4, - "c3.4xlarge": 8, - "c3.8xlarge": 8, - "c4.large": 3, - "c4.xlarge": 4, - "c4.2xlarge": 4, - "c4.4xlarge": 8, - "c4.8xlarge": 8, - "c5.large": 3, - "c5.xlarge": 4, - "c5.2xlarge": 4, - "c5.4xlarge": 8, - "c5.9xlarge": 8, - "c5.18xlarge": 15, - "c5d.large": 3, - "c5d.xlarge": 4, - "c5d.2xlarge": 4, - "c5d.4xlarge": 8, - "c5d.9xlarge": 8, - "c5d.18xlarge": 15, - "cc2.8xlarge": 8, - "cr1.8xlarge": 8, - "d2.xlarge": 4, - "d2.2xlarge": 4, - "d2.4xlarge": 8, - "d2.8xlarge": 8, - "f1.2xlarge": 4, - "f1.16xlarge": 8, - "g2.2xlarge": 4, - "g2.8xlarge": 8, - "g3.4xlarge": 8, - "g3.8xlarge": 8, - "g3.16xlarge": 15, - "h1.2xlarge": 4, - "h1.4xlarge": 8, - "h1.8xlarge": 8, - "h1.16xlarge": 15, - "hs1.8xlarge": 8, - "i2.xlarge": 4, - "i2.2xlarge": 4, - "i2.4xlarge": 8, - "i2.8xlarge": 8, - "i3.large": 3, - "i3.xlarge": 4, - "i3.2xlarge": 4, - "i3.4xlarge": 8, - "i3.8xlarge": 8, - "i3.16xlarge": 15, - "i3.metal": 15, - "m1.small": 2, - "m1.medium": 2, - "m1.large": 3, - "m1.xlarge": 4, - "m2.xlarge": 4, - "m2.2xlarge": 4, - "m2.4xlarge": 8, - "m3.medium": 2, - "m3.large": 3, - "m3.xlarge": 4, - "m3.2xlarge": 4, - "m4.large": 2, - "m4.xlarge": 4, - "m4.2xlarge": 4, - "m4.4xlarge": 8, - "m4.10xlarge": 8, - "m4.16xlarge": 8, - "m5.large": 3, - "m5.xlarge": 4, - "m5.2xlarge": 4, - "m5.4xlarge": 8, - "m5.12xlarge": 8, - "m5.24xlarge": 15, - "m5d.large": 3, - "m5d.xlarge": 4, - "m5d.2xlarge": 4, - "m5d.4xlarge": 8, - "m5d.12xlarge": 8, - "m5d.24xlarge": 15, - "p2.xlarge": 4, - "p2.8xlarge": 8, - "p2.16xlarge": 8, - "p3.2xlarge": 4, - "p3.8xlarge": 8, - "p3.16xlarge": 8, - "r3.large": 3, - "r3.xlarge": 4, - "r3.2xlarge": 4, - "r3.4xlarge": 8, - "r3.8xlarge": 8, - "r4.large": 3, - "r4.xlarge": 4, - "r4.2xlarge": 4, - "r4.4xlarge": 8, - "r4.8xlarge": 8, - "r4.16xlarge": 15, - "t1.micro": 2, - "t2.nano": 2, - "t2.micro": 2, - "t2.small": 2, - "t2.medium": 3, - "t2.large": 3, - "t2.xlarge": 3, - "t2.2xlarge": 3, - "x1.16xlarge": 8, - "x1.32xlarge": 8, - "x1e.xlarge": 3, - "x1e.2xlarge": 4, - "x1e.4xlarge": 4, - "x1e.8xlarge": 4, - "x1e.16xlarge": 8, - "x1e.32xlarge": 8, + "c1.medium": 2, + "c1.xlarge": 4, + "c3.large": 3, + "c3.xlarge": 4, + "c3.2xlarge": 4, + "c3.4xlarge": 8, + "c3.8xlarge": 8, + "c4.large": 3, + "c4.xlarge": 4, + "c4.2xlarge": 4, + "c4.4xlarge": 8, + "c4.8xlarge": 8, + "c5.large": 3, + "c5.xlarge": 4, + "c5.2xlarge": 4, + "c5.4xlarge": 8, + "c5.9xlarge": 8, + "c5.18xlarge": 15, + "c5d.large": 3, + "c5d.xlarge": 4, + "c5d.2xlarge": 4, + "c5d.4xlarge": 8, + "c5d.9xlarge": 8, + "c5d.18xlarge": 15, + "cc2.8xlarge": 8, + "cr1.8xlarge": 8, + "d2.xlarge": 4, + "d2.2xlarge": 4, + "d2.4xlarge": 8, + "d2.8xlarge": 8, + "f1.2xlarge": 4, + "f1.16xlarge": 8, + "g2.2xlarge": 4, + "g2.8xlarge": 8, + "g3.4xlarge": 8, + "g3.8xlarge": 8, + "g3.16xlarge": 15, + "h1.2xlarge": 4, + "h1.4xlarge": 8, + "h1.8xlarge": 8, + "h1.16xlarge": 15, + "hs1.8xlarge": 8, + "i2.xlarge": 4, + "i2.2xlarge": 4, + "i2.4xlarge": 8, + "i2.8xlarge": 8, + "i3.large": 3, + "i3.xlarge": 4, + "i3.2xlarge": 4, + "i3.4xlarge": 8, + "i3.8xlarge": 8, + "i3.16xlarge": 15, + "i3.metal": 15, + "m1.small": 2, + "m1.medium": 2, + "m1.large": 3, + "m1.xlarge": 4, + "m2.xlarge": 4, + "m2.2xlarge": 4, + "m2.4xlarge": 8, + "m3.medium": 2, + "m3.large": 3, + "m3.xlarge": 4, + "m3.2xlarge": 4, + "m4.large": 2, + "m4.xlarge": 4, + "m4.2xlarge": 4, + "m4.4xlarge": 8, + "m4.10xlarge": 8, + "m4.16xlarge": 8, + "m5.large": 3, + "m5.xlarge": 4, + "m5.2xlarge": 4, + "m5.4xlarge": 8, + "m5.12xlarge": 8, + "m5.24xlarge": 15, + "m5d.large": 3, + "m5d.xlarge": 4, + "m5d.2xlarge": 4, + "m5d.4xlarge": 8, + "m5d.12xlarge": 8, + "m5d.24xlarge": 15, + "p2.xlarge": 4, + "p2.8xlarge": 8, + "p2.16xlarge": 8, + "p3.2xlarge": 4, + "p3.8xlarge": 8, + "p3.16xlarge": 8, + "r3.large": 3, + "r3.xlarge": 4, + "r3.2xlarge": 4, + "r3.4xlarge": 8, + "r3.8xlarge": 8, + "r4.large": 3, + "r4.xlarge": 4, + "r4.2xlarge": 4, + "r4.4xlarge": 8, + "r4.8xlarge": 8, + "r4.16xlarge": 15, + "t1.micro": 2, + "t2.nano": 2, + "t2.micro": 2, + "t2.small": 2, + "t2.medium": 3, + "t2.large": 3, + "t2.xlarge": 3, + "t2.2xlarge": 3, + "x1.16xlarge": 8, + "x1.32xlarge": 8, + "x1e.xlarge": 3, + "x1e.2xlarge": 4, + "x1e.4xlarge": 4, + "x1e.8xlarge": 4, + "x1e.16xlarge": 8, + "x1e.32xlarge": 8, } // InstanceIPsAvailable contains a mapping of instance types to the number of IPs per ENI // https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html#AvailableIpPerENI var InstanceIPsAvailable = map[string]int64{ - "c1.medium": 6, - "c1.xlarge": 15, - "c3.large": 10, - "c3.xlarge": 15, - "c3.2xlarge": 15, - "c3.4xlarge": 30, - "c3.8xlarge": 30, - "c4.large": 10, - "c4.xlarge": 15, - "c4.2xlarge": 15, - "c4.4xlarge": 30, - "c4.8xlarge": 30, - "c5.large": 10, - "c5.xlarge": 15, - "c5.2xlarge": 15, - "c5.4xlarge": 30, - "c5.9xlarge": 30, - "c5.18xlarge": 50, - "c5d.large": 10, - "c5d.xlarge": 15, - "c5d.2xlarge": 15, - "c5d.4xlarge": 30, - "c5d.9xlarge": 30, - "c5d.18xlarge": 50, - "cc2.8xlarge": 30, - "cr1.8xlarge": 30, - "d2.xlarge": 15, - "d2.2xlarge": 15, - "d2.4xlarge": 30, - "d2.8xlarge": 30, - "f1.2xlarge": 15, - "f1.16xlarge": 50, - "g2.2xlarge": 15, - "g2.8xlarge": 30, - "g3.4xlarge": 30, - "g3.8xlarge": 30, - "g3.16xlarge": 50, - "h1.2xlarge": 15, - "h1.4xlarge": 30, - "h1.8xlarge": 30, - "h1.16xlarge": 50, - "hs1.8xlarge": 30, - "i2.xlarge": 15, - "i2.2xlarge": 15, - "i2.4xlarge": 30, - "i2.8xlarge": 30, - "i3.large": 10, - "i3.xlarge": 15, - "i3.2xlarge": 15, - "i3.4xlarge": 30, - "i3.8xlarge": 30, - "i3.16xlarge": 50, - "i3.metal": 50, - "m1.small": 4, - "m1.medium": 6, - "m1.large": 10, - "m1.xlarge": 15, - "m2.xlarge": 15, - "m2.2xlarge": 30, - "m2.4xlarge": 30, - "m3.medium": 6, - "m3.large": 10, - "m3.xlarge": 15, - "m3.2xlarge": 30, - "m4.large": 10, - "m4.xlarge": 15, - "m4.2xlarge": 15, - "m4.4xlarge": 30, - "m4.10xlarge": 30, - "m4.16xlarge": 30, - "m5.large": 10, - "m5.xlarge": 15, - "m5.2xlarge": 15, - "m5.4xlarge": 30, - "m5.12xlarge": 30, - "m5.24xlarge": 50, - "m5d.large": 10, - "m5d.xlarge": 15, - "m5d.2xlarge": 15, - "m5d.4xlarge": 30, - "m5d.12xlarge": 30, - "m5d.24xlarge": 50, - "p2.xlarge": 15, - "p2.8xlarge": 30, - "p2.16xlarge": 30, - "p3.2xlarge": 15, - "p3.8xlarge": 30, - "p3.16xlarge": 30, - "r3.large": 10, - "r3.xlarge": 15, - "r3.2xlarge": 15, - "r3.4xlarge": 30, - "r3.8xlarge": 30, - "r4.large": 10, - "r4.xlarge": 15, - "r4.2xlarge": 15, - "r4.4xlarge": 30, - "r4.8xlarge": 30, - "r4.16xlarge": 50, - "t1.micro": 2, - "t2.nano": 2, - "t2.micro": 2, - "t2.small": 4, - "t2.medium": 6, - "t2.large": 12, - "t2.xlarge": 15, - "t2.2xlarge": 15, - "x1.16xlarge": 30, - "x1.32xlarge": 30, - "x1e.xlarge": 10, - "x1e.2xlarge": 15, - "x1e.4xlarge": 15, - "x1e.8xlarge": 15, - "x1e.16xlarge": 30, - "x1e.32xlarge": 30, + "c1.medium": 6, + "c1.xlarge": 15, + "c3.large": 10, + "c3.xlarge": 15, + "c3.2xlarge": 15, + "c3.4xlarge": 30, + "c3.8xlarge": 30, + "c4.large": 10, + "c4.xlarge": 15, + "c4.2xlarge": 15, + "c4.4xlarge": 30, + "c4.8xlarge": 30, + "c5.large": 10, + "c5.xlarge": 15, + "c5.2xlarge": 15, + "c5.4xlarge": 30, + "c5.9xlarge": 30, + "c5.18xlarge": 50, + "c5d.large": 10, + "c5d.xlarge": 15, + "c5d.2xlarge": 15, + "c5d.4xlarge": 30, + "c5d.9xlarge": 30, + "c5d.18xlarge": 50, + "cc2.8xlarge": 30, + "cr1.8xlarge": 30, + "d2.xlarge": 15, + "d2.2xlarge": 15, + "d2.4xlarge": 30, + "d2.8xlarge": 30, + "f1.2xlarge": 15, + "f1.16xlarge": 50, + "g2.2xlarge": 15, + "g2.8xlarge": 30, + "g3.4xlarge": 30, + "g3.8xlarge": 30, + "g3.16xlarge": 50, + "h1.2xlarge": 15, + "h1.4xlarge": 30, + "h1.8xlarge": 30, + "h1.16xlarge": 50, + "hs1.8xlarge": 30, + "i2.xlarge": 15, + "i2.2xlarge": 15, + "i2.4xlarge": 30, + "i2.8xlarge": 30, + "i3.large": 10, + "i3.xlarge": 15, + "i3.2xlarge": 15, + "i3.4xlarge": 30, + "i3.8xlarge": 30, + "i3.16xlarge": 50, + "i3.metal": 50, + "m1.small": 4, + "m1.medium": 6, + "m1.large": 10, + "m1.xlarge": 15, + "m2.xlarge": 15, + "m2.2xlarge": 30, + "m2.4xlarge": 30, + "m3.medium": 6, + "m3.large": 10, + "m3.xlarge": 15, + "m3.2xlarge": 30, + "m4.large": 10, + "m4.xlarge": 15, + "m4.2xlarge": 15, + "m4.4xlarge": 30, + "m4.10xlarge": 30, + "m4.16xlarge": 30, + "m5.large": 10, + "m5.xlarge": 15, + "m5.2xlarge": 15, + "m5.4xlarge": 30, + "m5.12xlarge": 30, + "m5.24xlarge": 50, + "m5d.large": 10, + "m5d.xlarge": 15, + "m5d.2xlarge": 15, + "m5d.4xlarge": 30, + "m5d.12xlarge": 30, + "m5d.24xlarge": 50, + "p2.xlarge": 15, + "p2.8xlarge": 30, + "p2.16xlarge": 30, + "p3.2xlarge": 15, + "p3.8xlarge": 30, + "p3.16xlarge": 30, + "r3.large": 10, + "r3.xlarge": 15, + "r3.2xlarge": 15, + "r3.4xlarge": 30, + "r3.8xlarge": 30, + "r4.large": 10, + "r4.xlarge": 15, + "r4.2xlarge": 15, + "r4.4xlarge": 30, + "r4.8xlarge": 30, + "r4.16xlarge": 50, + "t1.micro": 2, + "t2.nano": 2, + "t2.micro": 2, + "t2.small": 4, + "t2.medium": 6, + "t2.large": 12, + "t2.xlarge": 15, + "t2.2xlarge": 15, + "x1.16xlarge": 30, + "x1.32xlarge": 30, + "x1e.xlarge": 10, + "x1e.2xlarge": 15, + "x1e.4xlarge": 15, + "x1e.8xlarge": 15, + "x1e.16xlarge": 30, + "x1e.32xlarge": 30, } diff --git a/pkg/k8sapi/discovery.go b/pkg/k8sapi/discovery.go index 5908f57e86..7f54bcc6ff 100644 --- a/pkg/k8sapi/discovery.go +++ b/pkg/k8sapi/discovery.go @@ -1,4 +1,4 @@ -// Package k8sapi contains logic to retrive pods running on local node +// Package k8sapi contains logic to retrieve pods running on local node package k8sapi import ( @@ -63,7 +63,7 @@ type Controller struct { synced bool } -// NewController creats a new DiscoveryController +// NewController creates a new DiscoveryController func NewController(clientset kubernetes.Interface) *Controller { return &Controller{kubeClient: clientset, myNodeName: os.Getenv("MY_NODE_NAME"), @@ -195,7 +195,7 @@ func (d *Controller) processNextItem() bool { func (d *Controller) handlePodUpdate(key string) error { obj, exists, err := d.controller.indexer.GetByKey(key) if err != nil { - log.Errorf("Fetching object with key %s from store failed with %v", key, err) + log.Errorf("fetching object with key %s from store failed with %v", key, err) return err } @@ -209,8 +209,8 @@ func (d *Controller) handlePodUpdate(key string) error { pod, ok := obj.(*v1.Pod) if !ok { - log.Errorf("Updated object recieved was not a pod: %+v", obj) - return errors.New("recieved a non-pod object update") + log.Errorf("updated object received was not a pod: %+v", obj) + return errors.New("received a non-pod object update") } // Note that you also have to check the uid if you have a local controlled resource, which // is dependent on the actual instance, to detect that a Pod was recreated with the same name @@ -269,7 +269,7 @@ func (d *Controller) run(threadiness int, stopCh chan struct{}) { // Wait for all involved caches to be synced, before processing items from the queue is started if !cache.WaitForCacheSync(stopCh, d.controller.informer.HasSynced) { - runtime.HandleError(fmt.Errorf("Timed out waiting for caches to sync")) + runtime.HandleError(fmt.Errorf("timed out waiting for caches to sync")) return } diff --git a/pkg/mocks/network_mocks.go b/pkg/mocks/network_mocks.go deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/pkg/networkutils/network.go b/pkg/networkutils/network.go index 17bb33e040..43024dbb98 100644 --- a/pkg/networkutils/network.go +++ b/pkg/networkutils/network.go @@ -109,7 +109,7 @@ func (os *linuxNetwork) SetupHostNetwork(vpcCIDR *net.IPNet, primaryAddr *net.IP err = ipt.Append("nat", "POSTROUTING", natCmd...) if err != nil { - return errors.Wrapf(err, "host network setup: failed to append POSTROUTING rule for primary adderss %s", primaryAddr) + return errors.Wrapf(err, "host network setup: failed to append POSTROUTING rule for primary address %s", primaryAddr) } } @@ -180,14 +180,14 @@ func setupENINetwork(eniIP string, eniMAC string, eniTable int, eniSubnetCIDR st for _, r := range []netlink.Route{ // Add a direct link route for the host's ENI IP only - netlink.Route{ + { LinkIndex: deviceNumber, Dst: &net.IPNet{IP: gw.IP, Mask: net.CIDRMask(32, 32)}, Scope: netlink.SCOPE_LINK, Table: eniTable, }, // Route all other traffic via the host's ENI IP - netlink.Route{ + { LinkIndex: deviceNumber, Dst: &net.IPNet{IP: net.IPv4zero, Mask: net.CIDRMask(0, 32)}, Scope: netlink.SCOPE_UNIVERSE, @@ -239,7 +239,6 @@ func isNotExistsError(err error) bool { if errno, ok := err.(syscall.Errno); ok { return errno == syscall.ESRCH } - return false } @@ -252,5 +251,4 @@ func isRouteExistsError(err error) bool { return errno == syscall.EEXIST } return false - } diff --git a/pkg/utils/errors.go b/pkg/utils/errors.go index 98005ccb97..6d8ae3040d 100644 --- a/pkg/utils/errors.go +++ b/pkg/utils/errors.go @@ -65,7 +65,7 @@ func NewAttributeError(err string) AttributeError { return AttributeError{err} } -// Implements error +// MultiErr Implements error type MultiErr struct { errors []error } diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 33f021f38b..172cce66e9 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -27,9 +27,9 @@ import ( "github.com/aws/amazon-vpc-cni-k8s/pkg/utils/ttime" ) -func DefaultIfBlank(str string, default_value string) string { +func DefaultIfBlank(str string, defaultValue string) string { if len(str) == 0 { - return default_value + return defaultValue } return str } @@ -134,7 +134,6 @@ func RetryWithBackoffCtx(ctx context.Context, backoff Backoff, fn func() error) _time.Sleep(backoff.Duration()) } - return err } // RetryNWithBackoff takes a Backoff, a maximum number of tries 'n', and a