in pkg/aws/ec2/api/wrapper.go [439:485]
func NewEC2Wrapper(roleARN, clusterName, region string, instanceClientQPS, instanceClientBurst,
userClientQPS, userClientBurst int, log logr.Logger,
) (EC2Wrapper, error) {
// Register the metrics
prometheusRegister()
ec2Wrapper := &ec2Wrapper{log: log}
cfg, err := ec2Wrapper.getInstanceConfig()
if err != nil {
return nil, err
}
// Role ARN is passed, assume the role ARN to make EC2 API Calls
if roleARN != "" {
// Create the instance service client with low QPS, it will be only used fro associate branch to trunk calls
log.Info("Creating INSTANCE service client with configured QPS", "QPS", instanceClientQPS, "Burst", instanceClientBurst)
instanceServiceClient, err := ec2Wrapper.getInstanceServiceClient(instanceClientQPS, instanceClientBurst,
*cfg)
if err != nil {
return nil, err
}
ec2Wrapper.instanceServiceClient = instanceServiceClient
// Create the user service client with higher QPS, this will be used to make rest of the EC2 API Calls
log.Info("Creating USER service client with configured QPS", "QPS", userClientQPS, "Burst", userClientBurst)
userServiceClient, err := ec2Wrapper.getClientUsingAssumedRole(cfg.Region, roleARN, clusterName, region,
userClientQPS, userClientBurst)
if err != nil {
return nil, err
}
ec2Wrapper.userServiceClient = userServiceClient
} else {
// Role ARN is not provided, assuming that instance service client is allowlisted for ENI branching and use
// the instance service client as the user service client with higher QPS.
log.Info("Creating INSTANCE service client with configured USER Service QPS", "QPS", userClientQPS, "Burst", userClientBurst)
instanceServiceClient, err := ec2Wrapper.getInstanceServiceClient(userClientQPS,
userClientBurst, *cfg)
if err != nil {
return nil, err
}
ec2Wrapper.instanceServiceClient = instanceServiceClient
ec2Wrapper.userServiceClient = instanceServiceClient
}
return ec2Wrapper, nil
}