Skip to content

Commit be5a2a8

Browse files
authored
CLOUDP-159055: Support copySettings field for BackupSchedule (#870)
Support copySettings for backupSchedule
1 parent 558a5a6 commit be5a2a8

13 files changed

+512
-33
lines changed

config/crd/bases/atlas.mongodb.com_atlasbackupschedules.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,41 @@ spec:
4242
snapshots to the AWS bucket. You must also define the export policy
4343
using export. If omitted, defaults to false.
4444
type: boolean
45+
copySettings:
46+
description: Copy backups to other regions for increased resiliency
47+
and faster restores.
48+
items:
49+
properties:
50+
cloudProvider:
51+
default: AWS
52+
description: Identifies the cloud provider that stores the snapshot
53+
copy.
54+
enum:
55+
- AWS
56+
- GCP
57+
- AZURE
58+
type: string
59+
frequencies:
60+
description: List that describes which types of snapshots to
61+
copy.
62+
items:
63+
type: string
64+
minItems: 1
65+
type: array
66+
regionName:
67+
description: Target region to copy snapshots belonging to replicationSpecId
68+
to.
69+
type: string
70+
replicationSpecId:
71+
description: Unique identifier that identifies the replication
72+
object for a zone in a cluster.
73+
type: string
74+
shouldCopyOplogs:
75+
description: Flag that indicates whether to copy the oplogs
76+
to the target region.
77+
type: boolean
78+
type: object
79+
type: array
4580
export:
4681
description: Export policy for automatically exporting cloud backup
4782
snapshots to AWS bucket.

config/crd/bases/atlas.mongodb.com_atlasdeployments.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,17 @@ spec:
917917
reconciliation of the resource.
918918
format: int64
919919
type: integer
920+
replicaSets:
921+
items:
922+
properties:
923+
id:
924+
type: string
925+
zoneName:
926+
type: string
927+
required:
928+
- id
929+
type: object
930+
type: array
920931
serverlessPrivateEndpoints:
921932
items:
922933
properties:

config/samples/atlas_v1_atlasbackuppolicy.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ kind: AtlasBackupPolicy
33
metadata:
44
name: atlasbackuppolicy-sample
55
spec:
6-
id: "1"
76
items:
8-
- id: "2"
9-
frequencyType: "WEEKLY"
10-
frequencyInterval: 6
11-
retentionUnit: "DAYS"
12-
retentionValue: 6
7+
- frequencyType: daily
8+
frequencyInterval: 3
9+
retentionUnit: weeks
10+
retentionValue: 2

config/samples/atlas_v1_atlasbackupschedule.yaml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@ kind: AtlasBackupSchedule
33
metadata:
44
name: atlasbackupschedule-sample
55
spec:
6-
autoExportEnabled: true
6+
autoExportEnabled: false
77
referenceHourOfDay: 10
88
referenceMinuteOfHour: 10
99
restoreWindowDays: 2
10-
policies:
11-
- name: atlas-default-backuppolicy
12-
namespace: mongodb-atlas-system
13-
- name: atlas-default-backuppolicy2
14-
namespace: mongodb-atlas-system
10+
copySettings:
11+
- regionName: US_WEST_1
12+
cloudProvider: AWS
13+
replicationSpecId: a1b2c3
14+
shouldCopyOplogs: false
15+
frequencies:
16+
- WEEKLY
17+
useOrgAndGroupNamesInExportPrefix: true
18+
policy:
19+
name: atlasbackuppolicy-sample
1520

pkg/api/v1/atlasbackupschedule_types.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ type AtlasBackupScheduleSpec struct {
5454
// Specify true to use organization and project names instead of organization and project UUIDs in the path for the metadata files that Atlas uploads to your S3 bucket after it finishes exporting the snapshots
5555
// +optional
5656
UseOrgAndGroupNamesInExportPrefix bool `json:"useOrgAndGroupNamesInExportPrefix,omitempty"`
57+
58+
// Copy backups to other regions for increased resiliency and faster restores.
59+
// +optional
60+
CopySettings []CopySetting `json:"copySettings,omitempty"`
5761
}
5862

5963
type AtlasBackupExportSpec struct {
@@ -64,6 +68,22 @@ type AtlasBackupExportSpec struct {
6468
FrequencyType string `json:"frequencyType"`
6569
}
6670

71+
type CopySetting struct {
72+
// Identifies the cloud provider that stores the snapshot copy.
73+
// +kubebuilder:validation:Enum:=AWS;GCP;AZURE
74+
// +kubebuilder:default:=AWS
75+
CloudProvider *string `json:"cloudProvider,omitempty"`
76+
// Target region to copy snapshots belonging to replicationSpecId to.
77+
RegionName *string `json:"regionName,omitempty"`
78+
// Unique identifier that identifies the replication object for a zone in a cluster.
79+
ReplicationSpecID *string `json:"replicationSpecId,omitempty"`
80+
// Flag that indicates whether to copy the oplogs to the target region.
81+
ShouldCopyOplogs *bool `json:"shouldCopyOplogs,omitempty"`
82+
// List that describes which types of snapshots to copy.
83+
// +kubebuilder:validation:MinItems=1
84+
Frequencies []string `json:"frequencies,omitempty"`
85+
}
86+
6787
// AtlasBackupSchedule is the Schema for the atlasbackupschedules API
6888
// +kubebuilder:object:root=true
6989
// +kubebuilder:subresource:status

pkg/api/v1/status/atlasdeployment.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ type AtlasDeploymentStatus struct {
2020
// ConnectionStrings is a set of connection strings that your applications use to connect to this cluster.
2121
ConnectionStrings *ConnectionStrings `json:"connectionStrings,omitempty"`
2222

23+
ReplicaSets []ReplicaSet `json:"replicaSets,omitempty"`
24+
2325
ServerlessPrivateEndpoints []ServerlessPrivateEndpoint `json:"serverlessPrivateEndpoints,omitempty"`
2426

2527
CustomZoneMapping *CustomZoneMapping `json:"customZoneMapping,omitempty"`
@@ -40,6 +42,11 @@ const (
4042
StateREPAIRING = "REPAIRING"
4143
)
4244

45+
type ReplicaSet struct {
46+
ID string `json:"id"`
47+
ZoneName string `json:"zoneName,omitempty"`
48+
}
49+
4350
// ConnectionStrings contains configuration for applications use to connect to this cluster
4451
type ConnectionStrings struct {
4552
// Public mongodb:// connection string for this cluster.
@@ -114,6 +121,12 @@ func AtlasDeploymentStateNameOption(stateName string) AtlasDeploymentStatusOptio
114121
}
115122
}
116123

124+
func AtlasDeploymentReplicaSet(replicas []ReplicaSet) AtlasDeploymentStatusOption {
125+
return func(s *AtlasDeploymentStatus) {
126+
s.ReplicaSets = replicas
127+
}
128+
}
129+
117130
func AtlasDeploymentSPEOption(pe []ServerlessPrivateEndpoint) AtlasDeploymentStatusOption {
118131
return func(s *AtlasDeploymentStatus) {
119132
s.ServerlessPrivateEndpoints = pe

pkg/api/v1/status/zz_generated.deepcopy.go

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

pkg/api/v1/zz_generated.deepcopy.go

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

pkg/controller/atlasdeployment/atlasdeployment_controller.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,19 @@ func (r *AtlasDeploymentReconciler) handleAdvancedDeployment(ctx *workflow.Conte
258258
return result, nil
259259
}
260260

261+
replicaSetStatus := make([]status.ReplicaSet, 0, len(deployment.Spec.AdvancedDeploymentSpec.ReplicationSpecs))
262+
for _, replicaSet := range c.ReplicationSpecs {
263+
replicaSetStatus = append(
264+
replicaSetStatus,
265+
status.ReplicaSet{
266+
ID: replicaSet.ID,
267+
ZoneName: replicaSet.ZoneName,
268+
},
269+
)
270+
}
271+
272+
ctx.EnsureStatusOption(status.AtlasDeploymentReplicaSet(replicaSetStatus))
273+
261274
backupEnabled := false
262275
if c.BackupEnabled != nil {
263276
backupEnabled = *c.BackupEnabled
@@ -266,8 +279,7 @@ func (r *AtlasDeploymentReconciler) handleAdvancedDeployment(ctx *workflow.Conte
266279
if err := r.ensureBackupScheduleAndPolicy(
267280
context.Background(),
268281
ctx, project.ID(),
269-
c.Name,
270-
*deployment.Spec.BackupScheduleRef.GetObject(deployment.Namespace),
282+
deployment,
271283
backupEnabled,
272284
req.NamespacedName,
273285
); err != nil {
@@ -306,6 +318,19 @@ func (r *AtlasDeploymentReconciler) handleRegularDeployment(ctx *workflow.Contex
306318
return result, nil
307319
}
308320

321+
replicaSetStatus := make([]status.ReplicaSet, 0, len(deployment.Spec.DeploymentSpec.ReplicationSpecs))
322+
for _, replicaSet := range atlasDeployment.ReplicationSpecs {
323+
replicaSetStatus = append(
324+
replicaSetStatus,
325+
status.ReplicaSet{
326+
ID: replicaSet.ID,
327+
ZoneName: replicaSet.ZoneName,
328+
},
329+
)
330+
}
331+
332+
ctx.EnsureStatusOption(status.AtlasDeploymentReplicaSet(replicaSetStatus))
333+
309334
backupEnabled := false
310335
providerBackupEnabled := false
311336
if atlasDeployment.ProviderBackupEnabled != nil {
@@ -319,8 +344,7 @@ func (r *AtlasDeploymentReconciler) handleRegularDeployment(ctx *workflow.Contex
319344
context.Background(),
320345
ctx,
321346
project.ID(),
322-
atlasDeployment.Name,
323-
*deployment.Spec.BackupScheduleRef.GetObject(deployment.Namespace),
347+
deployment,
324348
providerBackupEnabled || backupEnabled,
325349
req.NamespacedName,
326350
); err != nil {

0 commit comments

Comments
 (0)