Skip to content

Commit

Permalink
Consider non-terminated instances to be existing
Browse files Browse the repository at this point in the history
Currently, any non-existing instance is recreated during machine reconciliation.
In case an AWS instance is stopped for maintenance purposes, it is considered
as it would be terminated. Which is not the expected behaviour.
Instead, consider such instance to be existing until its status changes back to
running or is terminated.

Side effect: stopped worker machines will not get reconciled.
  • Loading branch information
ingvagabund committed May 30, 2019
1 parent 461e8d0 commit 57f8907
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/actuators/machine/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ func (a *Actuator) getMachineInstances(cluster *clusterv1.Cluster, machine *mach
return nil, fmt.Errorf("error getting EC2 client: %v", err)
}

return getRunningInstances(machine, client)
return getExistingInstances(machine, client)
}

// updateLoadBalancers adds a given machine instance to the load balancers specified in its provider config
Expand Down
10 changes: 10 additions & 0 deletions pkg/actuators/machine/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ func getStoppedInstances(machine *machinev1.Machine, client awsclient.Client) ([
return getInstances(machine, client, stoppedInstanceStateFilter)
}

func getExistingInstances(machine *machinev1.Machine, client awsclient.Client) ([]*ec2.Instance, error) {
return getInstances(machine, client, []*string{
aws.String(ec2.InstanceStateNameRunning),
aws.String(ec2.InstanceStateNamePending),
aws.String(ec2.InstanceStateNameStopped),
aws.String(ec2.InstanceStateNameStopping),
aws.String(ec2.InstanceStateNameShuttingDown),
})
}

// getInstances returns all instances that have a tag matching our machine name,
// and cluster ID.
func getInstances(machine *machinev1.Machine, client awsclient.Client, instanceStateFilter []*string) ([]*ec2.Instance, error) {
Expand Down

0 comments on commit 57f8907

Please sign in to comment.