in pkg/cloudprovider/aws/instance.go [51:90]
func (p *InstanceProvider) Create(ctx context.Context, constraints *v1alpha1.Constraints, instanceTypes []cloudprovider.InstanceType, quantity int) ([]*v1.Node, error) {
// Launch Instance
ids, err := p.launchInstances(ctx, constraints, instanceTypes, quantity)
if err != nil {
return nil, err
}
// Get Instance with backoff retry since EC2 is eventually consistent
instances := []*ec2.Instance{}
if err := retry.Do(
func() (err error) { instances, err = p.getInstances(ctx, ids); return err },
retry.Delay(1*time.Second),
retry.Attempts(3),
); err != nil && len(instances) == 0 {
return nil, err
} else if err != nil {
logging.FromContext(ctx).Errorf("retrieving node name for %d/%d instances", quantity-len(instances), quantity)
}
nodes := []*v1.Node{}
for _, instance := range instances {
logging.FromContext(ctx).Infof("Launched instance: %s, hostname: %s, type: %s, zone: %s, capacityType: %s",
aws.StringValue(instance.InstanceId),
aws.StringValue(instance.PrivateDnsName),
aws.StringValue(instance.InstanceType),
aws.StringValue(instance.Placement.AvailabilityZone),
getCapacityType(instance),
)
// Convert Instance to Node
node, err := p.instanceToNode(ctx, instance, instanceTypes)
if err != nil {
logging.FromContext(ctx).Errorf("creating Node from an EC2 Instance: %s", err.Error())
continue
}
nodes = append(nodes, node)
}
if len(nodes) == 0 {
return nil, fmt.Errorf("zero nodes were created")
}
return nodes, nil
}