mirror of
https://github.com/arangodb/kube-arangodb.git
synced 2024-12-14 11:57:37 +00:00
GT-562 AutoDelete for ArangoBackup (#1583)
Co-authored-by: Nikita Vaniasin <nikita.vanyasin@gmail.com>
This commit is contained in:
parent
b6288974d9
commit
653fe729db
10 changed files with 110 additions and 8 deletions
|
@ -11,6 +11,7 @@
|
||||||
- (Maintenance) Bump Go to 1.21.6
|
- (Maintenance) Bump Go to 1.21.6
|
||||||
- (Bugfix) Enable LazyLoader for CRD & CRD Schemas
|
- (Bugfix) Enable LazyLoader for CRD & CRD Schemas
|
||||||
- (Feature) (ML) Restore ReadinessProbe for ML Storage sidecar
|
- (Feature) (ML) Restore ReadinessProbe for ML Storage sidecar
|
||||||
|
- (Feature) AutoDelete for ArangoBackup
|
||||||
|
|
||||||
## [1.2.36](https://github.com/arangodb/kube-arangodb/tree/1.2.36) (2024-01-08)
|
## [1.2.36](https://github.com/arangodb/kube-arangodb/tree/1.2.36) (2024-01-08)
|
||||||
- (Documentation) Improvements and fixes for rendered documentation (GH pages)
|
- (Documentation) Improvements and fixes for rendered documentation (GH pages)
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -49,7 +49,7 @@ endif
|
||||||
TEST_BUILD ?= 0
|
TEST_BUILD ?= 0
|
||||||
GOBUILDARGS ?=
|
GOBUILDARGS ?=
|
||||||
GOBASEVERSION := 1.21.6
|
GOBASEVERSION := 1.21.6
|
||||||
GOVERSION := $(GOBASEVERSION)-alpine3.17
|
GOVERSION := $(GOBASEVERSION)-alpine3.18
|
||||||
DISTRIBUTION := alpine:3.15
|
DISTRIBUTION := alpine:3.15
|
||||||
GOCOMPAT := $(shell sed -En 's/^go (.*)$$/\1/p' go.mod)
|
GOCOMPAT := $(shell sed -En 's/^go (.*)$$/\1/p' go.mod)
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,16 @@ This field is **immutable**: can't be changed after backup creation
|
||||||
|
|
||||||
***
|
***
|
||||||
|
|
||||||
|
### .spec.download.autoDelete
|
||||||
|
|
||||||
|
Type: `boolean` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.36/pkg/apis/backup/v1/backup_spec.go#L84)</sup>
|
||||||
|
|
||||||
|
AutoDelete removes the ArangoBackup resource (which removes the backup from the cluster) after successful upload
|
||||||
|
|
||||||
|
Default Value: `false`
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
### .spec.download.credentialsSecretName
|
### .spec.download.credentialsSecretName
|
||||||
|
|
||||||
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.36/pkg/apis/backup/v1/backup_spec.go#L81)</sup>
|
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.36/pkg/apis/backup/v1/backup_spec.go#L81)</sup>
|
||||||
|
@ -65,7 +75,7 @@ This field is **immutable**: can't be changed after backup creation
|
||||||
|
|
||||||
### .spec.download.id
|
### .spec.download.id
|
||||||
|
|
||||||
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.36/pkg/apis/backup/v1/backup_spec.go#L89)</sup>
|
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.36/pkg/apis/backup/v1/backup_spec.go#L92)</sup>
|
||||||
|
|
||||||
ID of the ArangoBackup to be downloaded
|
ID of the ArangoBackup to be downloaded
|
||||||
|
|
||||||
|
@ -137,6 +147,16 @@ This field is **immutable**: can't be changed after backup creation
|
||||||
|
|
||||||
***
|
***
|
||||||
|
|
||||||
|
### .spec.upload.autoDelete
|
||||||
|
|
||||||
|
Type: `boolean` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.36/pkg/apis/backup/v1/backup_spec.go#L84)</sup>
|
||||||
|
|
||||||
|
AutoDelete removes the ArangoBackup resource (which removes the backup from the cluster) after successful upload
|
||||||
|
|
||||||
|
Default Value: `false`
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
### .spec.upload.credentialsSecretName
|
### .spec.upload.credentialsSecretName
|
||||||
|
|
||||||
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.36/pkg/apis/backup/v1/backup_spec.go#L81)</sup>
|
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.36/pkg/apis/backup/v1/backup_spec.go#L81)</sup>
|
||||||
|
|
|
@ -114,6 +114,16 @@ This field is **immutable**: can't be changed after backup creation
|
||||||
|
|
||||||
***
|
***
|
||||||
|
|
||||||
|
### .spec.template.upload.autoDelete
|
||||||
|
|
||||||
|
Type: `boolean` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.36/pkg/apis/backup/v1/backup_spec.go#L84)</sup>
|
||||||
|
|
||||||
|
AutoDelete removes the ArangoBackup resource (which removes the backup from the cluster) after successful upload
|
||||||
|
|
||||||
|
Default Value: `false`
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
### .spec.template.upload.credentialsSecretName
|
### .spec.template.upload.credentialsSecretName
|
||||||
|
|
||||||
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.36/pkg/apis/backup/v1/backup_spec.go#L81)</sup>
|
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.36/pkg/apis/backup/v1/backup_spec.go#L81)</sup>
|
||||||
|
|
|
@ -79,6 +79,9 @@ type ArangoBackupSpecOperation struct {
|
||||||
// +doc/immutable: can't be changed after backup creation
|
// +doc/immutable: can't be changed after backup creation
|
||||||
// +doc/link: Defining a secret for backup upload or download|../backup-resource.md#defining-a-secret-for-backup-upload-or-download
|
// +doc/link: Defining a secret for backup upload or download|../backup-resource.md#defining-a-secret-for-backup-upload-or-download
|
||||||
CredentialsSecretName string `json:"credentialsSecretName,omitempty"`
|
CredentialsSecretName string `json:"credentialsSecretName,omitempty"`
|
||||||
|
// AutoDelete removes the ArangoBackup resource (which removes the backup from the cluster) after successful upload
|
||||||
|
// +doc/default: false
|
||||||
|
AutoDelete *bool `json:"autoDelete,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArangoBackupSpecDownload struct {
|
type ArangoBackupSpecDownload struct {
|
||||||
|
|
13
pkg/apis/backup/v1/zz_generated.deepcopy.go
generated
13
pkg/apis/backup/v1/zz_generated.deepcopy.go
generated
|
@ -267,12 +267,12 @@ func (in *ArangoBackupSpec) DeepCopyInto(out *ArangoBackupSpec) {
|
||||||
if in.Download != nil {
|
if in.Download != nil {
|
||||||
in, out := &in.Download, &out.Download
|
in, out := &in.Download, &out.Download
|
||||||
*out = new(ArangoBackupSpecDownload)
|
*out = new(ArangoBackupSpecDownload)
|
||||||
**out = **in
|
(*in).DeepCopyInto(*out)
|
||||||
}
|
}
|
||||||
if in.Upload != nil {
|
if in.Upload != nil {
|
||||||
in, out := &in.Upload, &out.Upload
|
in, out := &in.Upload, &out.Upload
|
||||||
*out = new(ArangoBackupSpecOperation)
|
*out = new(ArangoBackupSpecOperation)
|
||||||
**out = **in
|
(*in).DeepCopyInto(*out)
|
||||||
}
|
}
|
||||||
if in.PolicyName != nil {
|
if in.PolicyName != nil {
|
||||||
in, out := &in.PolicyName, &out.PolicyName
|
in, out := &in.PolicyName, &out.PolicyName
|
||||||
|
@ -357,7 +357,7 @@ func (in *ArangoBackupSpecDeployment) DeepCopy() *ArangoBackupSpecDeployment {
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
func (in *ArangoBackupSpecDownload) DeepCopyInto(out *ArangoBackupSpecDownload) {
|
func (in *ArangoBackupSpecDownload) DeepCopyInto(out *ArangoBackupSpecDownload) {
|
||||||
*out = *in
|
*out = *in
|
||||||
out.ArangoBackupSpecOperation = in.ArangoBackupSpecOperation
|
in.ArangoBackupSpecOperation.DeepCopyInto(&out.ArangoBackupSpecOperation)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,6 +374,11 @@ func (in *ArangoBackupSpecDownload) DeepCopy() *ArangoBackupSpecDownload {
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||||
func (in *ArangoBackupSpecOperation) DeepCopyInto(out *ArangoBackupSpecOperation) {
|
func (in *ArangoBackupSpecOperation) DeepCopyInto(out *ArangoBackupSpecOperation) {
|
||||||
*out = *in
|
*out = *in
|
||||||
|
if in.AutoDelete != nil {
|
||||||
|
in, out := &in.AutoDelete, &out.AutoDelete
|
||||||
|
*out = new(bool)
|
||||||
|
**out = **in
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -490,7 +495,7 @@ func (in *ArangoBackupTemplate) DeepCopyInto(out *ArangoBackupTemplate) {
|
||||||
if in.Upload != nil {
|
if in.Upload != nil {
|
||||||
in, out := &in.Upload, &out.Upload
|
in, out := &in.Upload, &out.Upload
|
||||||
*out = new(ArangoBackupSpecOperation)
|
*out = new(ArangoBackupSpecOperation)
|
||||||
**out = **in
|
(*in).DeepCopyInto(*out)
|
||||||
}
|
}
|
||||||
if in.Backoff != nil {
|
if in.Backoff != nil {
|
||||||
in, out := &in.Backoff, &out.Backoff
|
in, out := &in.Backoff, &out.Backoff
|
||||||
|
|
|
@ -32,6 +32,9 @@ v1:
|
||||||
download:
|
download:
|
||||||
description: Download Backup download settings
|
description: Download Backup download settings
|
||||||
properties:
|
properties:
|
||||||
|
autoDelete:
|
||||||
|
description: AutoDelete removes the ArangoBackup resource (which removes the backup from the cluster) after successful upload
|
||||||
|
type: boolean
|
||||||
credentialsSecretName:
|
credentialsSecretName:
|
||||||
description: CredentialsSecretName is the name of the secret used while accessing repository
|
description: CredentialsSecretName is the name of the secret used while accessing repository
|
||||||
type: string
|
type: string
|
||||||
|
@ -69,6 +72,9 @@ v1:
|
||||||
Upload Backup upload settings.
|
Upload Backup upload settings.
|
||||||
This field can be removed and created again with different values. This operation will trigger upload again.
|
This field can be removed and created again with different values. This operation will trigger upload again.
|
||||||
properties:
|
properties:
|
||||||
|
autoDelete:
|
||||||
|
description: AutoDelete removes the ArangoBackup resource (which removes the backup from the cluster) after successful upload
|
||||||
|
type: boolean
|
||||||
credentialsSecretName:
|
credentialsSecretName:
|
||||||
description: CredentialsSecretName is the name of the secret used while accessing repository
|
description: CredentialsSecretName is the name of the secret used while accessing repository
|
||||||
type: string
|
type: string
|
||||||
|
@ -116,6 +122,9 @@ v1alpha:
|
||||||
download:
|
download:
|
||||||
description: Download Backup download settings
|
description: Download Backup download settings
|
||||||
properties:
|
properties:
|
||||||
|
autoDelete:
|
||||||
|
description: AutoDelete removes the ArangoBackup resource (which removes the backup from the cluster) after successful upload
|
||||||
|
type: boolean
|
||||||
credentialsSecretName:
|
credentialsSecretName:
|
||||||
description: CredentialsSecretName is the name of the secret used while accessing repository
|
description: CredentialsSecretName is the name of the secret used while accessing repository
|
||||||
type: string
|
type: string
|
||||||
|
@ -153,6 +162,9 @@ v1alpha:
|
||||||
Upload Backup upload settings.
|
Upload Backup upload settings.
|
||||||
This field can be removed and created again with different values. This operation will trigger upload again.
|
This field can be removed and created again with different values. This operation will trigger upload again.
|
||||||
properties:
|
properties:
|
||||||
|
autoDelete:
|
||||||
|
description: AutoDelete removes the ArangoBackup resource (which removes the backup from the cluster) after successful upload
|
||||||
|
type: boolean
|
||||||
credentialsSecretName:
|
credentialsSecretName:
|
||||||
description: CredentialsSecretName is the name of the secret used while accessing repository
|
description: CredentialsSecretName is the name of the secret used while accessing repository
|
||||||
type: string
|
type: string
|
||||||
|
|
|
@ -77,6 +77,9 @@ v1:
|
||||||
type: object
|
type: object
|
||||||
upload:
|
upload:
|
||||||
properties:
|
properties:
|
||||||
|
autoDelete:
|
||||||
|
description: AutoDelete removes the ArangoBackup resource (which removes the backup from the cluster) after successful upload
|
||||||
|
type: boolean
|
||||||
credentialsSecretName:
|
credentialsSecretName:
|
||||||
description: CredentialsSecretName is the name of the secret used while accessing repository
|
description: CredentialsSecretName is the name of the secret used while accessing repository
|
||||||
type: string
|
type: string
|
||||||
|
@ -170,6 +173,9 @@ v1alpha:
|
||||||
type: object
|
type: object
|
||||||
upload:
|
upload:
|
||||||
properties:
|
properties:
|
||||||
|
autoDelete:
|
||||||
|
description: AutoDelete removes the ArangoBackup resource (which removes the backup from the cluster) after successful upload
|
||||||
|
type: boolean
|
||||||
credentialsSecretName:
|
credentialsSecretName:
|
||||||
description: CredentialsSecretName is the name of the secret used while accessing repository
|
description: CredentialsSecretName is the name of the secret used while accessing repository
|
||||||
type: string
|
type: string
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//
|
//
|
||||||
// DISCLAIMER
|
// 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");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
|
@ -21,8 +21,11 @@
|
||||||
package backup
|
package backup
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
|
||||||
"github.com/arangodb/go-driver"
|
"github.com/arangodb/go-driver"
|
||||||
|
|
||||||
backupApi "github.com/arangodb/kube-arangodb/pkg/apis/backup/v1"
|
backupApi "github.com/arangodb/kube-arangodb/pkg/apis/backup/v1"
|
||||||
|
@ -130,6 +133,15 @@ func stateReadyHandler(h *handler, backup *backupApi.ArangoBackup) (*backupApi.A
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handle AutoDelete case
|
||||||
|
if backup.Spec.Upload != nil && backup.Spec.Upload.AutoDelete != nil && *backup.Spec.Upload.AutoDelete {
|
||||||
|
err := h.client.BackupV1().ArangoBackups(backup.Namespace).Delete(context.Background(), backup.Name, meta.DeleteOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return wrapUpdateStatus(backup)
|
||||||
|
}
|
||||||
|
|
||||||
return wrapUpdateStatus(backup,
|
return wrapUpdateStatus(backup,
|
||||||
updateStatusBackup(backupMeta),
|
updateStatusBackup(backupMeta),
|
||||||
updateStatusAvailable(true),
|
updateStatusAvailable(true),
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//
|
//
|
||||||
// DISCLAIMER
|
// 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");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
|
@ -27,6 +27,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
apiErrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
|
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/util/uuid"
|
"k8s.io/apimachinery/pkg/util/uuid"
|
||||||
|
|
||||||
|
@ -317,6 +318,38 @@ func Test_State_Ready_Upload(t *testing.T) {
|
||||||
compareBackupMeta(t, backupMeta, newObj)
|
compareBackupMeta(t, backupMeta, newObj)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_State_Ready_Upload_AutoDelete(t *testing.T) {
|
||||||
|
// Arrange
|
||||||
|
handler, mock := newErrorsFakeHandler(mockErrorsArangoClientBackup{})
|
||||||
|
|
||||||
|
obj, deployment := newObjectSet(t, backupApi.ArangoBackupStateReady)
|
||||||
|
obj.Spec.Upload = &backupApi.ArangoBackupSpecOperation{
|
||||||
|
RepositoryURL: "Any",
|
||||||
|
AutoDelete: util.NewType[bool](true),
|
||||||
|
}
|
||||||
|
|
||||||
|
createResponse, err := mock.Create()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
backupMeta, err := mock.Get(createResponse.ID)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
obj.Status.Backup = createBackupFromMeta(backupMeta, &backupApi.ArangoBackupDetails{
|
||||||
|
Uploaded: util.NewType[bool](true),
|
||||||
|
})
|
||||||
|
|
||||||
|
// Act
|
||||||
|
createArangoDeployment(t, handler, deployment)
|
||||||
|
createArangoBackup(t, handler, obj)
|
||||||
|
|
||||||
|
require.NoError(t, handler.Handle(context.Background(), tests.NewItem(t, operation.Update, obj)))
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
_, err = handler.client.BackupV1().ArangoBackups(obj.Namespace).Get(context.Background(), obj.Name, meta.GetOptions{})
|
||||||
|
require.Error(t, err)
|
||||||
|
require.True(t, apiErrors.IsNotFound(err))
|
||||||
|
}
|
||||||
|
|
||||||
func Test_State_Ready_DownloadDoNothing(t *testing.T) {
|
func Test_State_Ready_DownloadDoNothing(t *testing.T) {
|
||||||
// Arrange
|
// Arrange
|
||||||
handler, mock := newErrorsFakeHandler(mockErrorsArangoClientBackup{})
|
handler, mock := newErrorsFakeHandler(mockErrorsArangoClientBackup{})
|
||||||
|
|
Loading…
Reference in a new issue