Skip to content

Commit

Permalink
UPSTREAM: 4670: Update awsmachine providerID and instanceID immediate…
Browse files Browse the repository at this point in the history
…ly 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 <mishen@umich.edu>
  • Loading branch information
mjlshen authored and Patryk-Stefanski committed Mar 19, 2024
1 parent 3e23a96 commit da1f259
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/cloud/services/ec2/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ func (s *Service) CreateInstance(scope *scope.MachineScope, userData []byte, use
return nil, err
}

// Set the providerID and instanceID as soon as we create an instance so that we keep it in case of errors afterward
scope.SetProviderID(out.ID, out.AvailabilityZone)
scope.SetInstanceID(out.ID)

if len(input.NetworkInterfaces) > 0 {
for _, id := range input.NetworkInterfaces {
s.scope.Debug("Attaching security groups to provided network interface", "groups", input.SecurityGroupIDs, "interface", id)
Expand All @@ -260,15 +264,15 @@ func (s *Service) CreateInstance(scope *scope.MachineScope, userData []byte, use

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

// Fetching the network interfaces attached to the specific instanace
// Fetching the network interfaces attached to the specific instance
networkInterfaces, err := s.getInstanceENIs(out.ID)
if err != nil {
return nil, err
}

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

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

0 comments on commit da1f259

Please sign in to comment.