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

Commit 2bee026

Browse files
kaufersDavid Chung
authored andcommitted
Check for quorom group instance changes during PlanUpdate (#567)
Signed-off-by: Steven Kaufer <[email protected]>
1 parent 7b7ded8 commit 2bee026

File tree

4 files changed

+344
-6
lines changed

4 files changed

+344
-6
lines changed

pkg/plugin/group/quorum.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ package group
33
import (
44
"errors"
55
"fmt"
6-
log "github.com/Sirupsen/logrus"
7-
"github.com/docker/infrakit/pkg/spi/group"
8-
"github.com/docker/infrakit/pkg/spi/instance"
96
"reflect"
107
"sync"
118
"time"
9+
10+
log "github.com/Sirupsen/logrus"
11+
"github.com/docker/infrakit/pkg/spi/group"
12+
"github.com/docker/infrakit/pkg/spi/instance"
1213
)
1314

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

42+
if settings.config.InstanceHash() == newSettings.config.InstanceHash() {
43+
// This is a no-op update because the instance configuration is unchanged
44+
return &noopUpdate{}, nil
45+
}
46+
4147
return &rollingupdate{
4248
desc: fmt.Sprintf(
4349
"Performing a rolling update on %d instances",

pkg/plugin/group/quorum_test.go

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package group
22

33
import (
4+
"testing"
5+
"time"
6+
47
mock_group "github.com/docker/infrakit/pkg/mock/plugin/group"
8+
mock_instance "github.com/docker/infrakit/pkg/mock/spi/instance"
9+
"github.com/docker/infrakit/pkg/plugin/group/types"
510
"github.com/docker/infrakit/pkg/spi/group"
611
"github.com/docker/infrakit/pkg/spi/instance"
712
"github.com/golang/mock/gomock"
8-
"testing"
9-
"time"
13+
"github.com/stretchr/testify/require"
1014
)
1115

1216
var (
@@ -95,3 +99,96 @@ func TestRemoveUnknown(t *testing.T) {
9599

96100
quorum.Run()
97101
}
102+
103+
func TestQuorumPlanUpdateNoChanges(t *testing.T) {
104+
ctrl := gomock.NewController(t)
105+
defer ctrl.Finish()
106+
107+
groupID := group.ID("quorum")
108+
scaled := mock_group.NewMockScaled(ctrl)
109+
instancePlugin := mock_instance.NewMockPlugin(ctrl)
110+
settings := groupSettings{
111+
instancePlugin: instancePlugin,
112+
config: types.Spec{
113+
Allocation: types.AllocationMethod{
114+
LogicalIDs: []instance.LogicalID{
115+
*a.LogicalID,
116+
},
117+
},
118+
},
119+
}
120+
quorum := NewQuorum(groupID, scaled, logicalIDs, 1*time.Millisecond)
121+
plan, err := quorum.PlanUpdate(scaled, settings, settings)
122+
require.NoError(t, err)
123+
require.IsType(t, &noopUpdate{}, plan)
124+
}
125+
126+
func TestQuorumPlanUpdateLogicalIDChange(t *testing.T) {
127+
ctrl := gomock.NewController(t)
128+
defer ctrl.Finish()
129+
130+
groupID := group.ID("quorum")
131+
scaled := mock_group.NewMockScaled(ctrl)
132+
instancePlugin := mock_instance.NewMockPlugin(ctrl)
133+
settingsOld := groupSettings{
134+
instancePlugin: instancePlugin,
135+
config: types.Spec{
136+
Allocation: types.AllocationMethod{
137+
LogicalIDs: []instance.LogicalID{
138+
*a.LogicalID,
139+
},
140+
},
141+
},
142+
}
143+
settingsNew := groupSettings{
144+
instancePlugin: instancePlugin,
145+
config: types.Spec{
146+
Allocation: types.AllocationMethod{
147+
LogicalIDs: []instance.LogicalID{
148+
*b.LogicalID,
149+
},
150+
},
151+
},
152+
}
153+
quorum := NewQuorum(groupID, scaled, logicalIDs, 1*time.Millisecond)
154+
_, err := quorum.PlanUpdate(scaled, settingsOld, settingsNew)
155+
require.Error(t, err)
156+
}
157+
158+
func TestQuorumPlanUpdateRollingUpdate(t *testing.T) {
159+
ctrl := gomock.NewController(t)
160+
defer ctrl.Finish()
161+
162+
groupID := group.ID("quorum")
163+
scaled := mock_group.NewMockScaled(ctrl)
164+
instancePlugin := mock_instance.NewMockPlugin(ctrl)
165+
instanceOld := types.InstancePlugin{
166+
Plugin: "name-old",
167+
}
168+
instanceNew := types.InstancePlugin{
169+
Plugin: "name-new",
170+
}
171+
allocation := types.AllocationMethod{
172+
LogicalIDs: []instance.LogicalID{
173+
*b.LogicalID,
174+
},
175+
}
176+
settingsOld := groupSettings{
177+
instancePlugin: instancePlugin,
178+
config: types.Spec{
179+
Allocation: allocation,
180+
Instance: instanceOld,
181+
},
182+
}
183+
settingsNew := groupSettings{
184+
instancePlugin: instancePlugin,
185+
config: types.Spec{
186+
Allocation: allocation,
187+
Instance: instanceNew,
188+
},
189+
}
190+
quorum := NewQuorum(groupID, scaled, logicalIDs, 1*time.Millisecond)
191+
plan, err := quorum.PlanUpdate(scaled, settingsOld, settingsNew)
192+
require.NoError(t, err)
193+
require.IsType(t, &rollingupdate{}, plan)
194+
}

pkg/plugin/group/scaler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (s *scaler) PlanUpdate(scaled Scaled, settings groupSettings, newSettings g
8989
newSettings.config.Allocation.Size)
9090
} else {
9191
plan.desc = fmt.Sprintf(
92-
"Terminating %d instances to reduce the group size to %d, "+
92+
"Terminating %d instances to reduce the group size to %d,"+
9393
" then performing a rolling update on %d instances",
9494
int(sizeChange)*-1,
9595
newSettings.config.Allocation.Size,

0 commit comments

Comments
 (0)