Skip to content

Commit

Permalink
non-nitro instances init issues (#1526)
Browse files Browse the repository at this point in the history
* non-nitro init issues

* fix formatting
  • Loading branch information
jayanthvn authored Jul 2, 2021
1 parent c9adb9e commit 0af437a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
13 changes: 9 additions & 4 deletions pkg/awsutils/awsutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ type APIs interface {

//GetInstanceType returns the EC2 instance type
GetInstanceType() string

//Update cached prefix delegation flag
InitCachedPrefixDelegation(bool)
}

// EC2InstanceMetadataCache caches instance metadata
Expand Down Expand Up @@ -339,7 +342,7 @@ func (i instrumentedIMDS) GetMetadataWithContext(ctx context.Context, p string)
}

// New creates an EC2InstanceMetadataCache
func New(useCustomNetworking, enableIpv4PrefixDelegation bool) (*EC2InstanceMetadataCache, error) {
func New(useCustomNetworking bool) (*EC2InstanceMetadataCache, error) {
//ctx is passed to initWithEC2Metadata func to cancel spawned go-routines when tests are run
ctx := context.Background()

Expand All @@ -365,9 +368,6 @@ func New(useCustomNetworking, enableIpv4PrefixDelegation bool) (*EC2InstanceMeta
cache.useCustomNetworking = useCustomNetworking
log.Infof("Custom networking enabled %v", cache.useCustomNetworking)

cache.enableIpv4PrefixDelegation = enableIpv4PrefixDelegation
log.Infof("Prefix Delegation enabled %v", cache.enableIpv4PrefixDelegation)

awsCfg := aws.NewConfig().WithRegion(region)
sess = sess.Copy(awsCfg)

Expand All @@ -384,6 +384,11 @@ func New(useCustomNetworking, enableIpv4PrefixDelegation bool) (*EC2InstanceMeta
return cache, nil
}

func (cache *EC2InstanceMetadataCache) InitCachedPrefixDelegation(enableIpv4PrefixDelegation bool) {
cache.enableIpv4PrefixDelegation = enableIpv4PrefixDelegation
log.Infof("Prefix Delegation enabled %v", cache.enableIpv4PrefixDelegation)
}

// InitWithEC2metadata initializes the EC2InstanceMetadataCache with the data retrieved from EC2 metadata service
func (cache *EC2InstanceMetadataCache) initWithEC2Metadata(ctx context.Context) error {
var err error
Expand Down
26 changes: 12 additions & 14 deletions pkg/awsutils/mocks/awsutils_mocks.go

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

3 changes: 2 additions & 1 deletion pkg/ipamd/ipamd.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func New(rawK8SClient client.Client, cachedK8SClient client.Client) (*IPAMContex
c.useCustomNetworking = UseCustomNetworkCfg()
c.enableIpv4PrefixDelegation = useIpv4PrefixDelegation()

client, err := awsutils.New(c.useCustomNetworking, c.enableIpv4PrefixDelegation)
client, err := awsutils.New(c.useCustomNetworking)
if err != nil {
return nil, errors.Wrap(err, "ipamd: can not initialize with AWS SDK interface")
}
Expand All @@ -329,6 +329,7 @@ func New(rawK8SClient client.Client, cachedK8SClient client.Client) (*IPAMContex
log.Warnf("Prefix delegation is not supported on non-nitro instance %s hence falling back to default (secondary IP) mode", c.awsClient.GetInstanceType())
c.enableIpv4PrefixDelegation = false
}
c.awsClient.InitCachedPrefixDelegation(c.enableIpv4PrefixDelegation)
c.myNodeName = os.Getenv("MY_NODE_NAME")
checkpointer := datastore.NewJSONFile(dsBackingStorePath())
c.dataStore = datastore.NewDataStore(log, checkpointer, c.enableIpv4PrefixDelegation)
Expand Down

0 comments on commit 0af437a

Please sign in to comment.