Skip to content

Commit d3f0ace

Browse files
authored
CLOUDP-152571: Add and handle finalizer for backup schedule and policy (#836)
Add and handle finalizer for backup schedule and policy
1 parent 3f2a47a commit d3f0ace

13 files changed

+551
-148
lines changed

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,51 @@ spec:
109109
- items
110110
type: object
111111
status:
112+
properties:
113+
backupScheduleIDs:
114+
description: DeploymentID of the deployment using the backup policy
115+
items:
116+
type: string
117+
type: array
118+
conditions:
119+
description: Conditions is the list of statuses showing the current
120+
state of the Atlas Custom Resource
121+
items:
122+
description: Condition describes the state of an Atlas Custom Resource
123+
at a certain point.
124+
properties:
125+
lastTransitionTime:
126+
description: Last time the condition transitioned from one status
127+
to another.
128+
format: date-time
129+
type: string
130+
message:
131+
description: A human readable message indicating details about
132+
the transition.
133+
type: string
134+
reason:
135+
description: The reason for the condition's last transition.
136+
type: string
137+
status:
138+
description: Status of the condition, one of True, False, Unknown.
139+
type: string
140+
type:
141+
description: Type of Atlas Custom Resource condition.
142+
type: string
143+
required:
144+
- status
145+
- type
146+
type: object
147+
type: array
148+
observedGeneration:
149+
description: ObservedGeneration indicates the generation of the resource
150+
specification that the Atlas Operator is aware of. The Atlas Operator
151+
updates this field to the 'metadata.generation' as soon as it starts
152+
reconciliation of the resource.
153+
format: int64
154+
type: integer
155+
required:
156+
- conditions
112157
type: object
113158
type: object
114159
served: true

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,50 @@ spec:
108108
- policy
109109
type: object
110110
status:
111+
properties:
112+
conditions:
113+
description: Conditions is the list of statuses showing the current
114+
state of the Atlas Custom Resource
115+
items:
116+
description: Condition describes the state of an Atlas Custom Resource
117+
at a certain point.
118+
properties:
119+
lastTransitionTime:
120+
description: Last time the condition transitioned from one status
121+
to another.
122+
format: date-time
123+
type: string
124+
message:
125+
description: A human readable message indicating details about
126+
the transition.
127+
type: string
128+
reason:
129+
description: The reason for the condition's last transition.
130+
type: string
131+
status:
132+
description: Status of the condition, one of True, False, Unknown.
133+
type: string
134+
type:
135+
description: Type of Atlas Custom Resource condition.
136+
type: string
137+
required:
138+
- status
139+
- type
140+
type: object
141+
type: array
142+
deploymentID:
143+
items:
144+
type: string
145+
type: array
146+
observedGeneration:
147+
description: ObservedGeneration indicates the generation of the resource
148+
specification that the Atlas Operator is aware of. The Atlas Operator
149+
updates this field to the 'metadata.generation' as soon as it starts
150+
reconciliation of the resource.
151+
format: int64
152+
type: integer
153+
required:
154+
- conditions
111155
type: object
112156
type: object
113157
served: true

pkg/api/v1/atlasbackuppolicy_types.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,23 @@ type AtlasBackupPolicy struct {
4545
metav1.TypeMeta `json:",inline"`
4646
metav1.ObjectMeta `json:"metadata,omitempty"`
4747

48-
Spec AtlasBackupPolicySpec `json:"spec,omitempty"`
49-
Status AtlasBackupPolicyStatus `json:"status,omitempty"`
48+
Spec AtlasBackupPolicySpec `json:"spec,omitempty"`
49+
Status status.BackupPolicyStatus `json:"status,omitempty"`
5050
}
5151

5252
func (in *AtlasBackupPolicy) GetStatus() status.Status {
53-
return nil
53+
return in.Status
5454
}
5555

56-
func (in *AtlasBackupPolicy) UpdateStatus(_ []status.Condition, _ ...status.Option) {
57-
}
56+
func (in *AtlasBackupPolicy) UpdateStatus(conditions []status.Condition, options ...status.Option) {
57+
in.Status.Conditions = conditions
58+
in.Status.ObservedGeneration = in.ObjectMeta.Generation
5859

59-
type AtlasBackupPolicyStatus struct {
60+
for _, o := range options {
61+
// This will fail if the Option passed is incorrect - which is expected
62+
v := o.(status.AtlasBackupPolicyStatusOption)
63+
v(&in.Status)
64+
}
6065
}
6166

6267
//+kubebuilder:object:root=true

pkg/api/v1/atlasbackupschedule_types.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,22 @@ type AtlasBackupSchedule struct {
7373

7474
Spec AtlasBackupScheduleSpec `json:"spec,omitempty"`
7575

76-
Status AtlasBackupScheduleStatus `json:"status,omitempty"`
76+
Status status.BackupScheduleStatus `json:"status,omitempty"`
7777
}
7878

7979
func (in *AtlasBackupSchedule) GetStatus() status.Status {
80-
return nil
80+
return in.Status
8181
}
8282

83-
func (in *AtlasBackupSchedule) UpdateStatus(_ []status.Condition, _ ...status.Option) {
84-
}
83+
func (in *AtlasBackupSchedule) UpdateStatus(conditions []status.Condition, options ...status.Option) {
84+
in.Status.Conditions = conditions
85+
in.Status.ObservedGeneration = in.ObjectMeta.Generation
8586

86-
type AtlasBackupScheduleStatus struct {
87+
for _, o := range options {
88+
// This will fail if the Option passed is incorrect - which is expected
89+
v := o.(status.AtlasBackupScheduleStatusOption)
90+
v(&in.Status)
91+
}
8792
}
8893

8994
//+kubebuilder:object:root=true

pkg/api/v1/status/backuppolicy.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package status
2+
3+
import "github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/collection"
4+
5+
// +k8s:deepcopy-gen=false
6+
7+
// AtlasBackupPolicyStatusOption is the option that is applied to AtlasBackupPolicy Status
8+
type AtlasBackupPolicyStatusOption func(s *BackupPolicyStatus)
9+
10+
func AtlasBackupPolicySetScheduleID(ID string) AtlasBackupPolicyStatusOption {
11+
return func(s *BackupPolicyStatus) {
12+
IDs := collection.CopyWithSkip(s.BackupScheduleIDs, ID)
13+
IDs = append(IDs, ID)
14+
15+
s.BackupScheduleIDs = IDs
16+
}
17+
}
18+
19+
func AtlasBackupPolicyUnsetScheduleID(ID string) AtlasBackupPolicyStatusOption {
20+
return func(s *BackupPolicyStatus) {
21+
s.BackupScheduleIDs = collection.CopyWithSkip(s.BackupScheduleIDs, ID)
22+
}
23+
}
24+
25+
type BackupPolicyStatus struct {
26+
Common `json:",inline"`
27+
28+
// DeploymentID of the deployment using the backup policy
29+
BackupScheduleIDs []string `json:"backupScheduleIDs,omitempty"`
30+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package status
2+
3+
import "github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/collection"
4+
5+
// +k8s:deepcopy-gen=false
6+
7+
// AtlasBackupScheduleStatusOption is the option that is applied to AtlasBackupSchedule Status
8+
type AtlasBackupScheduleStatusOption func(s *BackupScheduleStatus)
9+
10+
func AtlasBackupScheduleSetDeploymentID(ID string) AtlasBackupScheduleStatusOption {
11+
return func(s *BackupScheduleStatus) {
12+
IDs := collection.CopyWithSkip(s.DeploymentIDs, ID)
13+
IDs = append(IDs, ID)
14+
15+
s.DeploymentIDs = IDs
16+
}
17+
}
18+
19+
func AtlasBackupScheduleUnsetDeploymentID(ID string) AtlasBackupScheduleStatusOption {
20+
return func(s *BackupScheduleStatus) {
21+
s.DeploymentIDs = collection.CopyWithSkip(s.DeploymentIDs, ID)
22+
}
23+
}
24+
25+
type BackupScheduleStatus struct {
26+
Common `json:",inline"`
27+
28+
DeploymentIDs []string `json:"deploymentID,omitempty"`
29+
}

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

Lines changed: 42 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: 2 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)