8000 [Bugfix] Check Connection to the ArangoDB before creating Backup (#1609) · arangodb/kube-arangodb@1a2097c · GitHub
[go: up one dir, main page]

Skip to content

Commit 1a2097c

Browse files
authored
[Bugfix] Check Connection to the ArangoDB before creating Backup (#1609)
1 parent a29ef01 commit 1a2097c

File tree

6 files changed

+52
-4
lines changed

6 files changed

+52
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- (Feature) JobScheduler Coverage
1010
- (Feature) JobScheduler Volumes, Probes, Lifecycle and Ports integration
1111
- (Feature) Merge ArangoDB Usage Metrics
12+
- (Bugfix) Check Connection to the ArangoDB before creating Backup
1213

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

pkg/handlers/backup/arango_client.go

Lines changed: 3 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.
@@ -75,5 +75,7 @@ type ArangoBackupClient interface {
7575
Exists(driver.BackupID) (bool, error)
7676
Delete(driver.BackupID) error
7777

78+
HealthCheck() error
79+
7880
List() (map[driver.BackupID]driver.BackupMeta, error)
7981
}

pkg/handlers/backup/arango_client_impl.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,11 @@ func (ac *arangoClientBackupImpl) Abort(jobID driver.BackupTransferJobID) error
292292

293293
return ac.driver.Backup().Abort(ctx, jobID)
294294
}
295+
296+
func (ac *arangoClientBackupImpl) HealthCheck() error {
297+
ctx, cancel := globals.GetGlobalTimeouts().BackupArangoClientTimeout().WithTimeout(context.Background())
298+
defer cancel()
299+
300+
_, err := ac.driver.Version(ctx)
301+
return err
302+
}

pkg/handlers/backup/arango_client_mock_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func newMockArangoClientBackup(errors mockErrorsArangoClientBackup) *mockArangoC
6464
}
6565

6666
type mockErrorsArangoClientBackup struct {
67-
createError, listError, getError, uploadError, downloadError, progressError, existsError, deleteError, abortError error
67+
createError, listError, getError, uploadError, downloadError, progressError, existsError, deleteError, abortError, healthCheckError error
6868
}
6969

7070
type mockArangoClientBackupState struct {
@@ -245,6 +245,10 @@ func (m *mockArangoClientBackup) CreateAsync(jobID string) (ArangoBackupCreateRe
245245
return ArangoBackupCreateResponse{}, async.NewErrorAsyncJobInProgress(jobID)
246246
}
247247

248+
func (m *mockArangoClientBackup) HealthCheck() error {
249+
return m.state.errors.healthCheckError
250+
}
251+
248252
func (m *mockArangoClientBackup) getIDs() []string {
249253
ret := make([]string, 0, len(m.state.backups))
250254

pkg/handlers/backup/state_create.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.
@@ -39,6 +39,15 @@ func stateCreateHandler(h *handler, backup *backupApi.ArangoBackup) (*backupApi.
3939
return nil, newTemporaryError(err)
4040
}
4141

42+
if err := client.HealthCheck(); err != nil {
43+
return wrapUpdateStatus(backup,
44+
updateStatusState(backupApi.ArangoBackupStateCreateError, "Create failed on HealthCheck with error: %s", err.Error()),
45+
cleanStatusJob(),
46+
updateStatusAvailable(false),
47+
addBackOff(backup.Spec),
48+
)
49+
}
50+
4251
if features.AsyncBackupCreation().Enabled() {
4352
return asyncBackup(client, backup)
4453
} else {

pkg/handlers/backup/state_create_test.go

Lines changed: 25 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.
@@ -153,6 +153,30 @@ func Test_State_Create_Upload(t *testing.T) {
153153
compareBackupMeta(t, backupMeta, newObj)
154154
}
155155

156+
func Test_State_Create_CreateError_Health(t *testing.T) {
157+
*features.AsyncBackupCreation().EnabledPointer() = false
158+
159+
// Arrange
160+
handler, _ := newErrorsFakeHandler(mockErrorsArangoClientBackup{
161+
healthCheckError: newFatalErrorf("error"),
162+
})
163+
164+
obj, deployment := newObjectSet(t, backupApi.ArangoBackupStateCreate)
165+
166+
// Act
167+
createArangoDeployment(t, handler, deployment)
168+
createArangoBackup(t, handler, obj)
169+
170+
require.NoError(t, handler.Handle(context.Background(), tests.NewItem(t, operation.Update, obj)))
171+
172+
// Assert
173+
newObj := refreshArangoBackup(t, handler, obj)
174+
require.Equal(t, newObj.Status.State, backupApi.ArangoBackupStateCreateError)
175+
require.Equal(t, newObj.Status.Message, "Create failed on HealthCheck with error: error")
176+
require.Nil(t, newObj.Status.Backup)
177+
require.False(t, newObj.Status.Available)
178+
}
179+
156180
func Test_State_Create_CreateError(t *testing.T) {
157181
*features.AsyncBackupCreation().EnabledPointer() = false
158182

0 commit comments

Comments
 (0)
0