Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rolling update instance groups in consistent order #9412

Merged
merged 1 commit into from
Jun 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions pkg/instancegroups/rollingupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package instancegroups
import (
"context"
"fmt"
"sort"
"sync"
"time"

Expand Down Expand Up @@ -128,21 +129,21 @@ func (c *RollingUpdateCluster) RollingUpdate(ctx context.Context, groups map[str
{
var wg sync.WaitGroup

for k, bastionGroup := range bastionGroups {
for _, k := range sortGroups(bastionGroups) {
wg.Add(1)
go func(k string, group *cloudinstances.CloudInstanceGroup) {
go func(k string) {
resultsMutex.Lock()
results[k] = fmt.Errorf("function panic bastions")
resultsMutex.Unlock()

defer wg.Done()

err := c.rollingUpdateInstanceGroup(ctx, cluster, group, true, c.BastionInterval)
err := c.rollingUpdateInstanceGroup(ctx, cluster, bastionGroups[k], true, c.BastionInterval)

resultsMutex.Lock()
results[k] = err
resultsMutex.Unlock()
}(k, bastionGroup)
}(k)
}

wg.Wait()
Expand All @@ -161,8 +162,8 @@ func (c *RollingUpdateCluster) RollingUpdate(ctx context.Context, groups map[str
// typically they will be in separate instance groups, so we can force the zones,
// and we don't want to roll all the masters at the same time. See issue #284

for _, group := range masterGroups {
err := c.rollingUpdateInstanceGroup(ctx, cluster, group, false, c.MasterInterval)
for _, k := range sortGroups(masterGroups) {
err := c.rollingUpdateInstanceGroup(ctx, cluster, masterGroups[k], false, c.MasterInterval)

// Do not continue update if master(s) failed, cluster is potentially in an unhealthy state
if err != nil {
Expand All @@ -183,8 +184,8 @@ func (c *RollingUpdateCluster) RollingUpdate(ctx context.Context, groups map[str
results[k] = fmt.Errorf("function panic nodes")
}

for k, group := range nodeGroups {
err := c.rollingUpdateInstanceGroup(ctx, cluster, group, false, c.NodeInterval)
for _, k := range sortGroups(nodeGroups) {
err := c.rollingUpdateInstanceGroup(ctx, cluster, nodeGroups[k], false, c.NodeInterval)

results[k] = err

Expand All @@ -201,3 +202,12 @@ func (c *RollingUpdateCluster) RollingUpdate(ctx context.Context, groups map[str
klog.Infof("Rolling update completed for cluster %q!", c.ClusterName)
return nil
}

func sortGroups(groupMap map[string]*cloudinstances.CloudInstanceGroup) []string {
groups := make([]string, 0, len(groupMap))
for group := range groupMap {
groups = append(groups, group)
}
sort.Strings(groups)
return groups
}