Skip to content

Commit f81a2da

Browse files
authored
[Feature] Delay Action (#1827)
1 parent 67059bc commit f81a2da

13 files changed

+146
-9
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- (Feature) Allow to continue if ResignServer job is gone
1616
- (Feature) UpgradeByReplace Flow
1717
- (Feature) (Platform) ArangoRoute Timeout option
18+
- (Feature) Delay Action
1819

1920
## [1.2.44](https://github.com/arangodb/kube-arangodb/tree/1.2.44) (2025-02-03)
2021
- (Maintenance) Kubernetes 1.31.1 libraries

docs/generated/actions.md

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ nav_order: 11
2525
| CleanTLSCACertificate | no | 30m0s | no | Enterprise Only | Remove Certificate from CA TrustStore |
2626
| CleanTLSKeyfileCertificate | no | 30m0s | no | Enterprise Only | Remove old TLS certificate from server |
2727
| ClusterMemberCleanup | no | 10m0s | no | Community & Enterprise | Remove member from Cluster if it is gone already (Coordinators) |
28+
| Delay | no | 10m0s | yes | Community & Enterprise | Define delay operation |
2829
| ~~DisableClusterScaling~~ | no | 10m0s | no | Community & Enterprise | Disable Cluster Scaling integration |
2930
| DisableMaintenance | no | 10m0s | no | Community & Enterprise | Disable ArangoDB maintenance mode |
3031
| DisableMemberMaintenance | no | 10m0s | no | Enterprise Only | Disable ArangoDB DBServer maintenance mode |
@@ -121,6 +122,7 @@ spec:
121122
CleanTLSCACertificate: 30m0s
122123
CleanTLSKeyfileCertificate: 30m0s
123124
ClusterMemberCleanup: 10m0s
125+
Delay: 10m0s
124126
DisableClusterScaling: 10m0s
125127
DisableMaintenance: 10m0s
126128
DisableMemberMaintenance: 10m0s

internal/actions.config.go.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{- $root := . -}}
22
//
3-
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
3+
// Copyright 2023-2025 ArangoDB GmbH, Cologne, Germany
44
//
55
// Licensed under the Apache License, Version 2.0 (the "License");
66
// you may not use this file except in compliance with the License.

internal/actions.go.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{- $root := . -}}
22
//
3-
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
3+
// Copyright 2016-2025 ArangoDB GmbH, Cologne, Germany
44
//
55
// Licensed under the Apache License, Version 2.0 (the "License");
66
// you may not use this file except in compliance with the License.

internal/actions.register.go.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{- $root := . -}}
22
//
3-
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
3+
// Copyright 2016-2025 ArangoDB GmbH, Cologne, Germany
44
//
55
// Licensed under the Apache License, Version 2.0 (the "License");
66
// you may not use this file except in compliance with the License.

internal/actions.register.test.go.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{- $root := . -}}
22
//
3-
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
3+
// Copyright 2016-2025 ArangoDB GmbH, Cologne, Germany
44
//
55
// Licensed under the Apache License, Version 2.0 (the "License");
66
// you may not use this file except in compliance with the License.

internal/actions.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ actions:
44
description: Empty placeholder action
55
Idle:
66
description: Define idle operation in case if preconditions are not meet
7+
Delay:
8+
description: Define delay operation
9+
optional: true
10+
scopes:
11+
- Normal
12+
- High
713
AddMember:
814
description: Adds new member to the Member list
915
timeout: 10m

pkg/apis/deployment/v1/actions.generated.go

+13-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/deployment/v2alpha1/actions.generated.go

+13-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/deployment/reconcile/action.config.generated.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/deployment/reconcile/action.register.generated.go

+18-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/deployment/reconcile/action.register.generated_test.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
2+
// Copyright 2016-2025 ArangoDB GmbH, Cologne, Germany
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -160,6 +160,16 @@ func Test_Actions(t *testing.T) {
160160
})
161161
})
162162

163+
t.Run("Delay", func(t *testing.T) {
164+
ActionsExistence(t, api.ActionTypeDelay)
165+
t.Run("Internal", func(t *testing.T) {
166+
require.False(t, api.ActionTypeDelay.Internal())
167+
})
168+
t.Run("Optional", func(t *testing.T) {
169+
require.True(t, api.ActionTypeDelay.Optional())
170+
})
171+
})
172+
163173
t.Run("DisableClusterScaling", func(t *testing.T) {
164174
// nolint:staticcheck
165175
ActionsExistence(t, api.ActionTypeDisableClusterScaling)
+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2025 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package reconcile
22+
23+
import (
24+
"context"
25+
"time"
26+
27+
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
28+
)
29+
30+
const (
31+
DelayActionDuration = "delayActionDuration"
32+
)
33+
34+
// newDelayAction creates a new Action that implements the given
35+
// planned Delay action.
36+
func newDelayAction(action api.Action, actionCtx ActionContext) Action {
37+
a := &actionDelay{}
38+
39+
a.actionImpl = newActionImplDefRef(action, actionCtx)
40+
41+
return a
42+
}
43+
44+
// actionDelay implements an Delay.
45+
type actionDelay struct {
46+
// actionImpl implement timeout and member id functions
47+
actionImpl
48+
}
49+
50+
// Start performs the start of the action.
51+
// Returns true if the action is completely finished, false in case
52+
// the start time needs to be recorded and a ready condition needs to be checked.
53+
func (a *actionDelay) Start(ctx context.Context) (bool, error) {
54+
return false, nil
55+
}
56+
57+
func (a *actionDelay) CheckProgress(ctx context.Context) (bool, bool, error) {
58+
v, ok := a.action.Params[DelayActionDuration]
59+
if !ok {
60+
a.log.Str("key", DelayActionDuration).Warn("Param for the delay not defined")
61+
return true, false, nil
62+
}
63+
64+
d, err := time.ParseDuration(v)
65+
if err != nil {
66+
a.log.Err(err).Str("value", v).Warn("Unable to parse duration")
67+
return true, false, nil
68+
}
69+
70+
if v := a.action.StartTime; v != nil {
71+
if v.Time.Add(d).Before(time.Now()) {
72+
return true, false, nil
73+
}
74+
}
75+
76+
return false, false, nil
77+
}

0 commit comments

Comments
 (0)