Skip to content
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: 7 additions & 0 deletions pkg/apis/deployment/v1/server_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ var (
ServerGroupSyncMasters,
ServerGroupSyncWorkers,
}
// AllArangoDServerGroups contains a constant list of all ArangoD server groups
AllArangoDServerGroups = []ServerGroup{
ServerGroupAgents,
ServerGroupSingle,
ServerGroupDBServers,
ServerGroupCoordinators,
}
)

// AsRole returns the "role" value for the given group.
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/deployment/v2alpha1/server_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ var (
ServerGroupSyncMasters,
ServerGroupSyncWorkers,
}
// AllArangoDServerGroups contains a constant list of all ArangoD server groups
AllArangoDServerGroups = []ServerGroup{
ServerGroupAgents,
ServerGroupSingle,
ServerGroupDBServers,
ServerGroupCoordinators,
}
)

// AsRole returns the "role" value for the given group.
Expand Down
2 changes: 1 addition & 1 deletion pkg/deployment/access_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"strings"
"time"

"gopkg.in/yaml.v3"
"gopkg.in/yaml.v2"
core "k8s.io/api/core/v1"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand Down
25 changes: 19 additions & 6 deletions pkg/deployment/agency/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ import (
"context"
"sync"

"github.com/rs/zerolog"

"github.com/arangodb/go-driver"
"github.com/arangodb/go-driver/agency"

api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
"github.com/arangodb/kube-arangodb/pkg/generated/metric_descriptions"
"github.com/arangodb/kube-arangodb/pkg/logging"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/globals"
"github.com/arangodb/kube-arangodb/pkg/util/metrics"
Expand Down Expand Up @@ -164,10 +167,14 @@ func NewCache(namespace, name string, mode *api.DeploymentMode) Cache {
}

func NewAgencyCache(namespace, name string) Cache {
return &cache{
c := &cache{
namespace: namespace,
name: name,
}

c.log = logger.WrapObj(c)

return c
}

func NewSingleCache() Cache {
Expand Down Expand Up @@ -197,6 +204,8 @@ func (c cacheSingle) Data() (State, bool) {
type cache struct {
namespace, name string

log logging.Logger

lock sync.RWMutex

valid bool
Expand All @@ -208,6 +217,10 @@ type cache struct {
health Health
}

func (c *cache) WrapLogger(in *zerolog.Event) *zerolog.Event {
return in.Str("namespace", c.namespace).Str("name", c.name)
}

func (c *cache) CommitIndex() uint64 {
c.lock.RLock()
defer c.lock.RUnlock()
Expand Down Expand Up @@ -238,7 +251,7 @@ func (c *cache) Reload(ctx context.Context, size int, clients map[string]agency.
c.lock.Lock()
defer c.lock.Unlock()

leaderCli, leaderConfig, health, err := getLeader(ctx, size, clients)
leaderCli, leaderConfig, health, err := c.getLeader(ctx, size, clients)
if err != nil {
// Invalidate a leader ID and agency state.
// In the next iteration leaderID will be sat because `valid` will be false.
Expand All @@ -258,7 +271,7 @@ func (c *cache) Reload(ctx context.Context, size int, clients map[string]agency.
}

// A leader should be known even if an agency state is invalid.
if data, err := loadState(ctx, leaderCli); err != nil {
if data, err := c.loadState(ctx, leaderCli); err != nil {
c.valid = false
return leaderConfig.CommitIndex, err
} else {
Expand All @@ -271,7 +284,7 @@ func (c *cache) Reload(ctx context.Context, size int, clients map[string]agency.

// getLeader returns config and client to a leader agency, and health to check if agencies are on the same page.
// If there is no quorum for the leader then error is returned.
func getLeader(ctx context.Context, size int, clients map[string]agency.Agency) (agency.Agency, *Config, health, error) {
func (c *cache) getLeader(ctx context.Context, size int, clients map[string]agency.Agency) (agency.Agency, *Config, health, error) {
configs := make([]*Config, len(clients))
errs := make([]error, len(clients))
names := make([]string, 0, len(clients))
Expand Down Expand Up @@ -324,11 +337,11 @@ func getLeader(ctx context.Context, size int, clients map[string]agency.Agency)
}
}
if err := h.Serving(); err != nil {
logger.Err(err).Warn("Agency Not serving")
c.log.Err(err).Warn("Agency Not serving")
return nil, nil, h, err
}
if err := h.Healthy(); err != nil {
logger.Err(err).Warn("Agency Not healthy")
c.log.Err(err).Debug("Agency Not healthy")
}

for id := range names {
Expand Down
18 changes: 5 additions & 13 deletions pkg/deployment/agency/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/util/errors"
)

func loadState(ctx context.Context, client agency.Agency) (State, error) {
func (c *cache) loadState(ctx context.Context, client agency.Agency) (State, error) {
conn := client.Connection()

req, err := client.Connection().NewRequest(http.MethodPost, "/_api/agency/read")
Expand Down Expand Up @@ -67,25 +67,17 @@ func loadState(ctx context.Context, client agency.Agency) (State, error) {
return State{}, err
}

var c StateRoots
var r StateRoots

if err := json.Unmarshal(data, &c); err != nil {
if err := json.Unmarshal(data, &r); err != nil {
return State{}, err
}

if len(c) != 1 {
if len(r) != 1 {
return State{}, errors.Newf("Invalid response size")
}

state := c[0].Arango

if _, ok := state.Current.Collections["_system"]; !ok {
return State{}, errors.Newf("Unable to find system database (invalid data)")
}

if _, ok := state.Plan.Collections["_system"]; !ok {
return State{}, errors.Newf("Unable to find system database (invalid data)")
}
state := r[0].Arango

return state, nil
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/deployment/reconcile/action_backup_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package reconcile

import (
"context"
"time"

"github.com/arangodb/go-driver"

Expand Down Expand Up @@ -203,6 +204,16 @@ func (a actionBackupRestore) CheckProgress(ctx context.Context) (bool, bool, err
// Retry
return false, false, nil
}

// Add wait grace period for restore jobs - async job creation is asynchronous
if ok := conn.IsAsyncErrorNotFound(restoreError); ok {
if s := a.action.StartTime; s != nil && !s.Time.IsZero() {
if time.Since(s.Time) < 10*time.Second {
// Retry
return false, false, nil
}
}
}
}

// Restore is done
Expand All @@ -214,6 +225,7 @@ func (a actionBackupRestore) CheckProgress(ctx context.Context) (bool, bool, err
}

if restoreError != nil {
a.log.Err(restoreError).Error("Restore failed")
result.State = api.DeploymentRestoreStateRestoreFailed
result.Message = restoreError.Error()
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/deployment/reconcile/plan_builder_tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func (r *Reconciler) createKeyfileRenewalPlanSynced(ctx context.Context, apiObje
member := statusMember.Member

if !plan.IsEmpty() {
return nil
continue
}

cache, ok := planCtx.ACS().ClusterCache(member.ClusterID)
Expand Down