diff --git a/bouncer/asgset.go b/bouncer/asgset.go index b0ca3b77..4b728bb8 100644 --- a/bouncer/asgset.go +++ b/bouncer/asgset.go @@ -19,6 +19,7 @@ import ( "time" log "github.com/Sirupsen/logrus" + "github.com/aws/aws-sdk-go/service/autoscaling" "github.com/pkg/errors" "github.com/palantir/bouncer/aws" @@ -54,7 +55,7 @@ func (a *ASGSet) GetImmutableInstances() []*Instance { var instances []*Instance for _, asg := range a.ASGs { for _, inst := range asg.Instances { - if *inst.ASGInstance.LifecycleState == "Terminating" || *inst.ASGInstance.LifecycleState == "Pending" || *inst.ASGInstance.LifecycleState == "Terminating:Proceed" { + if *inst.ASGInstance.LifecycleState == autoscaling.LifecycleStateTerminating || *inst.ASGInstance.LifecycleState == autoscaling.LifecycleStatePending || *inst.ASGInstance.LifecycleState == autoscaling.LifecycleStateTerminatingProceed { instances = append(instances, inst) } } @@ -243,11 +244,21 @@ func (a *ASGSet) IsNewUnhealthy() bool { newUnhealthy := a.GetUnhealthyNewInstances() for _, inst := range newUnhealthy { + state := *inst.ASGInstance.LifecycleState + var msg string + + switch state { + case autoscaling.LifecycleStateTerminating, autoscaling.LifecycleStateTerminatingProceed, autoscaling.LifecycleStateTerminatingWait: + msg = "Waiting for unhealthy new instance to get out of the way" + default: + msg = "Waiting for new instance to become healthy" + } + log.WithFields(log.Fields{ "ASG": *inst.AutoscalingGroup.AutoScalingGroupName, "InstanceID": *inst.ASGInstance.InstanceId, - "State": *inst.ASGInstance.LifecycleState, - }).Info("Waiting for new instance to become healthy") + "State": state, + }).Info(msg) isNewUnhealthy = true } diff --git a/bouncer/runner.go b/bouncer/runner.go index ddefe0b0..42488660 100644 --- a/bouncer/runner.go +++ b/bouncer/runner.go @@ -21,6 +21,7 @@ import ( "time" log "github.com/Sirupsen/logrus" + "github.com/aws/aws-sdk-go/service/autoscaling" "github.com/pkg/errors" "github.com/palantir/bouncer/aws" @@ -56,11 +57,6 @@ const ( asgSeparator = "," desiredCapSeparator = ":" - - // The state instance is in while waiting for autoscaling:EC2_INSTANCE_LAUNCHING transition hook - pendingHookState = "Pending:Wait" - // The state instance is in while waiting for autoscaling:EC2_INSTANCE_TERMINATING transition hook - terminateHookState = "Terminating:Wait" ) func retry(attempts int, sleep time.Duration, callback func() error) (err error) { @@ -165,11 +161,11 @@ func (r *BaseRunner) KillInstance(inst *Instance) error { }).Info("Picked instance to die next") var hook string - if *inst.ASGInstance.LifecycleState == pendingHookState { + if *inst.ASGInstance.LifecycleState == autoscaling.LifecycleStatePendingWait { hook = r.opts.PendingHook } - if *inst.ASGInstance.LifecycleState == terminateHookState { + if *inst.ASGInstance.LifecycleState == autoscaling.LifecycleStateTerminatingWait { hook = r.opts.TerminateHook }