From 8f7587dafe3febabc58cd2b225d0dbc7599b93a1 Mon Sep 17 00:00:00 2001 From: Claes Mogren Date: Fri, 1 May 2020 16:22:42 -0700 Subject: [PATCH] Check all errors and log appropriately (#939) (cherry picked from commit af74b57e098534ba389d13d9407fc96a33ea8da1) --- pkg/awsutils/awsutils.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/awsutils/awsutils.go b/pkg/awsutils/awsutils.go index 43487253d1..c013b34df7 100644 --- a/pkg/awsutils/awsutils.go +++ b/pkg/awsutils/awsutils.go @@ -594,7 +594,11 @@ func (cache *EC2InstanceMetadataCache) AllocENI(useCustomCfg bool, sg []*string, attachmentID, err := cache.attachENI(eniID) if err != nil { - _ = cache.deleteENI(eniID, maxENIBackoffDelay) + derr := cache.deleteENI(eniID, maxENIBackoffDelay) + if derr != nil { + awsUtilsErrInc("AllocENIDeleteErr", err) + log.Errorf("Failed to delete newly created untagged ENI! %v", err) + } return "", errors.Wrap(err, "AllocENI: error attaching ENI") } @@ -1106,16 +1110,20 @@ func (cache *EC2InstanceMetadataCache) AllocIPAddresses(eniID string, numIPs int } start := time.Now() - _, err = cache.ec2SVC.AssignPrivateIpAddresses(input) + output, err := cache.ec2SVC.AssignPrivateIpAddresses(input) awsAPILatency.WithLabelValues("AssignPrivateIpAddresses", fmt.Sprint(err != nil)).Observe(msSince(start)) if err != nil { log.Errorf("Failed to allocate a private IP addresses on ENI %v: %v", eniID, err) awsAPIErrInc("AssignPrivateIpAddresses", err) if containsPrivateIPAddressLimitExceededError(err) { + log.Debug("AssignPrivateIpAddresses returned PrivateIpAddressLimitExceeded") return nil } return errors.Wrap(err, "allocate IP address: failed to allocate a private IP address") } + if output != nil { + log.Infof("Allocated %d private IP addresses", len(output.AssignedPrivateIpAddresses)) + } return nil } @@ -1160,6 +1168,7 @@ func (cache *EC2InstanceMetadataCache) cleanUpLeakedENIs() { eniID := aws.StringValue(networkInterface.NetworkInterfaceId) err = cache.deleteENI(eniID, maxENIBackoffDelay) if err != nil { + awsUtilsErrInc("cleanUpLeakedENIDeleteErr", err) log.Warnf("Failed to clean up leaked ENI %s: %v", eniID, err) } }