Skip to content

Commit 653fe72

Browse files
GT-562 AutoDelete for ArangoBackup (#1583)
Co-authored-by: Nikita Vaniasin <nikita.vanyasin@gmail.com>
1 parent b628897 commit 653fe72

10 files changed

+110
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- (Maintenance) Bump Go to 1.21.6
1212
- (Bugfix) Enable LazyLoader for CRD & CRD Schemas
1313
- (Feature) (ML) Restore ReadinessProbe for ML Storage sidecar
14+
- (Feature) AutoDelete for ArangoBackup
1415

1516
## [1.2.36](https://github.com/arangodb/kube-arangodb/tree/1.2.36) (2024-01-08)
1617
- (Documentation) Improvements and fixes for rendered documentation (GH pages)

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ endif
4949
TEST_BUILD ?= 0
5050
GOBUILDARGS ?=
5151
GOBASEVERSION := 1.21.6
52-
GOVERSION := $(GOBASEVERSION)-alpine3.17
52+
GOVERSION := $(GOBASEVERSION)-alpine3.18
5353
DISTRIBUTION := alpine:3.15
5454
GOCOMPAT := $(shell sed -En 's/^go (.*)$$/\1/p' go.mod)
5555

docs/api/ArangoBackup.V1.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ This field is **immutable**: can't be changed after backup creation
5050

5151
***
5252

53+
### .spec.download.autoDelete
54+
55+
Type: `boolean` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.36/pkg/apis/backup/v1/backup_spec.go#L84)</sup>
56+
57+
AutoDelete removes the ArangoBackup resource (which removes the backup from the cluster) after successful upload
58+
59+
Default Value: `false`
60+
61+
***
62+
5363
### .spec.download.credentialsSecretName
5464

5565
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
6575

6676
### .spec.download.id
6777

68-
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.36/pkg/apis/backup/v1/backup_spec.go#L89)</sup>
78+
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.36/pkg/apis/backup/v1/backup_spec.go#L92)</sup>
6979

7080
ID of the ArangoBackup to be downloaded
7181

@@ -137,6 +147,16 @@ This field is **immutable**: can't be changed after backup creation
137147

138148
***
139149

150+
### .spec.upload.autoDelete
151+
152+
Type: `boolean` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.36/pkg/apis/backup/v1/backup_spec.go#L84)</sup>
153+
154+
AutoDelete removes the ArangoBackup resource (which removes the backup from the cluster) after successful upload
155+
156+
Default Value: `false`
157+
158+
***
159+
140160
### .spec.upload.credentialsSecretName
141161

142162
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.36/pkg/apis/backup/v1/backup_spec.go#L81)</sup>

docs/api/ArangoBackupPolicy.V1.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ This field is **immutable**: can't be changed after backup creation
114114

115115
***
116116

117+
### .spec.template.upload.autoDelete
118+
119+
Type: `boolean` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.36/pkg/apis/backup/v1/backup_spec.go#L84)</sup>
120+
121+
AutoDelete removes the ArangoBackup resource (which removes the backup from the cluster) after successful upload
122+
123+
Default Value: `false`
124+
125+
***
126+
117127
### .spec.template.upload.credentialsSecretName
118128

119129
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.36/pkg/apis/backup/v1/backup_spec.go#L81)</sup>

pkg/apis/backup/v1/backup_spec.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ type ArangoBackupSpecOperation struct {
7979
// +doc/immutable: can't be changed after backup creation
8080
// +doc/link: Defining a secret for backup upload or download|../backup-resource.md#defining-a-secret-for-backup-upload-or-download
8181
CredentialsSecretName string `json:"credentialsSecretName,omitempty"`
82+
// AutoDelete removes the ArangoBackup resource (which removes the backup from the cluster) after successful upload
83+
// +doc/default: false
84+
AutoDelete *bool `json:"autoDelete,omitempty"`
8285
}
8386

8487
type ArangoBackupSpecDownload struct {

pkg/apis/backup/v1/zz_generated.deepcopy.go

Lines changed: 9 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/crd/crds/backups-backup.schema.generated.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ v1:
3232
download:
3333
description: Download Backup download settings
3434
properties:
35+
autoDelete:
36+
description: AutoDelete removes the ArangoBackup resource (which removes the backup from the cluster) after successful upload
37+
type: boolean
3538
credentialsSecretName:
3639
description: CredentialsSecretName is the name of the secret used while accessing repository
3740
type: string
@@ -69,6 +72,9 @@ v1:
6972
Upload Backup upload settings.
7073
This field can be removed and created again with different values. This operation will trigger upload again.
7174
properties:
75+
autoDelete:
76+
description: AutoDelete removes the ArangoBackup resource (which removes the backup from the cluster) after successful upload
77+
type: boolean
7278
credentialsSecretName:
7379
description: CredentialsSecretName is the name of the secret used while accessing repository
7480
type: string
@@ -116,6 +122,9 @@ v1alpha:
116122
download:
117123
description: Download Backup download settings
118124
properties:
125+
autoDelete:
126+
description: AutoDelete removes the ArangoBackup resource (which removes the backup from the cluster) after successful upload
127+
type: boolean
119128
credentialsSecretName:
120129
description: CredentialsSecretName is the name of the secret used while accessing repository
121130
type: string
@@ -153,6 +162,9 @@ v1alpha:
153162
Upload Backup upload settings.
154163
This field can be removed and created again with different values. This operation will trigger upload again.
155164
properties:
165+
autoDelete:
166+
description: AutoDelete removes the ArangoBackup resource (which removes the backup from the cluster) after successful upload
167+
type: boolean
156168
credentialsSecretName:
157169
description: CredentialsSecretName is the name of the secret used while accessing repository
158170
type: string

pkg/crd/crds/backups-backuppolicy.schema.generated.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ v1:
7777
type: object
7878
upload:
7979
properties:
80+
autoDelete:
81+
description: AutoDelete removes the ArangoBackup resource (which removes the backup from the cluster) after successful upload
82+
type: boolean
8083
credentialsSecretName:
8184
description: CredentialsSecretName is the name of the secret used while accessing repository
8285
type: string
@@ -170,6 +173,9 @@ v1alpha:
170173
type: object
171174
upload:
172175
properties:
176+
autoDelete:
177+
description: AutoDelete removes the ArangoBackup resource (which removes the backup from the cluster) after successful upload
178+
type: boolean
173179
credentialsSecretName:
174180
description: CredentialsSecretName is the name of the secret used while accessing repository
175181
type: string

pkg/handlers/backup/state_ready.go

Lines changed: 13 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.
@@ -21,8 +21,11 @@
2121
package backup
2222

2323
import (
24+
"context"
2425
"time"
2526

27+
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
28+
2629
"github.com/arangodb/go-driver"
2730

2831
backupApi "github.com/arangodb/kube-arangodb/pkg/apis/backup/v1"
@@ -130,6 +133,15 @@ func stateReadyHandler(h *handler, backup *backupApi.ArangoBackup) (*backupApi.A
130133
)
131134
}
132135

136+
// handle AutoDelete case
137+
if backup.Spec.Upload != nil && backup.Spec.Upload.AutoDelete != nil && *backup.Spec.Upload.AutoDelete {
138+
err := h.client.BackupV1().ArangoBackups(backup.Namespace).Delete(context.Background(), backup.Name, meta.DeleteOptions{})
139+
if err != nil {
140+
return nil, err
141+
}
142+
return wrapUpdateStatus(backup)
143+
}
144+
133145
return wrapUpdateStatus(backup,
134146
updateStatusBackup(backupMeta),
135147
updateStatusAvailable(true),

pkg/handlers/backup/state_ready_test.go

Lines changed: 34 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.
@@ -27,6 +27,7 @@ import (
2727
"time"
2828

2929
"github.com/stretchr/testify/require"
30+
apiErrors "k8s.io/apimachinery/pkg/api/errors"
3031
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
3132
"k8s.io/apimachinery/pkg/util/uuid"
3233

@@ -317,6 +318,38 @@ func Test_State_Ready_Upload(t *testing.T) {
317318
compareBackupMeta(t, backupMeta, newObj)
318319
}
319320

321+
func Test_State_Ready_Upload_AutoDelete(t *testing.T) {
322+
// Arrange
323+
handler, mock := newErrorsFakeHandler(mockErrorsArangoClientBackup{})
324+
325+
obj, deployment := newObjectSet(t, backupApi.ArangoBackupStateReady)
326+
obj.Spec.Upload = &backupApi.ArangoBackupSpecOperation{
327+
RepositoryURL: "Any",
328+
AutoDelete: util.NewType[bool](true),
329+
}
330+
331+
createResponse, err := mock.Create()
332+
require.NoError(t, err)
333+
334+
backupMeta, err := mock.Get(createResponse.ID)
335+
require.NoError(t, err)
336+
337+
obj.Status.Backup = createBackupFromMeta(backupMeta, &backupApi.ArangoBackupDetails{
338+
Uploaded: util.NewType[bool](true),
339+
})
340+
341+
// Act
342+
createArangoDeployment(t, handler, deployment)
343+
createArangoBackup(t, handler, obj)
344+
345+
require.NoError(t, handler.Handle(context.Background(), tests.NewItem(t, operation.Update, obj)))
346+
347+
// Assert
348+
_, err = handler.client.BackupV1().ArangoBackups(obj.Namespace).Get(context.Background(), obj.Name, meta.GetOptions{})
349+
require.Error(t, err)
350+
require.True(t, apiErrors.IsNotFound(err))
351+
}
352+
320353
func Test_State_Ready_DownloadDoNothing(t *testing.T) {
321354
// Arrange
322355
handler, mock := newErrorsFakeHandler(mockErrorsArangoClientBackup{})

0 commit comments

Comments
 (0)