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 @@ -8,6 +8,7 @@
- (Update) Bump K8S API to 1.21.10
- (Feature) (ACS) Add ACS handler
- (Feature) Allow to restart DBServers in cases when WriteConcern will be satisfied
- (Feature) Allow to configure action timeouts

## [1.2.8](https://github.com/arangodb/kube-arangodb/tree/1.2.8) (2022-02-24)
- Do not check License V2 on Community images
Expand Down
18 changes: 14 additions & 4 deletions pkg/apis/deployment/v1/timeouts.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ const (
)

type Timeouts struct {
// AddMember action timeout
AddMember *Timeout `json:"addMember,omitempty"`

// MaintenanceGracePeriod action timeout
MaintenanceGracePeriod *Timeout `json:"maintenanceGracePeriod,omitempty"`

// RuntimeContainerImageUpdate action timeout
RuntimeContainerImageUpdate *Timeout `json:"runtimeContainerImageUpdate,omitempty"`
// Actions
Actions ActionTimeouts `json:"actions,omitempty"`

// deprecated
AddMember *Timeout `json:"-"`

// deprecated
RuntimeContainerImageUpdate *Timeout `json:"-"`
}

func (t *Timeouts) GetMaintenanceGracePeriod() time.Duration {
Expand All @@ -57,6 +61,12 @@ func (t *Timeouts) Get() Timeouts {
return *t
}

type ActionTimeouts map[ActionType]Timeout

func NewTimeout(timeout time.Duration) Timeout {
return Timeout(meta.Duration{Duration: timeout})
}

type Timeout meta.Duration

func (t *Timeout) Get(d time.Duration) time.Duration {
Expand Down
16 changes: 13 additions & 3 deletions pkg/deployment/reconcile/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ import (
"github.com/rs/zerolog"
)

func GetAllActions() []api.ActionType {
z := make([]api.ActionType, 0, len(definedActions))

for k := range definedActions {
z = append(z, k)
}

return z
}

// ActionCore executes a single Plan item.
type ActionCore interface {
// Start performs the start of the action.
Expand All @@ -45,8 +55,6 @@ type ActionCore interface {
type Action interface {
ActionCore

// Timeout returns the amount of time after which this action will timeout.
Timeout(deploymentSpec api.DeploymentSpec) time.Duration
// MemberID Return the MemberID used / created in this action
MemberID() string
}
Expand Down Expand Up @@ -144,9 +152,10 @@ type actionFactory func(log zerolog.Logger, action api.Action, actionCtx ActionC
var (
definedActions = map[api.ActionType]actionFactory{}
definedActionsLock sync.Mutex
actionTimeouts = api.ActionTimeouts{}
)

func registerAction(t api.ActionType, f actionFactory) {
func registerAction(t api.ActionType, f actionFactory, timeout time.Duration) {
definedActionsLock.Lock()
defer definedActionsLock.Unlock()

Expand All @@ -156,6 +165,7 @@ func registerAction(t api.ActionType, f actionFactory) {
}

definedActions[t] = f
actionTimeouts[t] = api.NewTimeout(timeout)
}

func getActionFactory(t api.ActionType) (actionFactory, bool) {
Expand Down
7 changes: 2 additions & 5 deletions pkg/deployment/reconcile/action_add_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package reconcile

import (
"context"
"time"

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

Expand All @@ -35,17 +34,15 @@ import (
)

func init() {
registerAction(api.ActionTypeAddMember, newAddMemberAction)
registerAction(api.ActionTypeAddMember, newAddMemberAction, addMemberTimeout)
}

// newAddMemberAction creates a new Action that implements the given
// planned AddMember action.
func newAddMemberAction(log zerolog.Logger, action api.Action, actionCtx ActionContext) Action {
a := &actionAddMember{}

a.actionImpl = newBaseActionImpl(log, action, actionCtx, func(deploymentSpec api.DeploymentSpec) time.Duration {
return deploymentSpec.Timeouts.Get().AddMember.Get(addMemberTimeout)
}, &a.newMemberID)
a.actionImpl = newBaseActionImpl(log, action, actionCtx, &a.newMemberID)

return a
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ import (
)

func init() {
registerAction(api.ActionTypeArangoMemberUpdatePodSpec, newArangoMemberUpdatePodSpecAction)
registerAction(api.ActionTypeArangoMemberUpdatePodSpec, newArangoMemberUpdatePodSpecAction, defaultTimeout)
}

// newArangoMemberUpdatePodSpecAction creates a new Action that implements the given
// planned ArangoMemberUpdatePodSpec action.
func newArangoMemberUpdatePodSpecAction(log zerolog.Logger, action api.Action, actionCtx ActionContext) Action {
a := &actionArangoMemberUpdatePodSpec{}

a.actionImpl = newActionImplDefRef(log, action, actionCtx, defaultTimeout)
a.actionImpl = newActionImplDefRef(log, action, actionCtx)

return a
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

func init() {
registerAction(api.ActionTypeArangoMemberUpdatePodStatus, newArangoMemberUpdatePodStatusAction)
registerAction(api.ActionTypeArangoMemberUpdatePodStatus, newArangoMemberUpdatePodStatusAction, defaultTimeout)
}

const (
Expand All @@ -43,7 +43,7 @@ const (
func newArangoMemberUpdatePodStatusAction(log zerolog.Logger, action api.Action, actionCtx ActionContext) Action {
a := &actionArangoMemberUpdatePodStatus{}

a.actionImpl = newActionImplDefRef(log, action, actionCtx, defaultTimeout)
a.actionImpl = newActionImplDefRef(log, action, actionCtx)

return a
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deployment/reconcile/action_backup_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ import (
)

func init() {
registerAction(api.ActionTypeBackupRestore, newBackupRestoreAction)
registerAction(api.ActionTypeBackupRestore, newBackupRestoreAction, backupRestoreTimeout)
}

func newBackupRestoreAction(log zerolog.Logger, action api.Action, actionCtx ActionContext) Action {
a := &actionBackupRestore{}

a.actionImpl = newActionImplDefRef(log, action, actionCtx, backupRestoreTimeout)
a.actionImpl = newActionImplDefRef(log, action, actionCtx)

return a
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deployment/reconcile/action_backup_restore_clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ import (
)

func init() {
registerAction(api.ActionTypeBackupRestoreClean, newBackupRestoreCleanAction)
registerAction(api.ActionTypeBackupRestoreClean, newBackupRestoreCleanAction, backupRestoreTimeout)
}

func newBackupRestoreCleanAction(log zerolog.Logger, action api.Action, actionCtx ActionContext) Action {
a := &actionBackupRestoreClean{}

a.actionImpl = newActionImplDefRef(log, action, actionCtx, backupRestoreTimeout)
a.actionImpl = newActionImplDefRef(log, action, actionCtx)

return a
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/deployment/reconcile/action_bootstrap_set_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ import (
)

func init() {
registerAction(api.ActionTypeBootstrapSetPassword, newBootstrapSetPasswordAction)
registerAction(api.ActionTypeBootstrapSetPassword, newBootstrapSetPasswordAction, defaultTimeout)
}

func newBootstrapSetPasswordAction(log zerolog.Logger, action api.Action, actionCtx ActionContext) Action {
a := &actionBootstrapSetPassword{}

a.actionImpl = newActionImplDefRef(log, action, actionCtx, defaultTimeout)
a.actionImpl = newActionImplDefRef(log, action, actionCtx)

return a
}
Expand All @@ -66,7 +66,7 @@ func (a actionBootstrapSetPassword) Start(ctx context.Context) (bool, error) {
a.log.Warn().Msgf("User does not exist in password hashes")
return true, nil
} else {
ctxChild, cancel := context.WithTimeout(ctx, a.Timeout(spec))
ctxChild, cancel := globals.GetGlobals().Timeouts().ArangoD().WithTimeout(ctx)
defer cancel()

if password, err := a.setUserPassword(ctxChild, user, secret.Get()); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/deployment/reconcile/action_bootstrap_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ import (
)

func init() {
registerAction(api.ActionTypeBootstrapUpdate, newBootstrapUpdateAction)
registerAction(api.ActionTypeBootstrapUpdate, newBootstrapUpdateAction, defaultTimeout)
}

func newBootstrapUpdateAction(log zerolog.Logger, action api.Action, actionCtx ActionContext) Action {
a := &actionBootstrapUpdate{}

a.actionImpl = newActionImplDefRef(log, action, actionCtx, defaultTimeout)
a.actionImpl = newActionImplDefRef(log, action, actionCtx)

return a
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deployment/reconcile/action_cleanout_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ import (
)

func init() {
registerAction(api.ActionTypeCleanOutMember, newCleanOutMemberAction)
registerAction(api.ActionTypeCleanOutMember, newCleanOutMemberAction, cleanoutMemberTimeout)
}

// newCleanOutMemberAction creates a new Action that implements the given
// planned CleanOutMember action.
func newCleanOutMemberAction(log zerolog.Logger, action api.Action, actionCtx ActionContext) Action {
a := &actionCleanoutMember{}

a.actionImpl = newActionImplDefRef(log, action, actionCtx, cleanoutMemberTimeout)
a.actionImpl = newActionImplDefRef(log, action, actionCtx)

return a
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deployment/reconcile/action_cluster_member_cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ import (
)

func init() {
registerAction(api.ActionTypeClusterMemberCleanup, newClusterMemberCleanupAction)
registerAction(api.ActionTypeClusterMemberCleanup, newClusterMemberCleanupAction, addMemberTimeout)
}

// newClusterMemberCleanupAction creates a new Action that implements the given
// planned ClusterMemberCleanup action.
func newClusterMemberCleanupAction(log zerolog.Logger, action api.Action, actionCtx ActionContext) Action {
a := &actionClusterMemberCleanup{}

a.actionImpl = newActionImplDefRef(log, action, actionCtx, addMemberTimeout)
a.actionImpl = newActionImplDefRef(log, action, actionCtx)

return a
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deployment/reconcile/action_disable_scaling_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ import (
)

func init() {
registerAction(api.ActionTypeDisableClusterScaling, newDisableScalingCluster)
registerAction(api.ActionTypeDisableClusterScaling, newDisableScalingCluster, 0)
}

// newDisableScalingCluster creates the new action with disabling scaling DBservers and coordinators.
func newDisableScalingCluster(log zerolog.Logger, action api.Action, actionCtx ActionContext) Action {
a := &actionDisableScalingCluster{}

a.actionImpl = newActionImpl(log, action, actionCtx, 0, util.NewString(""))
a.actionImpl = newActionImpl(log, action, actionCtx, util.NewString(""))

return a
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deployment/reconcile/action_enable_scaling_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ import (
)

func init() {
registerAction(api.ActionTypeEnableClusterScaling, newEnableScalingCluster)
registerAction(api.ActionTypeEnableClusterScaling, newEnableScalingCluster, 0)
}

// newEnableScalingCluster creates the new action with enabling scaling DBservers and coordinators.
func newEnableScalingCluster(log zerolog.Logger, action api.Action, actionCtx ActionContext) Action {
a := &actionEnableScalingCluster{}

a.actionImpl = newActionImpl(log, action, actionCtx, 0, util.NewString(""))
a.actionImpl = newActionImpl(log, action, actionCtx, util.NewString(""))

return a
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deployment/reconcile/action_encryption_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ func ensureEncryptionSupport(actionCtx ActionContext) error {
}

func init() {
registerAction(api.ActionTypeEncryptionKeyAdd, newEncryptionKeyAdd)
registerAction(api.ActionTypeEncryptionKeyAdd, newEncryptionKeyAdd, defaultTimeout)
}

func newEncryptionKeyAdd(log zerolog.Logger, action api.Action, actionCtx ActionContext) Action {
a := &encryptionKeyAddAction{}

a.actionImpl = newActionImplDefRef(log, action, actionCtx, defaultTimeout)
a.actionImpl = newActionImplDefRef(log, action, actionCtx)

return a
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deployment/reconcile/action_encryption_propagated.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ import (
)

func init() {
registerAction(api.ActionTypeEncryptionKeyPropagated, newEncryptionKeyPropagated)
registerAction(api.ActionTypeEncryptionKeyPropagated, newEncryptionKeyPropagated, defaultTimeout)
}

func newEncryptionKeyPropagated(log zerolog.Logger, action api.Action, actionCtx ActionContext) Action {
a := &encryptionKeyPropagatedAction{}

a.actionImpl = newActionImplDefRef(log, action, actionCtx, defaultTimeout)
a.actionImpl = newActionImplDefRef(log, action, actionCtx)

return a
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deployment/reconcile/action_encryption_refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ import (
)

func init() {
registerAction(api.ActionTypeEncryptionKeyRefresh, newEncryptionKeyRefresh)
registerAction(api.ActionTypeEncryptionKeyRefresh, newEncryptionKeyRefresh, defaultTimeout)
}

func newEncryptionKeyRefresh(log zerolog.Logger, action api.Action, actionCtx ActionContext) Action {
a := &encryptionKeyRefreshAction{}

a.actionImpl = newActionImplDefRef(log, action, actionCtx, defaultTimeout)
a.actionImpl = newActionImplDefRef(log, action, actionCtx)

return a
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deployment/reconcile/action_encryption_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ import (
)

func init() {
registerAction(api.ActionTypeEncryptionKeyRemove, newEncryptionKeyRemove)
registerAction(api.ActionTypeEncryptionKeyRemove, newEncryptionKeyRemove, defaultTimeout)
}

func newEncryptionKeyRemove(log zerolog.Logger, action api.Action, actionCtx ActionContext) Action {
a := &encryptionKeyRemoveAction{}

a.actionImpl = newActionImplDefRef(log, action, actionCtx, defaultTimeout)
a.actionImpl = newActionImplDefRef(log, action, actionCtx)

return a
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/deployment/reconcile/action_encryption_status_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ import (
)

func init() {
registerAction(api.ActionTypeEncryptionKeyStatusUpdate, newEncryptionKeyStatusUpdate)
registerAction(api.ActionTypeEncryptionKeyStatusUpdate, newEncryptionKeyStatusUpdate, defaultTimeout)
}

func newEncryptionKeyStatusUpdate(log zerolog.Logger, action api.Action, actionCtx ActionContext) Action {
a := &encryptionKeyStatusUpdateAction{}

a.actionImpl = newActionImplDefRef(log, action, actionCtx, defaultTimeout)
a.actionImpl = newActionImplDefRef(log, action, actionCtx)

return a
}
Expand Down
Loading