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

Revisited scale up and scale down. #288

Merged
merged 3 commits into from
Nov 2, 2018
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion pkg/apis/deployment/v1alpha/member_status_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,12 @@ func (l MemberStatusList) SelectMemberToRemove() (MemberStatus, error) {
if len(l) > 0 {
// Try to find a not ready member
for _, m := range l {
if m.Phase == MemberPhaseNone || !m.Conditions.IsTrue(ConditionTypeReady) {
if m.Phase == MemberPhaseNone {
return m, nil
}
}
for _, m := range l {
if !m.Conditions.IsTrue(ConditionTypeReady) {
return m, nil
}
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/deployment/reconcile/action_cleanout_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ func (a *actionCleanoutMember) CheckProgress(ctx context.Context) (bool, bool, e
// We wanted to remove and it is already gone. All ok
return true, false, nil
}
// do not try to clean out a pod that was not initialized
if !m.IsInitialized {
return false, true, nil
}
c, err := a.actionCtx.GetDatabaseClient(ctx)
if err != nil {
log.Debug().Err(err).Msg("Failed to create database client")
Expand Down
4 changes: 4 additions & 0 deletions pkg/deployment/reconcile/action_shutdown_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func (a *actionShutdownMember) Start(ctx context.Context) (bool, error) {
return true, nil
}
if group.IsArangod() {
// do not try to shut down a pod that is not ready
if !m.Conditions.IsTrue(api.ConditionTypeReady) {
return true, nil
}
// Invoke shutdown endpoint
c, err := a.actionCtx.GetServerClient(ctx, group, a.action.MemberID)
if err != nil {
Expand Down
10 changes: 3 additions & 7 deletions pkg/deployment/reconcile/plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,17 +371,13 @@ func createScalePlan(log zerolog.Logger, members api.MemberStatusList, group api
Str("member-id", m.ID).
Str("phase", string(m.Phase)).
Msg("Found member to remove")
if m.Conditions.IsTrue(api.ConditionTypeReady) {
if group == api.ServerGroupDBServers {
plan = append(plan,
api.NewAction(api.ActionTypeCleanOutMember, group, m.ID),
)
}
if group == api.ServerGroupDBServers {
plan = append(plan,
api.NewAction(api.ActionTypeShutdownMember, group, m.ID),
api.NewAction(api.ActionTypeCleanOutMember, group, m.ID),
)
}
plan = append(plan,
api.NewAction(api.ActionTypeShutdownMember, group, m.ID),
api.NewAction(api.ActionTypeRemoveMember, group, m.ID),
)
log.Debug().
Expand Down
27 changes: 12 additions & 15 deletions pkg/deployment/reconcile/plan_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@ func TestCreatePlanActiveFailoverScale(t *testing.T) {
}
newPlan, changed = createPlan(log, depl, nil, spec, status, nil, c)
assert.True(t, changed)
require.Len(t, newPlan, 1) // Note: Downscaling is only down 1 at a time
assert.Equal(t, api.ActionTypeRemoveMember, newPlan[0].Type)
require.Len(t, newPlan, 2) // Note: Downscaling is only down 1 at a time
assert.Equal(t, api.ActionTypeShutdownMember, newPlan[0].Type)
assert.Equal(t, api.ActionTypeRemoveMember, newPlan[1].Type)
assert.Equal(t, api.ServerGroupSingle, newPlan[0].Group)
assert.Equal(t, api.ServerGroupSingle, newPlan[1].Group)
}

// TestCreatePlanClusterScale creates a `cluster` deployment to test the creating of scaling plan.
Expand Down Expand Up @@ -261,12 +263,6 @@ func TestCreatePlanClusterScale(t *testing.T) {
api.MemberStatus{
ID: "cr1",
PodName: "coordinator1",
Conditions: api.ConditionList{
api.Condition{
Type: api.ConditionTypeReady,
Status: v1.ConditionTrue,
},
},
},
api.MemberStatus{
ID: "cr2",
Expand All @@ -277,14 +273,15 @@ func TestCreatePlanClusterScale(t *testing.T) {
spec.Coordinators.Count = util.NewInt(1)
newPlan, changed = createPlan(log, depl, nil, spec, status, nil, c)
assert.True(t, changed)

fmt.Printf("%v", newPlan)

require.Len(t, newPlan, 3) // Note: Downscaling is done 1 at a time
assert.Equal(t, api.ActionTypeRemoveMember, newPlan[0].Type)
require.Len(t, newPlan, 5) // Note: Downscaling is done 1 at a time
assert.Equal(t, api.ActionTypeCleanOutMember, newPlan[0].Type)
assert.Equal(t, api.ActionTypeShutdownMember, newPlan[1].Type)
assert.Equal(t, api.ActionTypeRemoveMember, newPlan[2].Type)
assert.Equal(t, api.ActionTypeShutdownMember, newPlan[3].Type)
assert.Equal(t, api.ActionTypeRemoveMember, newPlan[4].Type)
assert.Equal(t, api.ServerGroupDBServers, newPlan[0].Group)
assert.Equal(t, api.ServerGroupCoordinators, newPlan[1].Group)
assert.Equal(t, api.ServerGroupCoordinators, newPlan[2].Group)
assert.Equal(t, api.ServerGroupDBServers, newPlan[1].Group)
assert.Equal(t, api.ServerGroupDBServers, newPlan[2].Group)
assert.Equal(t, api.ServerGroupCoordinators, newPlan[3].Group)
assert.Equal(t, api.ServerGroupCoordinators, newPlan[4].Group)
}