Skip to content

Commit

Permalink
Merge pull request #12734 from johngmyers/automated-cherry-pick-of-#1…
Browse files Browse the repository at this point in the history
…2698-upstream-release-1.21

Automated cherry pick of #12698: Fix out of bounds error when instance detach fails
  • Loading branch information
k8s-ci-robot authored Nov 14, 2021
2 parents d679ca6 + 2c7a30b commit cbbe326
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/instancegroups/instancegroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,16 @@ func (c *RollingUpdateCluster) rollingUpdateInstanceGroup(group *cloudinstances.
if maxSurge > 0 && !c.CloudOnly {
skippedNodes := 0
for numSurge := 1; numSurge <= maxSurge; numSurge++ {
u := update[len(update)-numSurge+skippedNodes]
u := update[len(update)-numSurge-skippedNodes]
if u.Status != cloudinstances.CloudInstanceStatusDetached {
if err := c.detachInstance(u); err != nil {
// If detaching a node fails, we simply proceed to the next one instead of
// bubbling up the error.
skippedNodes++
numSurge--
if maxSurge > len(update)-skippedNodes {
maxSurge = len(update) - skippedNodes
}
}

// If noneReady, wait until after one node is detached and its replacement validates
Expand Down
29 changes: 29 additions & 0 deletions pkg/instancegroups/rollingupdate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package instancegroups
import (
"context"
"errors"
"fmt"
"strings"
"sync"
"testing"
Expand Down Expand Up @@ -1351,6 +1352,34 @@ func TestRollingUpdateMaxSurgeGreaterThanNeedUpdate(t *testing.T) {
assert.Equal(t, 2, countDetach.Count)
}

type failDetachAutoscaling struct {
autoscalingiface.AutoScalingAPI
}

func (m *failDetachAutoscaling) DetachInstances(input *autoscaling.DetachInstancesInput) (*autoscaling.DetachInstancesOutput, error) {
return nil, fmt.Errorf("testing error")
}

func TestRollingUpdateDetachFails(t *testing.T) {

c, cloud := getTestSetup()

cloud.MockAutoscaling = &failDetachAutoscaling{AutoScalingAPI: cloud.MockAutoscaling}
cloud.MockEC2 = &ec2IgnoreTags{EC2API: cloud.MockEC2}

ten := intstr.FromInt(10)
c.Cluster.Spec.RollingUpdate = &kopsapi.RollingUpdate{
MaxSurge: &ten,
}

groups := make(map[string]*cloudinstances.CloudInstanceGroup)
makeGroup(groups, c.K8sClient, cloud, "node-1", kopsapi.InstanceGroupRoleNode, 3, 2)
err := c.RollingUpdate(groups, &kopsapi.InstanceGroupList{})
assert.NoError(t, err, "rolling update")

assertGroupInstanceCount(t, cloud, "node-1", 1)
}

// Request validate (1) -->
// <-- validated
// Detach instance -->
Expand Down

0 comments on commit cbbe326

Please sign in to comment.