Skip to content

Commit a117bdb

Browse files
authored
[Feature] Allow to configure action timeouts (#934)
1 parent 53871be commit a117bdb

File tree

69 files changed

+216
-168
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+216
-168
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- (Update) Bump K8S API to 1.21.10
99
- (Feature) (ACS) Add ACS handler
1010
- (Feature) Allow to restart DBServers in cases when WriteConcern will be satisfied
11+
- (Feature) Allow to configure action timeouts
1112

1213
## [1.2.8](https://github.com/arangodb/kube-arangodb/tree/1.2.8) (2022-02-24)
1314
- Do not check License V2 on Community images

pkg/apis/deployment/v1/timeouts.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,18 @@ const (
3131
)
3232

3333
type Timeouts struct {
34-
// AddMember action timeout
35-
AddMember *Timeout `json:"addMember,omitempty"`
3634

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

40-
// RuntimeContainerImageUpdate action timeout
41-
RuntimeContainerImageUpdate *Timeout `json:"runtimeContainerImageUpdate,omitempty"`
38+
// Actions
39+
Actions ActionTimeouts `json:"actions,omitempty"`
40+
41+
// deprecated
42+
AddMember *Timeout `json:"-"`
43+
44+
// deprecated
45+
RuntimeContainerImageUpdate *Timeout `json:"-"`
4246
}
4347

4448
func (t *Timeouts) GetMaintenanceGracePeriod() time.Duration {
@@ -57,6 +61,12 @@ func (t *Timeouts) Get() Timeouts {
5761
return *t
5862
}
5963

64+
type ActionTimeouts map[ActionType]Timeout
65+
66+
func NewTimeout(timeout time.Duration) Timeout {
67+
return Timeout(meta.Duration{Duration: timeout})
68+
}
69+
6070
type Timeout meta.Duration
6171

6272
func (t *Timeout) Get(d time.Duration) time.Duration {

pkg/deployment/reconcile/action.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ import (
3030
"github.com/rs/zerolog"
3131
)
3232

33+
func GetAllActions() []api.ActionType {
34+
z := make([]api.ActionType, 0, len(definedActions))
35+
36+
for k := range definedActions {
37+
z = append(z, k)
38+
}
39+
40+
return z
41+
}
42+
3343
// ActionCore executes a single Plan item.
3444
type ActionCore interface {
3545
// Start performs the start of the action.
@@ -45,8 +55,6 @@ type ActionCore interface {
4555
type Action interface {
4656
ActionCore
4757

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

149-
func registerAction(t api.ActionType, f actionFactory) {
158+
func registerAction(t api.ActionType, f actionFactory, timeout time.Duration) {
150159
definedActionsLock.Lock()
151160
defer definedActionsLock.Unlock()
152161

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

158167
definedActions[t] = f
168+
actionTimeouts[t] = api.NewTimeout(timeout)
159169
}
160170

161171
func getActionFactory(t api.ActionType) (actionFactory, bool) {

pkg/deployment/reconcile/action_add_member.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ package reconcile
2222

2323
import (
2424
"context"
25-
"time"
2625

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

@@ -35,17 +34,15 @@ import (
3534
)
3635

3736
func init() {
38-
registerAction(api.ActionTypeAddMember, newAddMemberAction)
37+
registerAction(api.ActionTypeAddMember, newAddMemberAction, addMemberTimeout)
3938
}
4039

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

46-
a.actionImpl = newBaseActionImpl(log, action, actionCtx, func(deploymentSpec api.DeploymentSpec) time.Duration {
47-
return deploymentSpec.Timeouts.Get().AddMember.Get(addMemberTimeout)
48-
}, &a.newMemberID)
45+
a.actionImpl = newBaseActionImpl(log, action, actionCtx, &a.newMemberID)
4946

5047
return a
5148
}

pkg/deployment/reconcile/action_arango_member_update_pod_spec.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ import (
3333
)
3434

3535
func init() {
36-
registerAction(api.ActionTypeArangoMemberUpdatePodSpec, newArangoMemberUpdatePodSpecAction)
36+
registerAction(api.ActionTypeArangoMemberUpdatePodSpec, newArangoMemberUpdatePodSpecAction, defaultTimeout)
3737
}
3838

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

44-
a.actionImpl = newActionImplDefRef(log, action, actionCtx, defaultTimeout)
44+
a.actionImpl = newActionImplDefRef(log, action, actionCtx)
4545

4646
return a
4747
}

pkg/deployment/reconcile/action_arango_member_update_pod_status.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
)
3232

3333
func init() {
34-
registerAction(api.ActionTypeArangoMemberUpdatePodStatus, newArangoMemberUpdatePodStatusAction)
34+
registerAction(api.ActionTypeArangoMemberUpdatePodStatus, newArangoMemberUpdatePodStatusAction, defaultTimeout)
3535
}
3636

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

46-
a.actionImpl = newActionImplDefRef(log, action, actionCtx, defaultTimeout)
46+
a.actionImpl = newActionImplDefRef(log, action, actionCtx)
4747

4848
return a
4949
}

pkg/deployment/reconcile/action_backup_restore.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ import (
3232
)
3333

3434
func init() {
35-
registerAction(api.ActionTypeBackupRestore, newBackupRestoreAction)
35+
registerAction(api.ActionTypeBackupRestore, newBackupRestoreAction, backupRestoreTimeout)
3636
}
3737

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

41-
a.actionImpl = newActionImplDefRef(log, action, actionCtx, backupRestoreTimeout)
41+
a.actionImpl = newActionImplDefRef(log, action, actionCtx)
4242

4343
return a
4444
}

pkg/deployment/reconcile/action_backup_restore_clean.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ import (
2828
)
2929

3030
func init() {
31-
registerAction(api.ActionTypeBackupRestoreClean, newBackupRestoreCleanAction)
31+
registerAction(api.ActionTypeBackupRestoreClean, newBackupRestoreCleanAction, backupRestoreTimeout)
3232
}
3333

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

37-
a.actionImpl = newActionImplDefRef(log, action, actionCtx, backupRestoreTimeout)
37+
a.actionImpl = newActionImplDefRef(log, action, actionCtx)
3838

3939
return a
4040
}

pkg/deployment/reconcile/action_bootstrap_set_password.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ import (
3737
)
3838

3939
func init() {
40-
registerAction(api.ActionTypeBootstrapSetPassword, newBootstrapSetPasswordAction)
40+
registerAction(api.ActionTypeBootstrapSetPassword, newBootstrapSetPasswordAction, defaultTimeout)
4141
}
4242

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

46-
a.actionImpl = newActionImplDefRef(log, action, actionCtx, defaultTimeout)
46+
a.actionImpl = newActionImplDefRef(log, action, actionCtx)
4747

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

7272
if password, err := a.setUserPassword(ctxChild, user, secret.Get()); err != nil {

pkg/deployment/reconcile/action_bootstrap_update.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ import (
2828
)
2929

3030
func init() {
31-
registerAction(api.ActionTypeBootstrapUpdate, newBootstrapUpdateAction)
31+
registerAction(api.ActionTypeBootstrapUpdate, newBootstrapUpdateAction, defaultTimeout)
3232
}
3333

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

37-
a.actionImpl = newActionImplDefRef(log, action, actionCtx, defaultTimeout)
37+
a.actionImpl = newActionImplDefRef(log, action, actionCtx)
3838

3939
return a
4040
}

0 commit comments

Comments
 (0)