Skip to content

Commit

Permalink
Merge pull request #1294 from torredil/err-log
Browse files Browse the repository at this point in the history
Improve ENIs error logging
  • Loading branch information
k8s-ci-robot authored Jun 29, 2022
2 parents 8217a2b + 9e944a2 commit 0d9f618
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/cloud/metadata_ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,19 @@ func EC2MetadataInstanceInfo(svc EC2Metadata) (*Metadata, error) {
}

enis, err := svc.GetMetadata(enisEndpoint)
if err != nil {
return nil, fmt.Errorf("could not get number of attached ENIs: %v", err)
}
// the ENIs should not be empty; if (somehow) it is empty, return an error
if enis == "" || err != nil {
return nil, fmt.Errorf("could not get number of attached ENIs")
if enis == "" {
return nil, fmt.Errorf("the ENIs should not be empty")
}

attachedENIs := strings.Count(enis, "\n") + 1

mappings, err := svc.GetMetadata(blockDevicesEndpoint)
if err != nil {
return nil, fmt.Errorf("could not get number of block device mappings")
return nil, fmt.Errorf("could not get number of block device mappings: %v", err)
}
// The output contains 1 volume for the AMI. Any other block device contributes to the attachment limit
blockDevMappings := strings.Count(mappings, "\n")
Expand Down

0 comments on commit 0d9f618

Please sign in to comment.