Skip to content

Commit 50a3aa4

Browse files
authored
GT-341 Fix invalid Timeout calculation in case of ActionList (#1243)
1 parent 2bf6769 commit 50a3aa4

File tree

3 files changed

+95
-6
lines changed

3 files changed

+95
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- (Maintenance) Add & Enable YAML Linter
1515
- (Feature) Optional ResignLeadership Action
1616
- (Feature) Improve CRD Management and deprecate CRD Chart
17+
- (Bugfix) Fix invalid Timeout calculation in case of ActionList
1718

1819
## [1.2.24](https://github.com/arangodb/kube-arangodb/tree/1.2.24) (2023-01-25)
1920
- (Bugfix) Fix deployment creation on ARM64

pkg/deployment/reconcile/plan_executor.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,18 +396,30 @@ func (d *Reconciler) executeAction(ctx context.Context, planAction api.Action, a
396396
log.Warn("Action aborted. Removing the entire plan")
397397
d.context.CreateEvent(k8sutil.NewPlanAbortedEvent(d.context.GetAPIObject(), string(planAction.Type), planAction.MemberID, planAction.Group.AsRole()))
398398
return false, true, false, false, nil
399-
} else if !timeout.Infinite() {
400-
if time.Now().After(planAction.CreationTime.Add(timeout.Duration)) {
401-
log.Warn("Action not finished in time. Removing the entire plan")
402-
d.context.CreateEvent(k8sutil.NewPlanTimeoutEvent(d.context.GetAPIObject(), string(planAction.Type), planAction.MemberID, planAction.Group.AsRole()))
403-
return false, true, false, false, nil
404-
}
399+
} else if isActionTimeout(timeout, planAction) {
400+
log.Warn("Action not finished in time. Removing the entire plan")
401+
d.context.CreateEvent(k8sutil.NewPlanTimeoutEvent(d.context.GetAPIObject(), string(planAction.Type), planAction.MemberID, planAction.Group.AsRole()))
402+
return false, true, false, false, nil
403+
405404
}
406405

407406
// Timeout not yet expired, come back soon
408407
return false, false, true, false, nil
409408
}
410409

410+
func isActionTimeout(timeout api.Timeout, planAction api.Action) bool {
411+
if planAction.StartTime == nil {
412+
return false
413+
}
414+
if planAction.StartTime.IsZero() {
415+
return false
416+
}
417+
if timeout.Infinite() {
418+
return false
419+
}
420+
return time.Since(planAction.StartTime.Time) > timeout.Duration
421+
}
422+
411423
func (d *Reconciler) executeActionCheckProgress(ctx context.Context, action Action) (ready bool, abort bool, retErr error) {
412424
retErr = panics.RecoverWithSection("ActionProgress", func() (err error) {
413425
ready, abort, err = action.CheckProgress(ctx)
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2023 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+
"testing"
25+
"time"
26+
27+
"github.com/stretchr/testify/require"
28+
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
29+
30+
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
31+
)
32+
33+
func TestIsActionTimeout(t *testing.T) {
34+
type testCase struct {
35+
timeout api.Timeout
36+
action api.Action
37+
expectedResult bool
38+
}
39+
40+
timeFiveMinutesAgo := meta.Time{
41+
Time: time.Now().Add(-time.Hour),
42+
}
43+
44+
testCases := map[string]testCase{
45+
"nil start time": {
46+
timeout: api.Timeout{},
47+
action: api.Action{},
48+
expectedResult: false,
49+
},
50+
"infinite timeout": {
51+
timeout: api.NewTimeout(0),
52+
action: api.Action{},
53+
expectedResult: false,
54+
},
55+
"timeouted case": {
56+
timeout: api.NewTimeout(time.Minute),
57+
action: api.Action{
58+
StartTime: &timeFiveMinutesAgo,
59+
},
60+
expectedResult: true,
61+
},
62+
"still in progress case": {
63+
timeout: api.NewTimeout(time.Minute * 10),
64+
action: api.Action{
65+
StartTime: &timeFiveMinutesAgo,
66+
},
67+
expectedResult: true,
68+
},
69+
}
70+
71+
for n, c := range testCases {
72+
t.Run(n, func(t *testing.T) {
73+
require.Equal(t, c.expectedResult, isActionTimeout(c.timeout, c.action))
74+
})
75+
}
76+
}

0 commit comments

Comments
 (0)