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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Define MemberReplacementRequired condition
- Remove pod immediately when annotation is turned on
- (ARM64) Add support for ARM64 enablement
- (Cleanup) Reorganize main reconciliation context

## [1.2.7](https://github.com/arangodb/kube-arangodb/tree/1.2.7) (2022-01-17)
- Add Plan BackOff functionality
Expand Down
7 changes: 3 additions & 4 deletions pkg/deployment/client/client_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import (
"strconv"
"sync"

"github.com/arangodb/kube-arangodb/pkg/deployment/resources"

"github.com/arangodb/kube-arangodb/pkg/util/errors"

"github.com/arangodb/go-driver/agency"
Expand All @@ -36,6 +34,7 @@ import (

driver "github.com/arangodb/go-driver"
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
"github.com/arangodb/kube-arangodb/pkg/deployment/reconciler"
)

type Cache interface {
Expand All @@ -49,8 +48,8 @@ type Cache interface {
}

type CacheGen interface {
resources.DeploymentEndpoints
resources.DeploymentInfoGetter
reconciler.DeploymentEndpoints
reconciler.DeploymentInfoGetter
}

func NewClientCache(in CacheGen, factory conn.Factory) Cache {
Expand Down
18 changes: 12 additions & 6 deletions pkg/deployment/context_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import (

backupApi "github.com/arangodb/kube-arangodb/pkg/apis/backup/v1"
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
"github.com/arangodb/kube-arangodb/pkg/deployment/reconciler"
"github.com/arangodb/kube-arangodb/pkg/deployment/resources"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
core "k8s.io/api/core/v1"
Expand All @@ -97,7 +98,7 @@ func (d *Deployment) GetAPIObject() k8sutil.APIObject {
}

// GetServerGroupIterator returns the deployment as ServerGroupIterator.
func (d *Deployment) GetServerGroupIterator() resources.ServerGroupIterator {
func (d *Deployment) GetServerGroupIterator() reconciler.ServerGroupIterator {
return d.apiObject
}

Expand Down Expand Up @@ -226,8 +227,13 @@ func (d *Deployment) GetAuthentication() conn.Auth {
}

// GetAgencyClients returns a client connection for every agency member.
func (d *Deployment) GetAgencyClients(ctx context.Context) ([]driver.Connection, error) {
return d.GetAgencyClientsWithPredicate(ctx, nil)
}

// GetAgencyClientsWithPredicate returns a client connection for every agency member.
// If the given predicate is not nil, only agents are included where the given predicate returns true.
func (d *Deployment) GetAgencyClients(ctx context.Context, predicate func(id string) bool) ([]driver.Connection, error) {
func (d *Deployment) GetAgencyClientsWithPredicate(ctx context.Context, predicate func(id string) bool) ([]driver.Connection, error) {
agencyMembers := d.status.last.Members.Agents
result := make([]driver.Connection, 0, len(agencyMembers))
for _, m := range agencyMembers {
Expand Down Expand Up @@ -591,7 +597,7 @@ func (d *Deployment) GetArangoImage() string {
return d.config.ArangoImage
}

func (d *Deployment) WithStatusUpdateErr(ctx context.Context, action resources.DeploymentStatusUpdateErrFunc, force ...bool) error {
func (d *Deployment) WithStatusUpdateErr(ctx context.Context, action reconciler.DeploymentStatusUpdateErrFunc, force ...bool) error {
d.status.mutex.Lock()
defer d.status.mutex.Unlock()

Expand All @@ -610,7 +616,7 @@ func (d *Deployment) WithStatusUpdateErr(ctx context.Context, action resources.D
return d.updateStatus(ctx, status, version, force...)
}

func (d *Deployment) WithStatusUpdate(ctx context.Context, action resources.DeploymentStatusUpdateFunc, force ...bool) error {
func (d *Deployment) WithStatusUpdate(ctx context.Context, action reconciler.DeploymentStatusUpdateFunc, force ...bool) error {
return d.WithStatusUpdateErr(ctx, func(s *api.DeploymentStatus) (bool, error) {
return action(s), nil
}, force...)
Expand Down Expand Up @@ -680,7 +686,7 @@ func (d *Deployment) SetCachedStatus(i inspectorInterface.Inspector) {
d.currentState = i
}

func (d *Deployment) WithArangoMemberUpdate(ctx context.Context, namespace, name string, action resources.ArangoMemberUpdateFunc) error {
func (d *Deployment) WithArangoMemberUpdate(ctx context.Context, namespace, name string, action reconciler.ArangoMemberUpdateFunc) error {
o, err := d.deps.DatabaseCRCli.DatabaseV1().ArangoMembers(namespace).Get(ctx, name, meta.GetOptions{})
if err != nil {
return err
Expand All @@ -695,7 +701,7 @@ func (d *Deployment) WithArangoMemberUpdate(ctx context.Context, namespace, name
return nil
}

func (d *Deployment) WithArangoMemberStatusUpdate(ctx context.Context, namespace, name string, action resources.ArangoMemberStatusUpdateFunc) error {
func (d *Deployment) WithArangoMemberStatusUpdate(ctx context.Context, namespace, name string, action reconciler.ArangoMemberStatusUpdateFunc) error {
o, err := d.deps.DatabaseCRCli.DatabaseV1().ArangoMembers(namespace).Get(ctx, name, meta.GetOptions{})
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (d *Deployment) RefreshAgencyCache(ctx context.Context) (uint64, error) {
}

func (d *Deployment) SetAgencyMaintenanceMode(ctx context.Context, enabled bool) error {
if !d.Mode().HasAgents() {
if !d.GetMode().HasAgents() {
return nil
}

Expand Down
66 changes: 32 additions & 34 deletions pkg/deployment/reconcile/action_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ import (
meta "k8s.io/apimachinery/pkg/apis/meta/v1"

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

"github.com/arangodb/go-driver"
backupApi "github.com/arangodb/kube-arangodb/pkg/apis/backup/v1"
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
agencyCache "github.com/arangodb/kube-arangodb/pkg/deployment/agency"
"github.com/arangodb/kube-arangodb/pkg/deployment/resources"
"github.com/arangodb/kube-arangodb/pkg/deployment/reconciler"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector"
Expand All @@ -52,31 +52,17 @@ import (
// ActionContext provides methods to the Action implementations
// to control their context.
type ActionContext interface {
resources.DeploymentStatusUpdate
resources.DeploymentAgencyMaintenance
resources.ArangoMemberContext
resources.DeploymentPodRenderer
resources.DeploymentModInterfaces
resources.DeploymentCachedStatus
resources.ArangoAgencyGet
resources.DeploymentInfoGetter

// Gets the specified mode of deployment
GetMode() api.DeploymentMode
// GetDatabaseClient returns a cached client for the entire database (cluster coordinators or single server),
// creating one if needed.
GetDatabaseClient(ctx context.Context) (driver.Client, error)
// GetServerClient returns a cached client for a specific server.
GetServerClient(ctx context.Context, group api.ServerGroup, id string) (driver.Client, error)
// GetAgencyClients returns a client connection for every agency member.
GetAgencyClients(ctx context.Context) ([]driver.Connection, error)
// GetAgency returns a connection to the entire agency.
GetAgency(ctx context.Context) (agency.Agency, error)
// GetSyncServerClient returns a cached client for a specific arangosync server.
GetSyncServerClient(ctx context.Context, group api.ServerGroup, id string) (client.API, error)
// CreateEvent creates a given event.
// On error, the error is logged.
CreateEvent(evt *k8sutil.Event)
reconciler.DeploymentStatusUpdate
reconciler.DeploymentAgencyMaintenance
reconciler.ArangoMemberContext
reconciler.DeploymentPodRenderer
reconciler.DeploymentModInterfaces
reconciler.DeploymentCachedStatus
reconciler.ArangoAgencyGet
reconciler.DeploymentInfoGetter
reconciler.DeploymentClient
reconciler.DeploymentSyncClient

// GetMemberStatusByID returns the current member status
// for the member with given id.
// Returns member status, true when found, or false
Expand Down Expand Up @@ -119,7 +105,7 @@ type ActionContext interface {
// GetImageInfo returns the image info for an image with given name.
// Returns: (info, infoFound)
GetImageInfo(imageName string) (api.ImageInfo, bool)
// GetImageInfo returns the image info for an current image.
// GetCurrentImageInfo returns the image info for an current image.
// Returns: (info, infoFound)
GetCurrentImageInfo() (api.ImageInfo, bool)
// SetCurrentImage changes the CurrentImage field in the deployment
Expand All @@ -135,7 +121,7 @@ type ActionContext interface {
DisableScalingCluster(ctx context.Context) error
// EnableScalingCluster enables scaling DBservers and coordinators
EnableScalingCluster(ctx context.Context) error
// WithStatusUpdate update status of ArangoDeployment with defined modifier. If action returns True action is taken
// UpdateClusterCondition update status of ArangoDeployment with defined modifier. If action returns True action is taken
UpdateClusterCondition(ctx context.Context, conditionType api.ConditionType, status bool, reason, message string) error
// GetBackup receives information about a backup resource
GetBackup(ctx context.Context, backup string) (*backupApi.ArangoBackup, error)
Expand All @@ -161,6 +147,18 @@ type actionContext struct {
cachedStatus inspectorInterface.Inspector
}

func (ac *actionContext) UpdateStatus(ctx context.Context, status api.DeploymentStatus, lastVersion int32, force ...bool) error {
return ac.context.UpdateStatus(ctx, status, lastVersion, force...)
}

func (ac *actionContext) GetNamespace() string {
return ac.context.GetNamespace()
}

func (ac *actionContext) GetAgencyClientsWithPredicate(ctx context.Context, predicate func(id string) bool) ([]driver.Connection, error) {
return ac.context.GetAgencyClientsWithPredicate(ctx, predicate)
}

func (ac *actionContext) GetStatus() (api.DeploymentStatus, int32) {
return ac.context.GetStatus()
}
Expand Down Expand Up @@ -189,11 +187,11 @@ func (ac *actionContext) SetAgencyMaintenanceMode(ctx context.Context, enabled b
return ac.context.SetAgencyMaintenanceMode(ctx, enabled)
}

func (ac *actionContext) WithArangoMemberUpdate(ctx context.Context, namespace, name string, action resources.ArangoMemberUpdateFunc) error {
func (ac *actionContext) WithArangoMemberUpdate(ctx context.Context, namespace, name string, action reconciler.ArangoMemberUpdateFunc) error {
return ac.context.WithArangoMemberUpdate(ctx, namespace, name, action)
}

func (ac *actionContext) WithArangoMemberStatusUpdate(ctx context.Context, namespace, name string, action resources.ArangoMemberStatusUpdateFunc) error {
func (ac *actionContext) WithArangoMemberStatusUpdate(ctx context.Context, namespace, name string, action reconciler.ArangoMemberStatusUpdateFunc) error {
return ac.context.WithArangoMemberStatusUpdate(ctx, namespace, name, action)
}

Expand Down Expand Up @@ -221,11 +219,11 @@ func (ac *actionContext) GetBackup(ctx context.Context, backup string) (*backupA
return ac.context.GetBackup(ctx, backup)
}

func (ac *actionContext) WithStatusUpdateErr(ctx context.Context, action resources.DeploymentStatusUpdateErrFunc, force ...bool) error {
func (ac *actionContext) WithStatusUpdateErr(ctx context.Context, action reconciler.DeploymentStatusUpdateErrFunc, force ...bool) error {
return ac.context.WithStatusUpdateErr(ctx, action, force...)
}

func (ac *actionContext) WithStatusUpdate(ctx context.Context, action resources.DeploymentStatusUpdateFunc, force ...bool) error {
func (ac *actionContext) WithStatusUpdate(ctx context.Context, action reconciler.DeploymentStatusUpdateFunc, force ...bool) error {
return ac.context.WithStatusUpdate(ctx, action, force...)
}

Expand Down Expand Up @@ -322,7 +320,7 @@ func (ac *actionContext) GetServerClient(ctx context.Context, group api.ServerGr

// GetAgencyClients returns a client connection for every agency member.
func (ac *actionContext) GetAgencyClients(ctx context.Context) ([]driver.Connection, error) {
c, err := ac.context.GetAgencyClients(ctx, nil)
c, err := ac.context.GetAgencyClients(ctx)
if err != nil {
return nil, errors.WithStack(err)
}
Expand Down
52 changes: 15 additions & 37 deletions pkg/deployment/reconcile/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,54 +23,34 @@ package reconcile
import (
"context"

"github.com/arangodb/arangosync-client/client"
"github.com/arangodb/go-driver"
"github.com/arangodb/go-driver/agency"
v1 "k8s.io/api/core/v1"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/arangodb/go-driver"
backupApi "github.com/arangodb/kube-arangodb/pkg/apis/backup/v1"
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
"github.com/arangodb/kube-arangodb/pkg/deployment/resources"
"github.com/arangodb/kube-arangodb/pkg/deployment/reconciler"
"github.com/arangodb/kube-arangodb/pkg/util/arangod/conn"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
)

type CreateMemberMod func(s *api.DeploymentStatus, g api.ServerGroup, m *api.MemberStatus) error

// Context provides methods to the reconcile package.
type Context interface {
resources.DeploymentStatusUpdate
resources.DeploymentAgencyMaintenance
resources.ArangoMemberContext
resources.DeploymentPodRenderer
resources.DeploymentImageManager
resources.DeploymentModInterfaces
resources.DeploymentCachedStatus
resources.ArangoAgencyGet
resources.ArangoApplier
resources.DeploymentInfoGetter
reconciler.DeploymentStatusUpdate
reconciler.DeploymentAgencyMaintenance
reconciler.ArangoMemberContext
reconciler.DeploymentPodRenderer
reconciler.DeploymentImageManager
reconciler.DeploymentModInterfaces
reconciler.DeploymentCachedStatus
reconciler.ArangoAgencyGet
reconciler.ArangoApplier
reconciler.DeploymentInfoGetter
reconciler.DeploymentClient
reconciler.KubernetesEventGenerator
reconciler.DeploymentSyncClient

// UpdateStatus replaces the status of the deployment with the given status and
// updates the resources in k8s.
UpdateStatus(ctx context.Context, status api.DeploymentStatus, lastVersion int32, force ...bool) error
// UpdateMember updates the deployment status wrt the given member.
UpdateMember(ctx context.Context, member api.MemberStatus) error
// GetDatabaseClient returns a cached client for the entire database (cluster coordinators or single server),
// creating one if needed.
GetDatabaseClient(ctx context.Context) (driver.Client, error)
// GetServerClient returns a cached client for a specific server.
GetServerClient(ctx context.Context, group api.ServerGroup, id string) (driver.Client, error)
// GetAgencyClients returns a client connection for every agency member.
// If the given predicate is not nil, only agents are included where the given predicate returns true.
GetAgencyClients(ctx context.Context, predicate func(id string) bool) ([]driver.Connection, error)
// GetAgency returns a connection to the entire agency.
GetAgency(ctx context.Context) (agency.Agency, error)
// GetSyncServerClient returns a cached client for a specific arangosync server.
GetSyncServerClient(ctx context.Context, group api.ServerGroup, id string) (client.API, error)
// CreateEvent creates a given event.
// On error, the error is logged.
CreateEvent(evt *k8sutil.Event)
// CreateMember adds a new member to the given group.
// If ID is non-empty, it will be used, otherwise a new ID is created.
// Returns ID, error
Expand Down Expand Up @@ -112,8 +92,6 @@ type Context interface {
EnableScalingCluster(ctx context.Context) error
// GetBackup receives information about a backup resource
GetBackup(ctx context.Context, backup string) (*backupApi.ArangoBackup, error)
// GetName receives deployment name
GetName() string
// GetAuthentication return authentication for members
GetAuthentication() conn.Auth
}
40 changes: 11 additions & 29 deletions pkg/deployment/reconcile/plan_builder_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,59 +23,41 @@ package reconcile
import (
"context"

"github.com/arangodb/kube-arangodb/pkg/deployment/resources"

"github.com/arangodb/go-driver/agency"
"github.com/arangodb/kube-arangodb/pkg/util/arangod/conn"

backupApi "github.com/arangodb/kube-arangodb/pkg/apis/backup/v1"

"github.com/arangodb/go-driver"

api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
"github.com/arangodb/kube-arangodb/pkg/deployment/reconciler"
core "k8s.io/api/core/v1"
)

// PlanBuilderContext contains context methods provided to plan builders.
type PlanBuilderContext interface {
resources.DeploymentAgencyMaintenance
resources.ArangoMemberContext
resources.DeploymentPodRenderer
resources.DeploymentImageManager
resources.DeploymentModInterfaces
resources.DeploymentCachedStatus
resources.ArangoAgencyGet
reconciler.DeploymentInfoGetter
reconciler.DeploymentAgencyMaintenance
reconciler.ArangoMemberContext
reconciler.DeploymentPodRenderer
reconciler.DeploymentImageManager
reconciler.DeploymentModInterfaces
reconciler.DeploymentCachedStatus
reconciler.ArangoAgencyGet
reconciler.DeploymentClient
reconciler.KubernetesEventGenerator

// GetTLSKeyfile returns the keyfile encoded TLS certificate+key for
// the given member.
GetTLSKeyfile(group api.ServerGroup, member api.MemberStatus) (string, error)
// CreateEvent creates a given event.
// On error, the error is logged.
CreateEvent(evt *k8sutil.Event)
// GetPvc gets a PVC by the given name, in the samespace of the deployment.
GetPvc(ctx context.Context, pvcName string) (*core.PersistentVolumeClaim, error)
// GetShardSyncStatus returns true if all shards are in sync
GetShardSyncStatus() bool
// InvalidateSyncStatus resets the sync state to false and triggers an inspection
InvalidateSyncStatus()
// GetStatus returns the current status of the deployment
GetStatus() (api.DeploymentStatus, int32)
// GetStatus returns the current spec of the deployment
GetSpec() api.DeploymentSpec
// GetDatabaseClient returns a cached client for the entire database (cluster coordinators or single server),
// creating one if needed.
GetDatabaseClient(ctx context.Context) (driver.Client, error)
// GetServerClient returns a cached client for a specific server.
GetServerClient(ctx context.Context, group api.ServerGroup, id string) (driver.Client, error)
// GetAuthentication return authentication for members
GetAuthentication() conn.Auth
// GetBackup receives information about a backup resource
GetBackup(ctx context.Context, backup string) (*backupApi.ArangoBackup, error)
// GetName receives deployment name
GetName() string
// GetAgency returns a connection to the entire agency.
GetAgency(ctx context.Context) (agency.Agency, error)
}

// newPlanBuilderContext creates a PlanBuilderContext from the given context
Expand Down
Loading