Repository: keikoproj/upgrade-manager
Pull request #20 (2019-10-01 19:17:04)

using TerminateInstanceInAutoScalingGroup instead of TerminateInstances
resolves issue #18 

 * Updates for using TerminateInstanceInAutoScalingGroup
 * removed imports of ec2iface and ec2
 * Updated tests to use autoscaling interface.

CLAassistant: [![CLA assistant check](https://cla-assistant.io/pull/badge/not_signed)](https://cla-assistant.io/keikoproj/upgrade-manager?pullRequest=20) <br/>Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our [Contributor License Agreement](https://cla-assistant.io/keikoproj/upgrade-manager?pullRequest=20) before we can accept your contribution.<br/><sub>You have signed the CLA already but the status is still pending? Let us [recheck](https://cla-assistant.io/check/keikoproj/upgrade-manager?pullRequest=20) it.</sub>
shrinandj: The build failed with the following errors:

```
# github.com/keikoproj/upgrade-manager/controllers
--
  | controllers/rollingupgrade_controller.go:213:115: undefined: autoscalingiface.AutoscalingAPI
  | controllers/rollingupgrade_controller.go:215:12: undefined: autoscaling.TerminateInstanceInAutoscalingGroupInput
  | controllers/rollingupgrade_controller.go:349:115: undefined: autoscalingiface.AutoscalingAPI
  | controllers/rollingupgrade_controller.go:622:117: undefined: autoscalingiface.AutoscalingAPI
  | controllers/rollingupgrade_controller.go:693:196: undefined: autoscalingiface.AutoscalingAPI
  | # github.com/keikoproj/upgrade-manager/controllers [github.com/keikoproj/upgrade-manager/controllers.test]
  | controllers/rollingupgrade_controller.go:213:115: undefined: autoscalingiface.AutoscalingAPI
  | controllers/rollingupgrade_controller.go:215:12: undefined: autoscaling.TerminateInstanceInAutoscalingGroupInput
  | controllers/rollingupgrade_controller.go:349:115: undefined: autoscalingiface.AutoscalingAPI
  | controllers/rollingupgrade_controller.go:622:117: undefined: autoscalingiface.AutoscalingAPI
  | controllers/rollingupgrade_controller.go:693:196: undefined: autoscalingiface.AutoscalingAPI
  | make: *** [Makefile:42: vet] Error 2
```
https://keikoproj-upgrade-manager.semaphoreci.com/jobs/18fc9eb1-8f2e-412f-ac56-668871061318
deepakbenny: Not able to view https://keikoproj-upgrade-manager.semaphoreci.com/jobs/18fc9eb1-8f2e-412f-ac56-668871061318, returning a 404.

Will check if i can set this up locally.
deepakbenny: @shrinandj can you please share the logs from the build. My local build is working fine.
kianjones4: @deepakbenny logs: 
> 2019/10/02 10:00:53 foo: Waiting for postDrainDelay
>   | --- FAIL: TestDrainNodePostDrainFailureToDrain (0.00s)
>   | rollingupgrade_controller_test.go:285:
>   | Expected
>   | <nil>: nil
>   | not to be nil
>   | --- FAIL: TestTerminateNodeSuccess (0.00s)
>   | panic: runtime error: invalid memory address or nil pointer dereference [recovered]
>   | panic: runtime error: invalid memory address or nil pointer dereference
>   | [signal SIGSEGV: segmentation violation code=0x1 addr=0x578 pc=0x13ff0a2]
>   |  
>   | goroutine 374 [running]:
>   | testing.tRunner.func1(0xc0000ed800)
>   | /usr/local/go/src/testing/testing.go:830 +0x392
>   | panic(0x15753a0, 0x2793240)
>   | /usr/local/go/src/runtime/panic.go:522 +0x1b5
>   | github.com/keikoproj/upgrade-manager/controllers.(*MockAutoscalingGroup).TerminateInstanceInAutoScalingGroup(0xc000550bd0, 0xc000552bc0, 0x7f54c5e1fe10, 0xc000423be0, 0x40d829)
>   | <autogenerated>:1 +0x32
>   | github.com/keikoproj/upgrade-manager/controllers.(*RollingUpgradeReconciler).TerminateNode(0xc000423ce0, 0xc0003afd78, 0x172f44d, 0xc, 0x1a730a0, 0xc000550bd0, 0x203000, 0x19)
>   | /root/upgrade-manager-v1/controllers/rollingupgrade_controller.go:220 +0xee
>   | github.com/keikoproj/upgrade-manager/controllers.TestTerminateNodeSuccess(0xc0000ed800)
>   | /root/upgrade-manager-v1/controllers/rollingupgrade_controller_test.go:315 +0x1e5
>   | testing.tRunner(0xc0000ed800, 0x17c8180)
>   | /usr/local/go/src/testing/testing.go:865 +0xc0
>   | created by testing.(*T).Run
>   | /usr/local/go/src/testing/testing.go:916 +0x35a
>   | FAIL	github.com/keikoproj/upgrade-manager/controllers	3.995s
>   | make: *** [Makefile:13: test] Error 1
>   | exit code: 2 duration: 120s

can you install [kubebuilder](https://book-v1.book.kubebuilder.io/getting_started/installation_and_setup.html) and try running `make test`? That way you can see where your build is failing.
deepakbenny: @kianjones4 @shrinandj can you please review?

Patch:
diff --git a/controllers/rollingupgrade_controller.go b/controllers/rollingupgrade_controller.go
index 432daf7..6277ef4 100644
--- a/controllers/rollingupgrade_controller.go
+++ b/controllers/rollingupgrade_controller.go
@@ -19,7 +19,6 @@ import (
 	"context"
 	"errors"
 	"fmt"
-	"k8s.io/apimachinery/pkg/util/intstr"
 	"log"
 	"os"
 	"os/exec"
@@ -28,6 +27,8 @@ import (
 	"sync"
 	"time"
 
+	"k8s.io/apimachinery/pkg/util/intstr"
+
 	corev1 "k8s.io/api/core/v1"
 
 	"github.com/aws/aws-sdk-go/aws"
@@ -35,8 +36,6 @@ import (
 	"github.com/aws/aws-sdk-go/aws/session"
 	"github.com/aws/aws-sdk-go/service/autoscaling"
 	"github.com/aws/aws-sdk-go/service/autoscaling/autoscalingiface"
-	"github.com/aws/aws-sdk-go/service/ec2"
-	"github.com/aws/aws-sdk-go/service/ec2/ec2iface"
 
 	"github.com/go-logr/logr"
 	k8serrors "k8s.io/apimachinery/pkg/api/errors"
@@ -89,7 +88,6 @@ type RollingUpgradeReconciler struct {
 
 func runScript(script string, background bool, objName string) (string, error) {
 	log.Printf("%s: Running script %s", objName, script)
-
 	if background {
 		log.Printf("%s: Running script in background. Logs not available.", objName)
 		exec.Command(ShellBinary, "-c", script).Run()
@@ -212,20 +210,23 @@ func (r *RollingUpgradeReconciler) CallKubectlDrain(ctx context.Context, nodeNam
 }
 
 // TerminateNode actually terminates the given node.
-func (r *RollingUpgradeReconciler) TerminateNode(ruObj *upgrademgrv1alpha1.RollingUpgrade, instanceID string, svc ec2iface.EC2API) error {
+func (r *RollingUpgradeReconciler) TerminateNode(ruObj *upgrademgrv1alpha1.RollingUpgrade, instanceID string, svc autoscalingiface.AutoScalingAPI) error {
 
-	input := &ec2.TerminateInstancesInput{
-		InstanceIds: []*string{
-			aws.String(instanceID),
-		},
+	input := &autoscaling.TerminateInstanceInAutoScalingGroupInput{
+		InstanceId:                     aws.String(instanceID),
+		ShouldDecrementDesiredCapacity: aws.Bool(false),
 	}
 
-	result, err := svc.TerminateInstances(input)
+	result, err := svc.TerminateInstanceInAutoScalingGroup(input)
 	if err != nil {
 		if aerr, ok := err.(awserr.Error); ok {
 			switch aerr.Code() {
 			case "InvalidInstanceID.NotFound":
 				log.Printf("Instance %s not found. Moving on\n", instanceID)
+			case autoscaling.ErrCodeScalingActivityInProgressFault:
+				log.Println(autoscaling.ErrCodeScalingActivityInProgressFault, aerr.Error())
+			case autoscaling.ErrCodeResourceContentionFault:
+				log.Println(autoscaling.ErrCodeResourceContentionFault, aerr.Error())
 				return nil
 			default:
 				log.Println(aerr.Error())
@@ -345,7 +346,7 @@ func loadEnvironmentVariables(ruObj *upgrademgrv1alpha1.RollingUpgrade, nodeInst
 	return nil
 }
 
-func (r *RollingUpgradeReconciler) runRestack(ctx *context.Context, ruObj *upgrademgrv1alpha1.RollingUpgrade, svc ec2iface.EC2API, KubeCtlCall string) (int, error) {
+func (r *RollingUpgradeReconciler) runRestack(ctx *context.Context, ruObj *upgrademgrv1alpha1.RollingUpgrade, svc autoscalingiface.AutoScalingAPI, KubeCtlCall string) (int, error) {
 	// Setting default values for the Strategy in rollup object
 	r.setDefaultsForRollingUpdateStrategy(ruObj)
 
@@ -443,13 +444,8 @@ func (r *RollingUpgradeReconciler) Process(ctx *context.Context, ruObj *upgradem
 	ruObj.Status.TotalNodes = len(asg.Instances)
 	r.Update(*ctx, ruObj)
 
-	ec2Sess, _ := session.NewSession(&aws.Config{
-		Region: aws.String(ruObj.Spec.Region)},
-	)
-	ec2Svc := ec2.New(ec2Sess)
-
 	// Run the restack that acutally performs the rolling update.
-	nodesProcessed, err := r.runRestack(ctx, ruObj, ec2Svc, KubeCtlBinary)
+	nodesProcessed, err := r.runRestack(ctx, ruObj, svc, KubeCtlBinary)
 	if err != nil {
 		return r.finishExecution(StatusError, nodesProcessed, ctx, ruObj)
 	}
@@ -623,7 +619,7 @@ func (r *RollingUpgradeReconciler) setDefaultsForRollingUpdateStrategy(ruObj *up
 
 // RandomUpdate treats all the azs as a single unit and picks random nodes for update
 // and rolls out the update based on the input parameters
-func (r *RollingUpgradeReconciler) RandomUpdate(ctx *context.Context, ruObj *upgrademgrv1alpha1.RollingUpgrade, svc ec2iface.EC2API, KubeCtlCall string) (int, error) {
+func (r *RollingUpgradeReconciler) RandomUpdate(ctx *context.Context, ruObj *upgrademgrv1alpha1.RollingUpgrade, svc autoscalingiface.AutoScalingAPI, KubeCtlCall string) (int, error) {
 
 	value, ok := r.ruObjNameToASG.Load(ruObj.Name)
 	if !ok {
@@ -694,7 +690,7 @@ func (r *RollingUpgradeReconciler) RandomUpdate(ctx *context.Context, ruObj *upg
 	return nodesProcessed, nil
 }
 
-func (r *RollingUpgradeReconciler) UpdateInstance(ctx *context.Context, ruObj *upgrademgrv1alpha1.RollingUpgrade, i *autoscaling.Instance, currentLaunchConfigName string, KubeCtlCall string, svc ec2iface.EC2API, drainTimeout int, ch chan error) {
+func (r *RollingUpgradeReconciler) UpdateInstance(ctx *context.Context, ruObj *upgrademgrv1alpha1.RollingUpgrade, i *autoscaling.Instance, currentLaunchConfigName string, KubeCtlCall string, svc autoscalingiface.AutoScalingAPI, drainTimeout int, ch chan error) {
 
 	targetLaunchConfigName := aws.StringValue(i.LaunchConfigurationName)
 	targetInstanceID := aws.StringValue(i.InstanceId)


Test patch:
diff --git a/controllers/rollingupgrade_controller_test.go b/controllers/rollingupgrade_controller_test.go
index fc4144f..9c343c8 100644
--- a/controllers/rollingupgrade_controller_test.go
+++ b/controllers/rollingupgrade_controller_test.go
@@ -3,8 +3,6 @@ package controllers
 import (
 	"encoding/json"
 	"fmt"
-	"gopkg.in/yaml.v2"
-	"k8s.io/apimachinery/pkg/util/intstr"
 	"log"
 	"os"
 	"path/filepath"
@@ -12,10 +10,13 @@ import (
 	"testing"
 	"time"
 
+	"k8s.io/apimachinery/pkg/util/intstr"
+
+	"gopkg.in/yaml.v2"
+
+	"github.com/aws/aws-sdk-go/aws"
 	"github.com/aws/aws-sdk-go/aws/awserr"
 	"github.com/aws/aws-sdk-go/service/autoscaling/autoscalingiface"
-	"github.com/aws/aws-sdk-go/service/ec2"
-	"github.com/aws/aws-sdk-go/service/ec2/ec2iface"
 	"github.com/pkg/errors"
 
 	"github.com/aws/aws-sdk-go/service/autoscaling"
@@ -284,22 +285,21 @@ func TestDrainNodePostDrainFailureToDrain(t *testing.T) {
 	g.Expect(err).To(gomega.Not(gomega.BeNil()))
 }
 
-type MockEC2Instance struct {
-	ec2iface.EC2API
+type MockAutoscalingGroup struct {
+	autoscalingiface.AutoScalingAPI
 	errorFlag bool
 	awsErr    awserr.Error
 }
 
-func (mockEC2Instance MockEC2Instance) TerminateInstances(input *ec2.TerminateInstancesInput) (*ec2.TerminateInstancesOutput, error) {
-	output := &ec2.TerminateInstancesOutput{}
-	if mockEC2Instance.errorFlag {
-		if mockEC2Instance.awsErr != nil {
-			return output, mockEC2Instance.awsErr
+func (mockAutoscalingGroup MockAutoscalingGroup) TerminateInstanceInAutoScalingGroup(input *autoscaling.TerminateInstanceInAutoScalingGroupInput) (*autoscaling.TerminateInstanceInAutoScalingGroupOutput, error) {
+	output := &autoscaling.TerminateInstanceInAutoScalingGroupOutput{}
+	if mockAutoscalingGroup.errorFlag {
+		if mockAutoscalingGroup.awsErr != nil {
+			return output, mockAutoscalingGroup.awsErr
 		}
 	}
-	name := input.InstanceIds[0]
-	instanceChange := ec2.InstanceStateChange{InstanceId: name}
-	output.TerminatingInstances = []*ec2.InstanceStateChange{&instanceChange}
+	asgChange := autoscaling.Activity{ActivityId: aws.String("xxx"), AutoScalingGroupName: aws.String("sss"), Cause: aws.String("xxx"), StartTime: aws.Time(time.Now()), StatusCode: aws.String("200"), StatusMessage: aws.String("success")}
+	output.Activity = &asgChange
 	return output, nil
 }
 
@@ -309,9 +309,8 @@ func TestTerminateNodeSuccess(t *testing.T) {
 
 	ruObj := &upgrademgrv1alpha1.RollingUpgrade{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"}}
 	rcRollingUpgrade := &RollingUpgradeReconciler{ClusterState: NewClusterState()}
-	mockEC2Instance := MockEC2Instance{errorFlag: false, awsErr: nil}
-
-	err := rcRollingUpgrade.TerminateNode(ruObj, mockNode, mockEC2Instance)
+	mockAutoscalingGroup := MockAutoscalingGroup{errorFlag: false, awsErr: nil}
+	err := rcRollingUpgrade.TerminateNode(ruObj, mockNode, mockAutoscalingGroup)
 	g.Expect(err).To(gomega.BeNil())
 }
 
@@ -321,11 +320,11 @@ func TestTerminateNodeErrorNotFound(t *testing.T) {
 
 	ruObj := &upgrademgrv1alpha1.RollingUpgrade{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"}}
 	rcRollingUpgrade := &RollingUpgradeReconciler{ClusterState: NewClusterState()}
-	mockEC2Instance := MockEC2Instance{errorFlag: true, awsErr: awserr.New("InvalidInstanceID.NotFound",
+	mockAutoscalingGroup := MockAutoscalingGroup{errorFlag: true, awsErr: awserr.New("InvalidInstanceID.NotFound",
 		"some message",
 		nil)}
 
-	err := rcRollingUpgrade.TerminateNode(ruObj, mockNode, mockEC2Instance)
+	err := rcRollingUpgrade.TerminateNode(ruObj, mockNode, mockAutoscalingGroup)
 	g.Expect(err).To(gomega.BeNil())
 }
 
@@ -335,11 +334,11 @@ func TestTerminateNodeErrorOtherError(t *testing.T) {
 
 	ruObj := &upgrademgrv1alpha1.RollingUpgrade{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"}}
 	rcRollingUpgrade := &RollingUpgradeReconciler{ClusterState: NewClusterState()}
-	mockEC2Instance := MockEC2Instance{errorFlag: true, awsErr: awserr.New("some-other-aws-error",
+	mockAutoscalingGroup := MockAutoscalingGroup{errorFlag: true, awsErr: awserr.New("some-other-aws-error",
 		"some message",
 		errors.New("some error"))}
 
-	err := rcRollingUpgrade.TerminateNode(ruObj, mockNode, mockEC2Instance)
+	err := rcRollingUpgrade.TerminateNode(ruObj, mockNode, mockAutoscalingGroup)
 	g.Expect(err.Error()).To(gomega.ContainSubstring("some error"))
 }
 
@@ -350,9 +349,9 @@ func TestTerminateNodePostTerminateScriptSuccess(t *testing.T) {
 	ruObj := &upgrademgrv1alpha1.RollingUpgrade{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"}}
 	ruObj.Spec.PostTerminate.Script = "echo hello!"
 	rcRollingUpgrade := &RollingUpgradeReconciler{ClusterState: NewClusterState()}
-	mockEC2Instance := MockEC2Instance{errorFlag: false, awsErr: nil}
+	mockAutoscalingGroup := MockAutoscalingGroup{errorFlag: false, awsErr: nil}
 
-	err := rcRollingUpgrade.TerminateNode(ruObj, mockNode, mockEC2Instance)
+	err := rcRollingUpgrade.TerminateNode(ruObj, mockNode, mockAutoscalingGroup)
 	g.Expect(err).To(gomega.BeNil())
 }
 
@@ -363,9 +362,9 @@ func TestTerminateNodePostTerminateScriptErrorNotFoundFromServer(t *testing.T) {
 	ruObj := &upgrademgrv1alpha1.RollingUpgrade{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"}}
 	ruObj.Spec.PostTerminate.Script = "echo 'Error from server (NotFound)'; exit 1"
 	rcRollingUpgrade := &RollingUpgradeReconciler{ClusterState: NewClusterState()}
-	mockEC2Instance := MockEC2Instance{errorFlag: false, awsErr: nil}
+	mockAutoscalingGroup := MockAutoscalingGroup{errorFlag: false, awsErr: nil}
 
-	err := rcRollingUpgrade.TerminateNode(ruObj, mockNode, mockEC2Instance)
+	err := rcRollingUpgrade.TerminateNode(ruObj, mockNode, mockAutoscalingGroup)
 	g.Expect(err).To(gomega.BeNil())
 }
 
@@ -376,9 +375,9 @@ func TestTerminateNodePostTerminateScriptErrorOtherError(t *testing.T) {
 	ruObj := &upgrademgrv1alpha1.RollingUpgrade{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"}}
 	ruObj.Spec.PostTerminate.Script = "exit 1"
 	rcRollingUpgrade := &RollingUpgradeReconciler{ClusterState: NewClusterState()}
-	mockEC2Instance := MockEC2Instance{errorFlag: false, awsErr: nil}
+	mockAutoscalingGroup := MockAutoscalingGroup{errorFlag: false, awsErr: nil}
 
-	err := rcRollingUpgrade.TerminateNode(ruObj, mockNode, mockEC2Instance)
+	err := rcRollingUpgrade.TerminateNode(ruObj, mockNode, mockAutoscalingGroup)
 	g.Expect(err).To(gomega.Not(gomega.BeNil()))
 	g.Expect(err.Error()).To(gomega.HavePrefix("Failed to run postTerminate script: "))
 }
@@ -704,7 +703,7 @@ func TestRunRestackSuccessOneNode(t *testing.T) {
 		ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"},
 		Spec:       upgrademgrv1alpha1.RollingUpgradeSpec{AsgName: someAsg},
 	}
-	mockEC2Instance := MockEC2Instance{}
+	mockAutoscalingGroup := MockAutoscalingGroup{}
 
 	mgr, err := manager.New(cfg, manager.Options{})
 	g.Expect(err).NotTo(gomega.HaveOccurred())
@@ -729,7 +728,7 @@ func TestRunRestackSuccessOneNode(t *testing.T) {
 
 	ctx := context.TODO()
 
-	nodesProcessed, err := rcRollingUpgrade.runRestack(&ctx, ruObj, mockEC2Instance, "exit 0;")
+	nodesProcessed, err := rcRollingUpgrade.runRestack(&ctx, ruObj, mockAutoscalingGroup, "exit 0;")
 	g.Expect(nodesProcessed).To(gomega.Equal(1))
 	g.Expect(err).To(gomega.BeNil())
 }
@@ -750,7 +749,7 @@ func TestRunRestackSuccessMultipleNodes(t *testing.T) {
 
 	ruObj := &upgrademgrv1alpha1.RollingUpgrade{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"},
 		Spec: upgrademgrv1alpha1.RollingUpgradeSpec{AsgName: someAsg}}
-	mockEC2Instance := MockEC2Instance{}
+	mockAutoscalingGroup := MockAutoscalingGroup{}
 
 	mgr, err := manager.New(cfg, manager.Options{})
 	g.Expect(err).NotTo(gomega.HaveOccurred())
@@ -776,7 +775,7 @@ func TestRunRestackSuccessMultipleNodes(t *testing.T) {
 
 	ctx := context.TODO()
 
-	nodesProcessed, err := rcRollingUpgrade.runRestack(&ctx, ruObj, mockEC2Instance, "exit 0;")
+	nodesProcessed, err := rcRollingUpgrade.runRestack(&ctx, ruObj, mockAutoscalingGroup, "exit 0;")
 	g.Expect(nodesProcessed).To(gomega.Equal(2))
 	g.Expect(err).To(gomega.BeNil())
 }
@@ -794,7 +793,7 @@ func TestRunRestackSameLaunchConfig(t *testing.T) {
 
 	ruObj := &upgrademgrv1alpha1.RollingUpgrade{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"},
 		Spec: upgrademgrv1alpha1.RollingUpgradeSpec{AsgName: someAsg}}
-	mockEC2Instance := MockEC2Instance{}
+	mockAutoscalingGroup := MockAutoscalingGroup{}
 
 	mgr, err := manager.New(cfg, manager.Options{})
 	g.Expect(err).NotTo(gomega.HaveOccurred())
@@ -812,7 +811,7 @@ func TestRunRestackSameLaunchConfig(t *testing.T) {
 	ctx := context.TODO()
 
 	// This execution should not perform drain or termination, but should pass
-	nodesProcessed, err := rcRollingUpgrade.runRestack(&ctx, ruObj, mockEC2Instance, KubeCtlBinary)
+	nodesProcessed, err := rcRollingUpgrade.runRestack(&ctx, ruObj, mockAutoscalingGroup, KubeCtlBinary)
 	g.Expect(nodesProcessed).To(gomega.Equal(1))
 	g.Expect(err).To(gomega.BeNil())
 }
@@ -821,12 +820,12 @@ func TestRunRestackRollingUpgradeNotInMap(t *testing.T) {
 	g := gomega.NewGomegaWithT(t)
 
 	ruObj := &upgrademgrv1alpha1.RollingUpgrade{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"}}
-	mockEC2Instance := MockEC2Instance{}
+	mockAutoscalingGroup := MockAutoscalingGroup{}
 	rcRollingUpgrade := &RollingUpgradeReconciler{ClusterState: NewClusterState()}
 	ctx := context.TODO()
 
 	g.Expect(rcRollingUpgrade.ruObjNameToASG.Load(ruObj.Name)).To(gomega.BeNil())
-	int, err := rcRollingUpgrade.runRestack(&ctx, ruObj, mockEC2Instance, KubeCtlBinary)
+	int, err := rcRollingUpgrade.runRestack(&ctx, ruObj, mockAutoscalingGroup, KubeCtlBinary)
 	g.Expect(int).To(gomega.Equal(0))
 	g.Expect(err).To(gomega.Not(gomega.BeNil()))
 	g.Expect(err.Error()).To(gomega.HavePrefix("Failed to find rollingUpgrade/ name in map."))
@@ -846,7 +845,7 @@ func TestRunRestackRollingUpgradeNodeNameNotFound(t *testing.T) {
 
 	ruObj := &upgrademgrv1alpha1.RollingUpgrade{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"},
 		Spec: upgrademgrv1alpha1.RollingUpgradeSpec{AsgName: someAsg}}
-	mockEC2Instance := MockEC2Instance{}
+	mockAutoscalingGroup := MockAutoscalingGroup{}
 
 	mgr, err := manager.New(cfg, manager.Options{})
 	g.Expect(err).NotTo(gomega.HaveOccurred())
@@ -866,7 +865,7 @@ func TestRunRestackRollingUpgradeNodeNameNotFound(t *testing.T) {
 	ctx := context.TODO()
 
 	// This execution gets past the different launch config check, but fails to be found at the node level
-	nodesProcessed, err := rcRollingUpgrade.runRestack(&ctx, ruObj, mockEC2Instance, KubeCtlBinary)
+	nodesProcessed, err := rcRollingUpgrade.runRestack(&ctx, ruObj, mockAutoscalingGroup, KubeCtlBinary)
 	g.Expect(nodesProcessed).To(gomega.Equal(1))
 	g.Expect(err).To(gomega.BeNil())
 }
@@ -885,7 +884,7 @@ func TestRunRestackNoNodeName(t *testing.T) {
 
 	ruObj := &upgrademgrv1alpha1.RollingUpgrade{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"},
 		Spec: upgrademgrv1alpha1.RollingUpgradeSpec{AsgName: someAsg}}
-	mockEC2Instance := MockEC2Instance{}
+	mockAutoscalingGroup := MockAutoscalingGroup{}
 
 	mgr, err := manager.New(cfg, manager.Options{})
 	g.Expect(err).NotTo(gomega.HaveOccurred())
@@ -910,7 +909,7 @@ func TestRunRestackNoNodeName(t *testing.T) {
 	ctx := context.TODO()
 
 	// This execution gets past the different launch config check, but since there is no node name, it is skipped
-	nodesProcessed, err := rcRollingUpgrade.runRestack(&ctx, ruObj, mockEC2Instance, KubeCtlBinary)
+	nodesProcessed, err := rcRollingUpgrade.runRestack(&ctx, ruObj, mockAutoscalingGroup, KubeCtlBinary)
 	g.Expect(nodesProcessed).To(gomega.Equal(1))
 	g.Expect(err).To(gomega.BeNil())
 }
@@ -938,7 +937,7 @@ func TestRunRestackDrainNodeFail(t *testing.T) {
 			PreDrain: somePreDrain,
 		},
 	}
-	mockEC2Instance := MockEC2Instance{}
+	mockAutoscalingGroup := MockAutoscalingGroup{}
 
 	mgr, err := manager.New(cfg, manager.Options{})
 	g.Expect(err).NotTo(gomega.HaveOccurred())
@@ -964,7 +963,7 @@ func TestRunRestackDrainNodeFail(t *testing.T) {
 	ctx := context.TODO()
 
 	// This execution gets past the different launch config check, but fails to drain the node because of a predrain failing script
-	nodesProcessed, err := rcRollingUpgrade.runRestack(&ctx, ruObj, mockEC2Instance, KubeCtlBinary)
+	nodesProcessed, err := rcRollingUpgrade.runRestack(&ctx, ruObj, mockAutoscalingGroup, KubeCtlBinary)
 	g.Expect(nodesProcessed).To(gomega.Equal(0))
 	g.Expect(err.Error()).To(gomega.HavePrefix(ruObj.Name + ": Predrain script failed"))
 }
@@ -984,7 +983,7 @@ func TestRunRestackTerminateNodeFail(t *testing.T) {
 	ruObj := &upgrademgrv1alpha1.RollingUpgrade{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"},
 		Spec: upgrademgrv1alpha1.RollingUpgradeSpec{AsgName: someAsg}}
 	// Error flag set, should return error
-	mockEC2Instance := MockEC2Instance{errorFlag: true, awsErr: awserr.New("some-other-aws-error",
+	mockAutoscalingGroup := MockAutoscalingGroup{errorFlag: true, awsErr: awserr.New("some-other-aws-error",
 		"some message",
 		errors.New("some error"))}
 
@@ -1012,7 +1011,7 @@ func TestRunRestackTerminateNodeFail(t *testing.T) {
 	ctx := context.TODO()
 
 	// This execution gets past the different launch config check, but fails to terminate node
-	nodesProcessed, err := rcRollingUpgrade.runRestack(&ctx, ruObj, mockEC2Instance, "exit 0;")
+	nodesProcessed, err := rcRollingUpgrade.runRestack(&ctx, ruObj, mockAutoscalingGroup, "exit 0;")
 	g.Expect(nodesProcessed).To(gomega.Equal(0))
 	g.Expect(err.Error()).To(gomega.ContainSubstring("some error"))
 }
@@ -1700,7 +1699,7 @@ func TestRunRestackNoNodeInAsg(t *testing.T) {
 			Strategy: upgrademgrv1alpha1.UpdateStrategy{Type: upgrademgrv1alpha1.RandomUpdateStrategy},
 		},
 	}
-	mockEC2Instance := MockEC2Instance{}
+	mockAutoscalingGroup := MockAutoscalingGroup{}
 
 	mgr, err := manager.New(cfg, manager.Options{})
 	g.Expect(err).NotTo(gomega.HaveOccurred())
@@ -1719,7 +1718,7 @@ func TestRunRestackNoNodeInAsg(t *testing.T) {
 	ctx := context.TODO()
 
 	// This execution gets past the different launch config check, but since there is no node name, it is skipped
-	nodesProcessed, err := rcRollingUpgrade.runRestack(&ctx, ruObj, mockEC2Instance, KubeCtlBinary)
+	nodesProcessed, err := rcRollingUpgrade.runRestack(&ctx, ruObj, mockAutoscalingGroup, KubeCtlBinary)
 	g.Expect(nodesProcessed).To(gomega.Equal(0))
 	g.Expect(err).To(gomega.BeNil())
 }
@@ -1744,7 +1743,7 @@ func TestRunRestackWithNodesLessThanMaxUnavailable(t *testing.T) {
 			},
 		},
 	}
-	mockEC2Instance := MockEC2Instance{}
+	mockAutoscalingGroup := MockAutoscalingGroup{}
 
 	mgr, err := manager.New(cfg, manager.Options{})
 	g.Expect(err).NotTo(gomega.HaveOccurred())
@@ -1762,7 +1761,7 @@ func TestRunRestackWithNodesLessThanMaxUnavailable(t *testing.T) {
 	ctx := context.TODO()
 
 	// This execution should not perform drain or termination, but should pass
-	nodesProcessed, err := rcRollingUpgrade.runRestack(&ctx, ruObj, mockEC2Instance, KubeCtlBinary)
+	nodesProcessed, err := rcRollingUpgrade.runRestack(&ctx, ruObj, mockAutoscalingGroup, KubeCtlBinary)
 	g.Expect(err).To(gomega.BeNil())
 	g.Expect(nodesProcessed).To(gomega.Equal(1))
 }