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

[Feature] Allow to abort upload (#845)

This commit is contained in:
Adam Janikowski 2021-12-04 01:13:11 +01:00 committed by GitHub
parent d93167fa0e
commit ac35757c35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 101 additions and 18 deletions

View file

@ -2,6 +2,7 @@
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
- Add ArangoBackup backoff functionality
- Allow to abort ArangoBackup uploads by removing spec.upload
## [1.2.5](https://github.com/arangodb/kube-arangodb/tree/1.2.5) (2021-10-25)
- Split & Unify Lifecycle management functionality

View file

@ -188,6 +188,13 @@ func (ac *arangoClientBackupImpl) Progress(jobID driver.BackupTransferJobID) (Ar
return ArangoBackupProgress{}, err
}
if report.Cancelled {
return ArangoBackupProgress{
Failed: true,
FailMessage: "Upload cancelled",
}, nil
}
var ret ArangoBackupProgress
var completedCount int
var total int

View file

@ -83,6 +83,20 @@ func stateUploadingHandler(h *handler, backup *backupApi.ArangoBackup) (*backupA
)
}
if backup.Spec.Upload == nil {
// Upload is canceled
if err = client.Abort(driver.BackupTransferJobID(backup.Status.Progress.JobID)); err == nil {
return wrapUpdateStatus(backup,
updateStatusState(backupApi.ArangoBackupStateReady, ""),
cleanStatusJob(),
updateStatusBackupUpload(util.NewBool(false)),
updateStatusAvailable(true),
cleanBackOff(),
)
}
}
return wrapUpdateStatus(backup,
updateStatusState(backupApi.ArangoBackupStateUploading, ""),
updateStatusAvailable(true),

View file

@ -57,6 +57,10 @@ func Test_State_Uploading_Success(t *testing.T) {
obj.Status.Backup = createBackupFromMeta(backupMeta, nil)
obj.Spec.Upload = &backupApi.ArangoBackupSpecOperation{
RepositoryURL: "S3 URL",
}
obj.Status.Progress = &backupApi.ArangoBackupProgress{
JobID: string(progress),
}
@ -162,16 +166,13 @@ func Test_StateUploading_FailedProgress(t *testing.T) {
backupMeta, err := mock.Get(createResponse.ID)
require.NoError(t, err)
progress, err := mock.Download(backupMeta.ID)
progress, err := mock.Upload(backupMeta.ID)
require.NoError(t, err)
obj.Status.Backup = createBackupFromMeta(backupMeta, nil)
obj.Spec.Download = &backupApi.ArangoBackupSpecDownload{
ArangoBackupSpecOperation: backupApi.ArangoBackupSpecOperation{
RepositoryURL: "S3 URL",
},
ID: string(backupMeta.ID),
obj.Spec.Upload = &backupApi.ArangoBackupSpecOperation{
RepositoryURL: "S3 URL",
}
obj.Status.Progress = &backupApi.ArangoBackupProgress{
@ -204,16 +205,13 @@ func Test_State_Uploading_TemporaryFailedProgress(t *testing.T) {
backupMeta, err := mock.Get(createResponse.ID)
require.NoError(t, err)
progress, err := mock.Download(backupMeta.ID)
progress, err := mock.Upload(backupMeta.ID)
require.NoError(t, err)
obj.Status.Backup = createBackupFromMeta(backupMeta, nil)
obj.Spec.Download = &backupApi.ArangoBackupSpecDownload{
ArangoBackupSpecOperation: backupApi.ArangoBackupSpecOperation{
RepositoryURL: "S3 URL",
},
ID: string(backupMeta.ID),
obj.Spec.Upload = &backupApi.ArangoBackupSpecOperation{
RepositoryURL: "S3 URL",
}
obj.Status.Progress = &backupApi.ArangoBackupProgress{
@ -248,16 +246,13 @@ func Test_State_Uploading_NotFoundProgress(t *testing.T) {
backupMeta, err := mock.Get(createResponse.ID)
require.NoError(t, err)
progress, err := mock.Download(backupMeta.ID)
progress, err := mock.Upload(backupMeta.ID)
require.NoError(t, err)
obj.Status.Backup = createBackupFromMeta(backupMeta, nil)
obj.Spec.Download = &backupApi.ArangoBackupSpecDownload{
ArangoBackupSpecOperation: backupApi.ArangoBackupSpecOperation{
RepositoryURL: "S3 URL",
},
ID: string(backupMeta.ID),
obj.Spec.Upload = &backupApi.ArangoBackupSpecOperation{
RepositoryURL: "S3 URL",
}
obj.Status.Progress = &backupApi.ArangoBackupProgress{
@ -276,3 +271,69 @@ func Test_State_Uploading_NotFoundProgress(t *testing.T) {
require.Equal(t, fmt.Sprintf("job with id %s does not exist anymore", progress), newObj.Status.Message)
require.Nil(t, newObj.Status.Progress)
}
func Test_StateUploading_Abort_Success(t *testing.T) {
// Arrange
handler, mock := newErrorsFakeHandler(mockErrorsArangoClientBackup{})
obj, deployment := newObjectSet(backupApi.ArangoBackupStateUploading)
createResponse, err := mock.Create()
require.NoError(t, err)
backupMeta, err := mock.Get(createResponse.ID)
require.NoError(t, err)
progress, err := mock.Upload(backupMeta.ID)
require.NoError(t, err)
obj.Status.Backup = createBackupFromMeta(backupMeta, nil)
obj.Status.Progress = &backupApi.ArangoBackupProgress{
JobID: string(progress),
}
// Act
createArangoDeployment(t, handler, deployment)
createArangoBackup(t, handler, obj)
require.NoError(t, handler.Handle(newItemFromBackup(operation.Update, obj)))
// Assert
newObj := refreshArangoBackup(t, handler, obj)
checkBackup(t, newObj, backupApi.ArangoBackupStateReady, true)
}
func Test_StateUploading_Abort_Fail(t *testing.T) {
// Arrange
handler, mock := newErrorsFakeHandler(mockErrorsArangoClientBackup{
abortError: newTemporaryErrorf("error"),
})
obj, deployment := newObjectSet(backupApi.ArangoBackupStateUploading)
createResponse, err := mock.Create()
require.NoError(t, err)
backupMeta, err := mock.Get(createResponse.ID)
require.NoError(t, err)
progress, err := mock.Upload(backupMeta.ID)
require.NoError(t, err)
obj.Status.Backup = createBackupFromMeta(backupMeta, nil)
obj.Status.Progress = &backupApi.ArangoBackupProgress{
JobID: string(progress),
}
// Act
createArangoDeployment(t, handler, deployment)
createArangoBackup(t, handler, obj)
require.NoError(t, handler.Handle(newItemFromBackup(operation.Update, obj)))
// Assert
newObj := refreshArangoBackup(t, handler, obj)
checkBackup(t, newObj, backupApi.ArangoBackupStateUploading, true)
}