1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

[Bugfix] Check Connection to the ArangoDB before creating Backup (#1609)

This commit is contained in:
Adam Janikowski 2024-03-05 13:24:52 +01:00 committed by GitHub
parent a29ef01ced
commit 1a2097c5c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 52 additions and 4 deletions

View file

@ -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

View file

@ -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.
@ -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)
}

View file

@ -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
}

View file

@ -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 {
@ -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))

View file

@ -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.
@ -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 {

View file

@ -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.
@ -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