Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Check for quorom group instance changes during PlanUpdate (#567)
Browse files Browse the repository at this point in the history
Signed-off-by: Steven Kaufer <[email protected]>
  • Loading branch information
kaufers authored and David Chung committed May 25, 2017
1 parent 7b7ded8 commit 2bee026
Show file tree
Hide file tree
Showing 4 changed files with 344 additions and 6 deletions.
12 changes: 9 additions & 3 deletions pkg/plugin/group/quorum.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package group
import (
"errors"
"fmt"
log "github.com/Sirupsen/logrus"
"github.com/docker/infrakit/pkg/spi/group"
"github.com/docker/infrakit/pkg/spi/instance"
"reflect"
"sync"
"time"

log "github.com/Sirupsen/logrus"
"github.com/docker/infrakit/pkg/spi/group"
"github.com/docker/infrakit/pkg/spi/instance"
)

// TODO(wfarner): Converge this implementation with scaler.go, they share a lot of behavior.
Expand Down Expand Up @@ -38,6 +39,11 @@ func (q *quorum) PlanUpdate(scaled Scaled, settings groupSettings, newSettings g
return nil, errors.New("Logical ID changes to a quorum is not currently supported")
}

if settings.config.InstanceHash() == newSettings.config.InstanceHash() {
// This is a no-op update because the instance configuration is unchanged
return &noopUpdate{}, nil
}

return &rollingupdate{
desc: fmt.Sprintf(
"Performing a rolling update on %d instances",
Expand Down
101 changes: 99 additions & 2 deletions pkg/plugin/group/quorum_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package group

import (
"testing"
"time"

mock_group "github.com/docker/infrakit/pkg/mock/plugin/group"
mock_instance "github.com/docker/infrakit/pkg/mock/spi/instance"
"github.com/docker/infrakit/pkg/plugin/group/types"
"github.com/docker/infrakit/pkg/spi/group"
"github.com/docker/infrakit/pkg/spi/instance"
"github.com/golang/mock/gomock"
"testing"
"time"
"github.com/stretchr/testify/require"
)

var (
Expand Down Expand Up @@ -95,3 +99,96 @@ func TestRemoveUnknown(t *testing.T) {

quorum.Run()
}

func TestQuorumPlanUpdateNoChanges(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

groupID := group.ID("quorum")
scaled := mock_group.NewMockScaled(ctrl)
instancePlugin := mock_instance.NewMockPlugin(ctrl)
settings := groupSettings{
instancePlugin: instancePlugin,
config: types.Spec{
Allocation: types.AllocationMethod{
LogicalIDs: []instance.LogicalID{
*a.LogicalID,
},
},
},
}
quorum := NewQuorum(groupID, scaled, logicalIDs, 1*time.Millisecond)
plan, err := quorum.PlanUpdate(scaled, settings, settings)
require.NoError(t, err)
require.IsType(t, &noopUpdate{}, plan)
}

func TestQuorumPlanUpdateLogicalIDChange(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

groupID := group.ID("quorum")
scaled := mock_group.NewMockScaled(ctrl)
instancePlugin := mock_instance.NewMockPlugin(ctrl)
settingsOld := groupSettings{
instancePlugin: instancePlugin,
config: types.Spec{
Allocation: types.AllocationMethod{
LogicalIDs: []instance.LogicalID{
*a.LogicalID,
},
},
},
}
settingsNew := groupSettings{
instancePlugin: instancePlugin,
config: types.Spec{
Allocation: types.AllocationMethod{
LogicalIDs: []instance.LogicalID{
*b.LogicalID,
},
},
},
}
quorum := NewQuorum(groupID, scaled, logicalIDs, 1*time.Millisecond)
_, err := quorum.PlanUpdate(scaled, settingsOld, settingsNew)
require.Error(t, err)
}

func TestQuorumPlanUpdateRollingUpdate(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

groupID := group.ID("quorum")
scaled := mock_group.NewMockScaled(ctrl)
instancePlugin := mock_instance.NewMockPlugin(ctrl)
instanceOld := types.InstancePlugin{
Plugin: "name-old",
}
instanceNew := types.InstancePlugin{
Plugin: "name-new",
}
allocation := types.AllocationMethod{
LogicalIDs: []instance.LogicalID{
*b.LogicalID,
},
}
settingsOld := groupSettings{
instancePlugin: instancePlugin,
config: types.Spec{
Allocation: allocation,
Instance: instanceOld,
},
}
settingsNew := groupSettings{
instancePlugin: instancePlugin,
config: types.Spec{
Allocation: allocation,
Instance: instanceNew,
},
}
quorum := NewQuorum(groupID, scaled, logicalIDs, 1*time.Millisecond)
plan, err := quorum.PlanUpdate(scaled, settingsOld, settingsNew)
require.NoError(t, err)
require.IsType(t, &rollingupdate{}, plan)
}
2 changes: 1 addition & 1 deletion pkg/plugin/group/scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (s *scaler) PlanUpdate(scaled Scaled, settings groupSettings, newSettings g
newSettings.config.Allocation.Size)
} else {
plan.desc = fmt.Sprintf(
"Terminating %d instances to reduce the group size to %d, "+
"Terminating %d instances to reduce the group size to %d,"+
" then performing a rolling update on %d instances",
int(sizeChange)*-1,
newSettings.config.Allocation.Size,
Expand Down
Loading

0 comments on commit 2bee026

Please sign in to comment.