Skip to content

Commit

Permalink
If instance is in standby mode already, just return (#138)
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg Atamanenko <[email protected]>

Co-authored-by: Shri Javadekar <[email protected]>
  • Loading branch information
uthark and shrinandj authored Nov 19, 2020
1 parent e2b197d commit 6cb6678
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion controllers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func getInServiceIds(instances []*autoscaling.Instance) []string {
return list
}

func getGroupInstanceState(group *autoscaling.Group, instanceID string) (string, error) {
func getInstanceStateInASG(group *autoscaling.Group, instanceID string) (string, error) {
for _, instance := range group.Instances {
if aws.StringValue(instance.InstanceId) == instanceID {
return aws.StringValue(instance.LifecycleState), nil
Expand Down
17 changes: 11 additions & 6 deletions controllers/rollingupgrade_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,28 +334,33 @@ func (r *RollingUpgradeReconciler) GetAutoScalingGroup(rollupName string) (*auto
// SetStandby sets the autoscaling instance to standby mode.
func (r *RollingUpgradeReconciler) SetStandby(ruObj *upgrademgrv1alpha1.RollingUpgrade, instanceID string) error {
r.info(ruObj, "Setting to stand-by", ruObj.Name, instanceID)
input := &autoscaling.EnterStandbyInput{
AutoScalingGroupName: aws.String(ruObj.Spec.AsgName),
InstanceIds: aws.StringSlice([]string{instanceID}),
ShouldDecrementDesiredCapacity: aws.Bool(false),
}

asg, err := r.GetAutoScalingGroup(ruObj.Name)
if err != nil {
return err
}

instanceState, err := getGroupInstanceState(asg, instanceID)
instanceState, err := getInstanceStateInASG(asg, instanceID)
if err != nil {
r.info(ruObj, fmt.Sprintf("WARNING: %v", err))
return nil
}

if instanceState == autoscaling.LifecycleStateStandby {
return nil
}

if !isInServiceLifecycleState(instanceState) {
r.info(ruObj, "Cannot set instance to stand-by, instance is in state", "instanceState", instanceState, "instanceID", instanceID)
return nil
}

input := &autoscaling.EnterStandbyInput{
AutoScalingGroupName: aws.String(ruObj.Spec.AsgName),
InstanceIds: aws.StringSlice([]string{instanceID}),
ShouldDecrementDesiredCapacity: aws.Bool(false),
}

_, err = r.ASGClient.EnterStandby(input)
if err != nil {
r.error(ruObj, err, "Failed to enter standby", "instanceID", instanceID)
Expand Down

0 comments on commit 6cb6678

Please sign in to comment.