Skip to content

Commit bd3989c

Browse files
committed
feat(platform): add implementation of backup-strategy controller for foundationdb
Signed-off-by: Andrey Kolkov <[email protected]>
1 parent 9d0724f commit bd3989c

33 files changed

Lines changed: 12545 additions & 47 deletions

‎api/apps/v1alpha1/foundationdb/types.go‎

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Package v1alpha1 defines strategy.backups.cozystack.io API types.
3+
//
4+
// Group: strategy.backups.cozystack.io
5+
// Version: v1alpha1
6+
package v1alpha1
7+
8+
import (
9+
corev1 "k8s.io/api/core/v1"
10+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11+
"k8s.io/apimachinery/pkg/runtime"
12+
)
13+
14+
func init() {
15+
SchemeBuilder.Register(func(s *runtime.Scheme) error {
16+
s.AddKnownTypes(GroupVersion,
17+
&FoundationDB{},
18+
&FoundationDBList{},
19+
)
20+
return nil
21+
})
22+
}
23+
24+
const (
25+
FoundationDBStrategyKind = "FoundationDB"
26+
)
27+
28+
// +kubebuilder:object:root=true
29+
// +kubebuilder:subresource:status
30+
// +kubebuilder:resource:scope=Cluster
31+
32+
// FoundationDB defines a backup strategy that delegates execution to the
33+
// FoundationDB Kubernetes operator (apps.foundationdb.org). The strategy
34+
// carries a templated FoundationDBBackup-like configuration; the driver
35+
// materialises apps.foundationdb.org/v1beta2 FoundationDBBackup objects per
36+
// Cozystack BackupJob and surfaces them as Cozystack Backup artefacts.
37+
// Restores are driven by materialising FoundationDBRestore CRs against the
38+
// target FoundationDBCluster (in-place: same cluster; to-copy: a freshly
39+
// deployed cluster).
40+
type FoundationDB struct {
41+
metav1.TypeMeta `json:",inline"`
42+
metav1.ObjectMeta `json:"metadata,omitempty"`
43+
44+
Spec FoundationDBSpec `json:"spec,omitempty"`
45+
Status FoundationDBStatus `json:"status,omitempty"`
46+
}
47+
48+
// +kubebuilder:object:root=true
49+
50+
// FoundationDBList contains a list of FoundationDB backup strategies.
51+
type FoundationDBList struct {
52+
metav1.TypeMeta `json:",inline"`
53+
metav1.ListMeta `json:"metadata,omitempty"`
54+
Items []FoundationDB `json:"items"`
55+
}
56+
57+
// FoundationDBSpec specifies the desired FoundationDB-operator-driven backup
58+
// strategy.
59+
type FoundationDBSpec struct {
60+
// Template carries the templated FoundationDBBackup/FoundationDBRestore
61+
// configuration applied per BackupJob and RestoreJob. String fields
62+
// support Helm-style Go templating with two top-level values:
63+
// .Application - the application object (apps.cozystack.io/FoundationDB)
64+
// .Parameters - the parameters from the matched BackupClassStrategy.
65+
// These values MUST NOT carry credentials. Route S3
66+
// access keys through BackupDeploymentPodTemplateSpec
67+
// volumes/env (typical pattern: mount a Secret-backed
68+
// blob_credentials.json file and set
69+
// FDB_BLOB_CREDENTIALS to its path, or pass
70+
// --blob_credentials=<path> via CustomParameters).
71+
Template FoundationDBTemplate `json:"template"`
72+
}
73+
74+
// FoundationDBTemplate describes the templated FoundationDBBackup-shaped
75+
// configuration the driver renders per BackupJob (and the matching
76+
// FoundationDBRestore on the restore path).
77+
type FoundationDBTemplate struct {
78+
// BlobStoreConfiguration is the templated blob-store configuration
79+
// passed verbatim to the FDB operator (apps.foundationdb.org). Field
80+
// semantics mirror apps.foundationdb.org/v1beta2 BlobStoreConfiguration.
81+
BlobStoreConfiguration FoundationDBBlobStoreTemplate `json:"blobStoreConfiguration"`
82+
83+
// AgentCount is the number of backup_agent pods the operator runs in
84+
// the backup deployment. When zero, the operator default applies.
85+
// +optional
86+
AgentCount *int32 `json:"agentCount,omitempty"`
87+
88+
// SnapshotPeriodSeconds controls how often the backup_agent rotates a
89+
// full snapshot inside the backup directory. When zero, the operator
90+
// default applies (3600).
91+
// +optional
92+
SnapshotPeriodSeconds *int32 `json:"snapshotPeriodSeconds,omitempty"`
93+
94+
// CustomParameters are extra knobs passed to the backup_agent and
95+
// fdbrestore processes. Templating is supported on each element.
96+
// Common entries include --blob_credentials=<path> and the
97+
// --knob_http_request_* tuning knobs.
98+
// +optional
99+
CustomParameters []string `json:"customParameters,omitempty"`
100+
101+
// EncryptionKeyPath is the in-container path to a backup encryption
102+
// key file. Templating is supported.
103+
// +optional
104+
EncryptionKeyPath string `json:"encryptionKeyPath,omitempty"`
105+
106+
// BackupDeploymentPodTemplateSpec is the PodTemplateSpec the driver
107+
// stamps onto FoundationDBBackup.spec.backupDeploymentSpec.podTemplateSpec.
108+
// Admins use it to mount credentials, CA bundles, or any other
109+
// per-tenant secrets the backup_agent needs. Templating is supported
110+
// on every string field.
111+
// +optional
112+
BackupDeploymentPodTemplateSpec *corev1.PodTemplateSpec `json:"backupDeploymentPodTemplateSpec,omitempty"`
113+
114+
// RetentionPolicy is an informational retention expression (e.g.
115+
// "30d") echoed onto Cozystack Backup artefacts. The FoundationDB
116+
// operator does not auto-prune backup directories, so the field is
117+
// purely metadata today; tenants are expected to wire retention through
118+
// Cozystack Plan-level policy.
119+
// +optional
120+
RetentionPolicy string `json:"retentionPolicy,omitempty"`
121+
}
122+
123+
// FoundationDBBlobStoreTemplate is a typed, kubebuilder-validated mirror of
124+
// apps.foundationdb.org/v1beta2 BlobStoreConfiguration. Restores reuse the
125+
// same shape: the driver re-renders the strategy and points the
126+
// FoundationDBRestore at the BackupName recorded on the source Backup
127+
// artefact.
128+
type FoundationDBBlobStoreTemplate struct {
129+
// AccountName is the operator's blob account identifier
130+
// (typically "<key>@<endpoint-host>"). Templating is supported.
131+
// +kubebuilder:validation:MinLength=1
132+
// +kubebuilder:validation:MaxLength=100
133+
AccountName string `json:"accountName"`
134+
135+
// Bucket is the S3 (or compatible) bucket name. Templating is
136+
// supported. When empty the operator uses the BackupName as the
137+
// path root only.
138+
// +optional
139+
// +kubebuilder:validation:MaxLength=63
140+
Bucket string `json:"bucket,omitempty"`
141+
142+
// BackupName is the per-cluster path segment under the bucket. When
143+
// empty, the driver fills it per BackupJob to give each run a
144+
// discrete S3 path (one operator backup directory per Cozystack
145+
// Backup artefact). Templating is supported.
146+
// +optional
147+
// +kubebuilder:validation:MaxLength=1024
148+
BackupName string `json:"backupName,omitempty"`
149+
150+
// URLParameters are extra blob-store URL parameters passed through
151+
// to the operator (e.g. "secure_connection=0", "region=us-east-1").
152+
// Templating is supported on each element.
153+
// +optional
154+
URLParameters []string `json:"urlParameters,omitempty"`
155+
}
156+
157+
// FoundationDBStatus reports observed state for the strategy CR. Driver
158+
// controllers surface diagnostic conditions here (e.g. validation issues).
159+
type FoundationDBStatus struct {
160+
// Conditions holds the latest available observations.
161+
// +optional
162+
// +listType=map
163+
// +listMapKey=type
164+
Conditions []metav1.Condition `json:"conditions,omitempty"`
165+
}

