Skip to content

Commit 095e261

Browse files
authored
[Feature] [ArangoBackup] Propagate message during retries (#1613)
1 parent 25542de commit 095e261

File tree

5 files changed

+56
-8
lines changed

5 files changed

+56
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- (Bugfix) Check Connection to the ArangoDB before creating Backup
1313
- (Feature) Deployment & Members Condition metrics
1414
- (Maintenance) Update Go to 1.21.8 & Dependencies
15+
- (Feature) (ArangoBackup) Propagate message during retries
1516

1617
## [1.2.38](https://github.com/arangodb/kube-arangodb/tree/1.2.38) (2024-02-22)
1718
- (Feature) Extract GRPC Server

pkg/handlers/backup/state_createerror.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -29,7 +29,8 @@ import (
2929
func stateCreateErrorHandler(h *handler, backup *backupApi.ArangoBackup) (*backupApi.ArangoBackupStatus, error) {
3030
if !backup.Spec.Backoff.Enabled() {
3131
return wrapUpdateStatus(backup,
32-
updateStatusState(backupApi.ArangoBackupStateFailed, "retries are disabled"),
32+
updateStatusStateOnly(backupApi.ArangoBackupStateFailed),
33+
cleanBackOff(),
3334
cleanStatusJob())
3435
}
3536

pkg/handlers/backup/state_createerror_test.go

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -97,7 +97,8 @@ func Test_State_CreateError_Retry_WhenBackoffDisabled_C1(t *testing.T) {
9797
// Assert
9898
newObj := refreshArangoBackup(t, handler, obj)
9999
require.Equal(t, newObj.Status.State, backupApi.ArangoBackupStateFailed)
100-
require.Equal(t, newObj.Status.Message, "retries are disabled")
100+
require.Nil(t, newObj.Status.Backoff)
101+
require.Equal(t, newObj.Status.Message, "")
101102
}
102103

103104
func Test_State_CreateError_Retry_WhenBackoffDisabled_C2(t *testing.T) {
@@ -126,7 +127,42 @@ func Test_State_CreateError_Retry_WhenBackoffDisabled_C2(t *testing.T) {
126127
// Assert
127128
newObj := refreshArangoBackup(t, handler, obj)
128129
require.Equal(t, newObj.Status.State, backupApi.ArangoBackupStateFailed)
129-
require.Equal(t, newObj.Status.Message, "retries are disabled")
130+
require.Nil(t, newObj.Status.Backoff)
131+
require.Equal(t, newObj.Status.Message, "")
132+
}
133+
134+
func Test_State_CreateError_Retry_WhenBackoffDisabled_C3(t *testing.T) {
135+
// Arrange
136+
message := "SomeRandomErrorMessage"
137+
138+
handler, mock := newErrorsFakeHandler(mockErrorsArangoClientBackup{})
139+
140+
obj, deployment := newObjectSet(t, backupApi.ArangoBackupStateCreateError)
141+
142+
obj.Status.Message = message
143+
144+
backupMeta, err := mock.Create()
145+
require.NoError(t, err)
146+
147+
obj.Status.Backup = &backupApi.ArangoBackupDetails{
148+
ID: string(backupMeta.ID),
149+
Version: backupMeta.Version,
150+
CreationTimestamp: meta.Now(),
151+
}
152+
153+
obj.Status.Time.Time = time.Now().Add(-2 * downloadDelay)
154+
155+
// Act
156+
createArangoDeployment(t, handler, deployment)
157+
createArangoBackup(t, handler, obj)
158+
159+
require.NoError(t, handler.Handle(context.Background(), tests.NewItem(t, operation.Update, obj)))
160+
161+
// Assert
162+
newObj := refreshArangoBackup(t, handler, obj)
163+
require.Equal(t, newObj.Status.State, backupApi.ArangoBackupStateFailed)
164+
require.Nil(t, newObj.Status.Backoff)
165+
require.Equal(t, newObj.Status.Message, message)
130166
}
131167

132168
func Test_State_CreateError_Transfer_To_Failed(t *testing.T) {

pkg/handlers/backup/state_uploaderror.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -30,7 +30,8 @@ func stateUploadErrorHandler(h *handler, backup *backupApi.ArangoBackup) (*backu
3030
// no more retries - move to failed state
3131
if !backup.Status.Backoff.ShouldBackoff(backup.Spec.Backoff) {
3232
return wrapUpdateStatus(backup,
33-
updateStatusState(backupApi.ArangoBackupStateFailed, "out of Upload retries"),
33+
updateStatusStateOnly(backupApi.ArangoBackupStateFailed),
34+
cleanBackOff(),
3435
cleanStatusJob())
3536
}
3637

pkg/handlers/backup/status.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -50,6 +50,15 @@ func updateStatus(backup *backupApi.ArangoBackup, update ...updateStatusFunc) *b
5050
return s
5151
}
5252

53+
func updateStatusStateOnly(state state.State) updateStatusFunc {
54+
return func(status *backupApi.ArangoBackupStatus) {
55+
if status.State != state {
56+
status.Time = meta.Now()
57+
}
58+
status.State = state
59+
}
60+
}
61+
5362
func updateStatusState(state state.State, template string, a ...interface{}) updateStatusFunc {
5463
return func(status *backupApi.ArangoBackupStatus) {
5564
if status.State != state {

0 commit comments

Comments
 (0)