Skip to content

Commit 06130ed

Browse files
committed
scheduledbackup
1 parent 4a72db0 commit 06130ed

14 files changed

+506
-39
lines changed

api/preview/backup_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
// BackupSpec defines the desired state of Backup.
1212
type BackupSpec struct {
1313
// Cluster specifies the DocumentDB cluster to backup.
14+
// The cluster must exist in the same namespace as the Backup resource.
15+
// +kubebuilder:validation:Required
1416
Cluster cnpgv1.LocalObjectReference `json:"cluster"`
1517
}
1618

@@ -39,8 +41,6 @@ type BackupStatus struct {
3941
// +kubebuilder:printcolumn:name="Started",type=date,JSONPath=".status.startedAt",description="Backup start time"
4042
// +kubebuilder:printcolumn:name="Stopped",type=date,JSONPath=".status.stoppedAt",description="Backup completion time"
4143
// +kubebuilder:printcolumn:name="Error",type=string,JSONPath=".status.error",description="Backup error information"
42-
43-
// Backup is the Schema for the backups API.
4444
type Backup struct {
4545
metav1.TypeMeta `json:",inline"`
4646
metav1.ObjectMeta `json:"metadata,omitempty"`
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
package preview
5+
6+
import (
7+
cnpgv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1"
8+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9+
)
10+
11+
// ScheduledBackupSpec defines the desired state of ScheduledBackup
12+
type ScheduledBackupSpec struct {
13+
// Cluster specifies the DocumentDB cluster to backup.
14+
// The cluster must exist in the same namespace as the ScheduledBackup resource.
15+
// +kubebuilder:validation:Required
16+
Cluster cnpgv1.LocalObjectReference `json:"cluster"`
17+
18+
// Schedule defines when backups should be created using cron expression format.
19+
// +kubebuilder:validation:Required
20+
Schedule string `json:"schedule"`
21+
}
22+
23+
// ScheduledBackupStatus defines the observed state of ScheduledBackup
24+
type ScheduledBackupStatus struct {
25+
}
26+
27+
// +kubebuilder:object:root=true
28+
// +kubebuilder:subresource:status
29+
// +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".spec.cluster.name"
30+
// +kubebuilder:printcolumn:name="Schedule",type="string",JSONPath=".spec.schedule"
31+
type ScheduledBackup struct {
32+
metav1.TypeMeta `json:",inline"`
33+
metav1.ObjectMeta `json:"metadata"`
34+
Spec ScheduledBackupSpec `json:"spec"`
35+
Status ScheduledBackupStatus `json:"status,omitempty"`
36+
}
37+
38+
// ScheduledBackupList contains a list of ScheduledBackup resources
39+
// +kubebuilder:object:root=true
40+
type ScheduledBackupList struct {
41+
metav1.TypeMeta `json:",inline"`
42+
metav1.ListMeta `json:"metadata,omitempty"`
43+
Items []ScheduledBackup `json:"items"`
44+
}
45+
46+
func init() {
47+
SchemeBuilder.Register(&ScheduledBackup{}, &ScheduledBackupList{})
48+
}

api/preview/zz_generated.deepcopy.go

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

cmd/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,14 @@ func main() {
209209
os.Exit(1)
210210
}
211211

212+
if err = (&controller.ScheduledBackupReconciler{
213+
Client: mgr.GetClient(),
214+
Scheme: mgr.GetScheme(),
215+
}).SetupWithManager(mgr); err != nil {
216+
setupLog.Error(err, "unable to create controller", "controller", "ScheduledBackup")
217+
os.Exit(1)
218+
}
219+
212220
// +kubebuilder:scaffold:builder
213221

214222
if metricsCertWatcher != nil {

config/crd/bases/db.microsoft.com_backups.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ spec:
6161
description: BackupSpec defines the desired state of Backup.
6262
properties:
6363
cluster:
64-
description: Cluster specifies the DocumentDB cluster to backup.
64+
description: |-
65+
Cluster specifies the DocumentDB cluster to backup.
66+
The cluster must exist in the same namespace as the Backup resource.
6567
properties:
6668
name:
6769
description: Name of the referent.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
controller-gen.kubebuilder.io/version: v0.17.2
7+
name: scheduledbackups.db.microsoft.com
8+
spec:
9+
group: db.microsoft.com
10+
names:
11+
kind: ScheduledBackup
12+
listKind: ScheduledBackupList
13+
plural: scheduledbackups
14+
singular: scheduledbackup
15+
scope: Namespaced
16+
versions:
17+
- additionalPrinterColumns:
18+
- jsonPath: .spec.cluster.name
19+
name: Cluster
20+
type: string
21+
- jsonPath: .spec.schedule
22+
name: Schedule
23+
type: string
24+
name: preview
25+
schema:
26+
openAPIV3Schema:
27+
properties:
28+
apiVersion:
29+
description: |-
30+
APIVersion defines the versioned schema of this representation of an object.
31+
Servers should convert recognized schemas to the latest internal value, and
32+
may reject unrecognized values.
33+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
34+
type: string
35+
kind:
36+
description: |-
37+
Kind is a string value representing the REST resource this object represents.
38+
Servers may infer this from the endpoint the client submits requests to.
39+
Cannot be updated.
40+
In CamelCase.
41+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
42+
type: string
43+
metadata:
44+
type: object
45+
spec:
46+
description: ScheduledBackupSpec defines the desired state of ScheduledBackup
47+
properties:
48+
cluster:
49+
description: |-
50+
Cluster specifies the DocumentDB cluster to backup.
51+
The cluster must exist in the same namespace as the ScheduledBackup resource.
52+
properties:
53+
name:
54+
description: Name of the referent.
55+
type: string
56+
required:
57+
- name
58+
type: object
59+
schedule:
60+
description: Schedule defines when backups should be created using
61+
cron expression format.
62+
type: string
63+
required:
64+
- cluster
65+
- schedule
66+
type: object
67+
status:
68+
description: ScheduledBackupStatus defines the observed state of ScheduledBackup
69+
type: object
70+
required:
71+
- metadata
72+
- spec
73+
type: object
74+
served: true
75+
storage: true
76+
subresources:
77+
status: {}

documentdb-chart/crds/db.microsoft.com_backups.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ spec:
6161
description: BackupSpec defines the desired state of Backup.
6262
properties:
6363
cluster:
64-
description: Cluster specifies the DocumentDB cluster to backup.
64+
description: |-
65+
Cluster specifies the DocumentDB cluster to backup.
66+
The cluster must exist in the same namespace as the Backup resource.
6567
properties:
6668
name:
6769
description: Name of the referent.

0 commit comments

Comments
 (0)