Skip to content

Commit 3abfda0

Browse files
authored
Fix terminate error (#8)
* check error message instead of code for instance not found * fix test
1 parent ff6a708 commit 3abfda0

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

controllers/rollingupgrade_controller.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,11 @@ func (r *RollingUpgradeReconciler) TerminateNode(ruObj *upgrademgrv1alpha1.Rolli
230230
result, err := svc.TerminateInstanceInAutoScalingGroup(input)
231231
if err != nil {
232232
if aerr, ok := err.(awserr.Error); ok {
233-
switch aerr.Code() {
234-
case "InvalidInstanceID.NotFound":
233+
if strings.Contains(aerr.Message(), "not found") {
235234
log.Printf("Instance %s not found. Moving on\n", instanceID)
235+
return nil
236+
}
237+
switch aerr.Code() {
236238
case autoscaling.ErrCodeScalingActivityInProgressFault:
237239
log.Println(autoscaling.ErrCodeScalingActivityInProgressFault, aerr.Error())
238240
case autoscaling.ErrCodeResourceContentionFault:
@@ -637,7 +639,7 @@ func (r *RollingUpgradeReconciler) RandomUpdate(ctx *context.Context, ruObj *upg
637639

638640
value, ok := r.ruObjNameToASG.Load(ruObj.Name)
639641
if !ok {
640-
msg := "Failed to find rollup name in map."
642+
msg := "Failed to find rollingUpgrade name in map."
641643
log.Printf(msg)
642644
return 0, errors.New(msg)
643645
}

controllers/rollingupgrade_controller_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ func TestTerminateNodeErrorNotFound(t *testing.T) {
322322
ruObj := &upgrademgrv1alpha1.RollingUpgrade{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"}}
323323
rcRollingUpgrade := &RollingUpgradeReconciler{ClusterState: NewClusterState()}
324324
mockAutoscalingGroup := MockAutoscalingGroup{errorFlag: true, awsErr: awserr.New("InvalidInstanceID.NotFound",
325-
"some message",
325+
"ValidationError: Instance Id not found - No managed instance found for instance ID i-0bba",
326326
nil)}
327327

328328
err := rcRollingUpgrade.TerminateNode(ruObj, mockNode, mockAutoscalingGroup)

0 commit comments

Comments
 (0)