Skip to content

Commit

Permalink
Min dbserver count is 2. Revert phase when cleanout has failed
Browse files Browse the repository at this point in the history
  • Loading branch information
ewoutp committed Jun 15, 2018
1 parent d9db5e9 commit 589fe67
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
11 changes: 11 additions & 0 deletions pkg/apis/deployment/v1alpha/server_group_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (s ServerGroupSpec) Validate(group ServerGroup, used bool, mode DeploymentM
if used {
minCount := 1
if env == EnvironmentProduction {
// Set validation boundaries for production mode
switch group {
case ServerGroupSingle:
if mode == DeploymentModeActiveFailover {
Expand All @@ -87,6 +88,16 @@ func (s ServerGroupSpec) Validate(group ServerGroup, used bool, mode DeploymentM
case ServerGroupDBServers, ServerGroupCoordinators, ServerGroupSyncMasters, ServerGroupSyncWorkers:
minCount = 2
}
} else {
// Set validation boundaries for development mode
switch group {
case ServerGroupSingle:
if mode == DeploymentModeActiveFailover {
minCount = 2
}
case ServerGroupDBServers:
minCount = 2
}
}
if s.GetCount() < minCount {
return maskAny(errors.Wrapf(ValidationError, "Invalid count value %d. Expected >= %d", s.GetCount(), minCount))
Expand Down
22 changes: 16 additions & 6 deletions pkg/deployment/cluster_scaling_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha"
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/arangod"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
)

// clusterScalingIntegration is a helper to communicate with the clusters
Expand Down Expand Up @@ -150,15 +151,24 @@ func (ci *clusterScalingIntegration) inspectCluster(ctx context.Context, expectS
log.Debug().Err(err).Msg("Failed to get current deployment")
return maskAny(err)
}
newSpec := current.Spec.DeepCopy()
if coordinatorsChanged {
current.Spec.Coordinators.Count = util.NewInt(req.GetCoordinators())
newSpec.Coordinators.Count = util.NewInt(req.GetCoordinators())
}
if dbserversChanged {
current.Spec.DBServers.Count = util.NewInt(req.GetDBServers())
}
if err := ci.depl.updateCRSpec(current.Spec); err != nil {
log.Warn().Err(err).Msg("Failed to update current deployment")
return maskAny(err)
newSpec.DBServers.Count = util.NewInt(req.GetDBServers())
}
if err := newSpec.Validate(); err != nil {
// Log failure & create event
log.Warn().Err(err).Msg("Validation of updated spec has failed")
ci.depl.CreateEvent(k8sutil.NewErrorEvent("Validation failed", err, apiObject))
// Restore original spec in cluster
ci.SendUpdateToCluster(current.Spec)
} else {
if err := ci.depl.updateCRSpec(*newSpec); err != nil {
log.Warn().Err(err).Msg("Failed to update current deployment")
return maskAny(err)
}
}
return nil
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/deployment/reconcile/action_cleanout_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ func (a *actionCleanoutMember) CheckProgress(ctx context.Context) (bool, bool, e
}
if jobStatus.IsFailed() {
log.Warn().Str("reason", jobStatus.Reason()).Msg("Cleanout Job failed. Aborting plan")
// Revert cleanout state
m.Phase = api.MemberPhaseCreated
m.CleanoutJobID = ""
if a.actionCtx.UpdateMember(m); err != nil {
return false, false, maskAny(err)
}
return false, true, nil
}
return false, false, nil
Expand Down
4 changes: 3 additions & 1 deletion pkg/deployment/reconcile/plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,9 @@ func createScalePlan(log zerolog.Logger, members api.MemberStatusList, group api
Msg("Creating scale-up plan")
} else if len(members) > count {
// Note, we scale down 1 member at a time
if m, err := members.SelectMemberToRemove(); err == nil {
if m, err := members.SelectMemberToRemove(); err != nil {
log.Warn().Err(err).Str("role", group.AsRole()).Msg("Failed to select member to remove")
} else {
if group == api.ServerGroupDBServers {
plan = append(plan,
api.NewAction(api.ActionTypeCleanOutMember, group, m.ID),
Expand Down

0 comments on commit 589fe67

Please sign in to comment.