‎api/backups/strategy/v1alpha1/zz_generated.deepcopy.go‎

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

‎cmd/backupstrategy-controller/main.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ import (
4141
backupsv1alpha1 "github.com/cozystack/cozystack/api/backups/v1alpha1"
4242
"github.com/cozystack/cozystack/internal/backupcontroller"
4343
"github.com/cozystack/cozystack/internal/backupcontroller/cnpgtypes"
44+
"github.com/cozystack/cozystack/internal/backupcontroller/foundationdbapp"
45+
"github.com/cozystack/cozystack/internal/backupcontroller/foundationdbtypes"
4446
"github.com/cozystack/cozystack/internal/backupcontroller/mariadbapp"
4547
"github.com/cozystack/cozystack/internal/backupcontroller/mariadbtypes"
4648
"github.com/cozystack/cozystack/internal/backupcontroller/postgresapp"
@@ -63,6 +65,8 @@ func init() {
6365
utilruntime.Must(postgresapp.AddToScheme(scheme))
6466
utilruntime.Must(mariadbtypes.AddToScheme(scheme))
6567
utilruntime.Must(mariadbapp.AddToScheme(scheme))
68+
utilruntime.Must(foundationdbtypes.AddToScheme(scheme))
69+
utilruntime.Must(foundationdbapp.AddToScheme(scheme))
6670
// +kubebuilder:scaffold:scheme
6771
}
6872

0 commit comments

Comments
 (0)