Skip to content

Commit

Permalink
[Bugfix] Check Connection to the ArangoDB before creating Backup (#1609)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajanikow authored Mar 5, 2024
1 parent a29ef01 commit 1a2097c
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- (Feature) JobScheduler Coverage
- (Feature) JobScheduler Volumes, Probes, Lifecycle and Ports integration
- (Feature) Merge ArangoDB Usage Metrics
- (Bugfix) Check Connection to the ArangoDB before creating Backup

## [1.2.38](https://github.com/arangodb/kube-arangodb/tree/1.2.38) (2024-02-22)
- (Feature) Extract GRPC Server
Expand Down
4 changes: 3 additions & 1 deletion pkg/handlers/backup/arango_client.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -75,5 +75,7 @@ type ArangoBackupClient interface {
Exists(driver.BackupID) (bool, error)
Delete(driver.BackupID) error

HealthCheck() error

List() (map[driver.BackupID]driver.BackupMeta, error)
}
8 changes: 8 additions & 0 deletions pkg/handlers/backup/arango_client_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,11 @@ func (ac *arangoClientBackupImpl) Abort(jobID driver.BackupTransferJobID) error

return ac.driver.Backup().Abort(ctx, jobID)
}

func (ac *arangoClientBackupImpl) HealthCheck() error {
ctx, cancel := globals.GetGlobalTimeouts().BackupArangoClientTimeout().WithTimeout(context.Background())
defer cancel()

_, err := ac.driver.Version(ctx)
return err
}
6 changes: 5 additions & 1 deletion pkg/handlers/backup/arango_client_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func newMockArangoClientBackup(errors mockErrorsArangoClientBackup) *mockArangoC
}

type mockErrorsArangoClientBackup struct {
createError, listError, getError, uploadError, downloadError, progressError, existsError, deleteError, abortError error
createError, listError, getError, uploadError, downloadError, progressError, existsError, deleteError, abortError, healthCheckError error
}

type mockArangoClientBackupState struct {
Expand Down Expand Up @@ -245,6 +245,10 @@ func (m *mockArangoClientBackup) CreateAsync(jobID string) (ArangoBackupCreateRe
return ArangoBackupCreateResponse{}, async.NewErrorAsyncJobInProgress(jobID)
}

func (m *mockArangoClientBackup) HealthCheck() error {
return m.state.errors.healthCheckError
}

func (m *mockArangoClientBackup) getIDs() []string {
ret := make([]string, 0, len(m.state.backups))

Expand Down
11 changes: 10 additions & 1 deletion pkg/handlers/backup/state_create.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -39,6 +39,15 @@ func stateCreateHandler(h *handler, backup *backupApi.ArangoBackup) (*backupApi.
return nil, newTemporaryError(err)
}

if err := client.HealthCheck(); err != nil {
return wrapUpdateStatus(backup,
updateStatusState(backupApi.ArangoBackupStateCreateError, "Create failed on HealthCheck with error: %s", err.Error()),
cleanStatusJob(),
updateStatusAvailable(false),
addBackOff(backup.Spec),
)
}

if features.AsyncBackupCreation().Enabled() {
return asyncBackup(client, backup)
} else {
Expand Down
26 changes: 25 additions & 1 deletion pkg/handlers/backup/state_create_test.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -153,6 +153,30 @@ func Test_State_Create_Upload(t *testing.T) {
compareBackupMeta(t, backupMeta, newObj)
}

func Test_State_Create_CreateError_Health(t *testing.T) {
*features.AsyncBackupCreation().EnabledPointer() = false

// Arrange
handler, _ := newErrorsFakeHandler(mockErrorsArangoClientBackup{
healthCheckError: newFatalErrorf("error"),
})

obj, deployment := newObjectSet(t, backupApi.ArangoBackupStateCreate)

// 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.ArangoBackupStateCreateError)
require.Equal(t, newObj.Status.Message, "Create failed on HealthCheck with error: error")
require.Nil(t, newObj.Status.Backup)
require.False(t, newObj.Status.Available)
}

func Test_State_Create_CreateError(t *testing.T) {
*features.AsyncBackupCreation().EnabledPointer() = false

Expand Down

0 comments on commit 1a2097c

Please sign in to comment.