Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick (#1526) #1527

Merged
merged 1 commit into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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