Skip to content

Commit 0c62661

Browse files
committed
Update awsmachine providerID and instanceID immediately after ec2:RunInstances is called
This mitigates issues caused by falling back to tag-based searching for EC2 instances in case future AWS calls fail, such as attaching ENIs to security groups or tagging ENIs. Signed-off-by: Michael Shen <[email protected]>
1 parent c9b9276 commit 0c62661

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pkg/cloud/services/ec2/instances.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ func (s *Service) CreateInstance(scope *scope.MachineScope, userData []byte, use
250250
return nil, err
251251
}
252252

253+
// Set the providerID and instanceID as soon as we create an instance so that we keep it in case of errors afterward
254+
scope.SetProviderID(out.ID, out.AvailabilityZone)
255+
scope.SetInstanceID(out.ID)
256+
253257
if len(input.NetworkInterfaces) > 0 {
254258
for _, id := range input.NetworkInterfaces {
255259
s.scope.Debug("Attaching security groups to provided network interface", "groups", input.SecurityGroupIDs, "interface", id)
@@ -261,15 +265,15 @@ func (s *Service) CreateInstance(scope *scope.MachineScope, userData []byte, use
261265

262266
s.scope.Debug("Adding tags on each network interface from resource", "resource-id", out.ID)
263267

264-
// Fetching the network interfaces attached to the specific instanace
268+
// Fetching the network interfaces attached to the specific instance
265269
networkInterfaces, err := s.getInstanceENIs(out.ID)
266270
if err != nil {
267271
return nil, err
268272
}
269273

270274
s.scope.Debug("Fetched the network interfaces")
271275

272-
// Once all the network interfaces attached to the specific instanace are found, the similar tags of instance are created for network interfaces too
276+
// Once all the network interfaces attached to the specific instance are found, the similar tags of instance are created for network interfaces too
273277
if len(networkInterfaces) > 0 {
274278
s.scope.Debug("Attempting to create tags from resource", "resource-id", out.ID)
275279
for _, networkInterface := range networkInterfaces {

0 commit comments

Comments
 (0)