Skip to content

Commit

Permalink
Don't try to set SourceDestCheck on terminated instances
Browse files Browse the repository at this point in the history
  • Loading branch information
justinsb committed Jun 4, 2016
1 parent ce5a1f1 commit 3f29807
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions pkg/awscontroller/instances/instancescontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ type instance struct {
}

func (c *InstancesController) runLoop() {
// TODO: A better way to run right away?
go wait.Until(func() {
if err := c.runOnce(); err != nil {
runtime.HandleError(err)
Expand Down Expand Up @@ -144,13 +143,35 @@ func (c *InstancesController) runOnce() error {
}

for _, i := range c.instances {
id := i.ID

if i.sequence != sequence {
glog.Infof("Instance deleted: %q", i.ID)
delete(c.instances, i.ID)
glog.Infof("Instance deleted: %q", id)
delete(c.instances, id)
continue
}

if c.SourceDestCheck != nil && *c.SourceDestCheck != aws.BoolValue(i.status.SourceDestCheck) {
canSetSourceDestCheck := false
instanceStateName := aws.StringValue(i.status.State.Name)
switch (instanceStateName) {
case "pending":
glog.V(2).Infof("Ignoring pending instance: %q", id)
case "running":
canSetSourceDestCheck = true
case "shutting-down":
// ignore
case "terminated":
// ignore
case "stopping":
canSetSourceDestCheck = true
case "stopped":
canSetSourceDestCheck = true

default:
runtime.HandleError(fmt.Errorf("unknown instance state for instance %q: %q", id, instanceStateName))
}

if canSetSourceDestCheck && c.SourceDestCheck != nil && *c.SourceDestCheck != aws.BoolValue(i.status.SourceDestCheck) {
err := c.configureInstanceSourceDestCheck(i.ID, *c.SourceDestCheck)
if err != nil {
runtime.HandleError(fmt.Errorf("failed to configure SourceDestCheck for instance %q: %v", i.ID, err))
Expand Down

0 comments on commit 3f29807

Please sign in to comment.