Skip to content

Commit

Permalink
Removed the workflow for getting Primary ipv4 address of the vpc.
Browse files Browse the repository at this point in the history
This is not required as we can use the dns settings of the primary instance ENI.
  • Loading branch information
Harsh Rawat committed May 24, 2021
1 parent 7106ffb commit 6c045de
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 78 deletions.
5 changes: 0 additions & 5 deletions agent/ec2/blackhole_ec2_metadata_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package ec2

import (
"errors"
"net"

"github.com/aws/aws-sdk-go/aws/ec2metadata"
)
Expand Down Expand Up @@ -85,7 +84,3 @@ func (blackholeMetadataClient) SpotInstanceAction() (string, error) {
func (blackholeMetadataClient) OutpostARN() (string, error) {
return "", errors.New("blackholed")
}

func (c blackholeMetadataClient) PrimaryIPV4VPCCIDR(mac string) (*net.IPNet, error) {
return nil, errors.New("blackholed")
}
17 changes: 0 additions & 17 deletions agent/ec2/ec2_metadata_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"encoding/json"
"errors"
"fmt"
"net"
"strings"
"time"

Expand Down Expand Up @@ -83,7 +82,6 @@ type EC2MetadataClient interface {
PublicIPv4Address() (string, error)
SpotInstanceAction() (string, error)
OutpostARN() (string, error)
PrimaryIPV4VPCCIDR(mac string) (*net.IPNet, error)
}

type ec2MetadataClientImpl struct {
Expand Down Expand Up @@ -205,18 +203,3 @@ func (c *ec2MetadataClientImpl) SpotInstanceAction() (string, error) {
func (c *ec2MetadataClientImpl) OutpostARN() (string, error) {
return c.client.GetMetadata(OutpostARN)
}

// PrimaryIPV4VPCCIDR returns the primary IPV4 block associated with the VPC
func (c *ec2MetadataClientImpl) PrimaryIPV4VPCCIDR(mac string) (*net.IPNet, error) {
vpcCIDR, err := c.client.GetMetadata(fmt.Sprintf(PrimaryIPV4VPCCIDRResourceFormat, mac))
if err != nil {
return nil, err
}

_, parsedCIDR, err := net.ParseCIDR(vpcCIDR)
if err != nil {
return nil, err
}

return parsedCIDR, nil
}
48 changes: 8 additions & 40 deletions agent/ec2/ec2_metadata_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@ import (
)

const (
testRoleName = "test-role"
mac = "01:23:45:67:89:ab"
macs = "01:23:45:67:89:ab/\n01:23:45:67:89:ac"
vpcID = "vpc-1234"
subnetID = "subnet-1234"
iidRegion = "us-east-1"
privateIP = "127.0.0.1"
publicIP = "127.0.0.1"
vpcPrimaryCIDR = "10.0.0.0/16"
incorrectVPCPrimaryCIDR = "10.0.0.0\n/16"
testRoleName = "test-role"
mac = "01:23:45:67:89:ab"
macs = "01:23:45:67:89:ab/\n01:23:45:67:89:ac"
vpcID = "vpc-1234"
subnetID = "subnet-1234"
iidRegion = "us-east-1"
privateIP = "127.0.0.1"
publicIP = "127.0.0.1"
)

func makeTestRoleCredentials() ec2.RoleCredentials {
Expand Down Expand Up @@ -254,33 +252,3 @@ func TestSpotInstanceActionError(t *testing.T) {
assert.Error(t, err)
assert.Equal(t, "", resp)
}

func TestPrimaryIPV4VPCCIDRSuccess(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

mockGetter := mock_ec2.NewMockHttpClient(ctrl)
testClient := ec2.NewEC2MetadataClient(mockGetter)

mockGetter.EXPECT().GetMetadata(fmt.Sprintf(ec2.PrimaryIPV4VPCCIDRResourceFormat, mac)).
Return(vpcPrimaryCIDR, nil)
resp, err := testClient.PrimaryIPV4VPCCIDR(mac)

assert.NoError(t, err)
assert.Equal(t, vpcPrimaryCIDR, resp.String())
}

func TestPrimaryIPV4VPCCIDRError(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

mockGetter := mock_ec2.NewMockHttpClient(ctrl)
testClient := ec2.NewEC2MetadataClient(mockGetter)

mockGetter.EXPECT().GetMetadata(fmt.Sprintf(ec2.PrimaryIPV4VPCCIDRResourceFormat, mac)).
Return(incorrectVPCPrimaryCIDR, nil)
resp, err := testClient.PrimaryIPV4VPCCIDR(mac)

assert.Error(t, err)
assert.Nil(t, resp)
}
16 changes: 0 additions & 16 deletions agent/ec2/mocks/ec2_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6c045de

Please sign in to comment.