diff --git a/CHANGELOG.md b/CHANGELOG.md index e945ce9c9..930144301 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - (Bugfix) Check Connection to the ArangoDB before creating Backup - (Feature) Deployment & Members Condition metrics - (Maintenance) Update Go to 1.21.8 & Dependencies +- (Feature) (ArangoBackup) Propagate message during retries ## [1.2.38](https://github.com/arangodb/kube-arangodb/tree/1.2.38) (2024-02-22) - (Feature) Extract GRPC Server diff --git a/pkg/handlers/backup/state_createerror.go b/pkg/handlers/backup/state_createerror.go index 9e7428b34..9ee71f3e9 100644 --- a/pkg/handlers/backup/state_createerror.go +++ b/pkg/handlers/backup/state_createerror.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -29,7 +29,8 @@ import ( func stateCreateErrorHandler(h *handler, backup *backupApi.ArangoBackup) (*backupApi.ArangoBackupStatus, error) { if !backup.Spec.Backoff.Enabled() { return wrapUpdateStatus(backup, - updateStatusState(backupApi.ArangoBackupStateFailed, "retries are disabled"), + updateStatusStateOnly(backupApi.ArangoBackupStateFailed), + cleanBackOff(), cleanStatusJob()) } diff --git a/pkg/handlers/backup/state_createerror_test.go b/pkg/handlers/backup/state_createerror_test.go index 2064f2997..311f6bc10 100644 --- a/pkg/handlers/backup/state_createerror_test.go +++ b/pkg/handlers/backup/state_createerror_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // 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) { // Assert newObj := refreshArangoBackup(t, handler, obj) require.Equal(t, newObj.Status.State, backupApi.ArangoBackupStateFailed) - require.Equal(t, newObj.Status.Message, "retries are disabled") + require.Nil(t, newObj.Status.Backoff) + require.Equal(t, newObj.Status.Message, "") } func Test_State_CreateError_Retry_WhenBackoffDisabled_C2(t *testing.T) { @@ -126,7 +127,42 @@ func Test_State_CreateError_Retry_WhenBackoffDisabled_C2(t *testing.T) { // Assert newObj := refreshArangoBackup(t, handler, obj) require.Equal(t, newObj.Status.State, backupApi.ArangoBackupStateFailed) - require.Equal(t, newObj.Status.Message, "retries are disabled") + require.Nil(t, newObj.Status.Backoff) + require.Equal(t, newObj.Status.Message, "") +} + +func Test_State_CreateError_Retry_WhenBackoffDisabled_C3(t *testing.T) { + // Arrange + message := "SomeRandomErrorMessage" + + handler, mock := newErrorsFakeHandler(mockErrorsArangoClientBackup{}) + + obj, deployment := newObjectSet(t, backupApi.ArangoBackupStateCreateError) + + obj.Status.Message = message + + backupMeta, err := mock.Create() + require.NoError(t, err) + + obj.Status.Backup = &backupApi.ArangoBackupDetails{ + ID: string(backupMeta.ID), + Version: backupMeta.Version, + CreationTimestamp: meta.Now(), + } + + obj.Status.Time.Time = time.Now().Add(-2 * downloadDelay) + + // Act + createArangoDeployment(t, handler, deployment) + createArangoBackup(t, handler, obj) + + require.NoError(t, handler.Handle(context.Background(), tests.NewItem(t, operation.Update, obj))) + + // Assert + newObj := refreshArangoBackup(t, handler, obj) + require.Equal(t, newObj.Status.State, backupApi.ArangoBackupStateFailed) + require.Nil(t, newObj.Status.Backoff) + require.Equal(t, newObj.Status.Message, message) } func Test_State_CreateError_Transfer_To_Failed(t *testing.T) { diff --git a/pkg/handlers/backup/state_uploaderror.go b/pkg/handlers/backup/state_uploaderror.go index abfa4edc5..ec4877195 100644 --- a/pkg/handlers/backup/state_uploaderror.go +++ b/pkg/handlers/backup/state_uploaderror.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -30,7 +30,8 @@ func stateUploadErrorHandler(h *handler, backup *backupApi.ArangoBackup) (*backu // no more retries - move to failed state if !backup.Status.Backoff.ShouldBackoff(backup.Spec.Backoff) { return wrapUpdateStatus(backup, - updateStatusState(backupApi.ArangoBackupStateFailed, "out of Upload retries"), + updateStatusStateOnly(backupApi.ArangoBackupStateFailed), + cleanBackOff(), cleanStatusJob()) } diff --git a/pkg/handlers/backup/status.go b/pkg/handlers/backup/status.go index edd80fe9d..cbc177b83 100644 --- a/pkg/handlers/backup/status.go +++ b/pkg/handlers/backup/status.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -50,6 +50,15 @@ func updateStatus(backup *backupApi.ArangoBackup, update ...updateStatusFunc) *b return s } +func updateStatusStateOnly(state state.State) updateStatusFunc { + return func(status *backupApi.ArangoBackupStatus) { + if status.State != state { + status.Time = meta.Now() + } + status.State = state + } +} + func updateStatusState(state state.State, template string, a ...interface{}) updateStatusFunc { return func(status *backupApi.ArangoBackupStatus) { if status.State != state {