Skip to content

Commit 55af5ec

Browse files
committed
feat(platform): implement backup strategy for mariadb
Signed-off-by: Andrey Kolkov <[email protected]>
1 parent 86f5267 commit 55af5ec

30 files changed

Lines changed: 5553 additions & 47 deletions

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

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
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+
&MariaDB{},
18+
&MariaDBList{},
19+
)
20+
return nil
21+
})
22+
}
23+
24+
const (
25+
MariaDBStrategyKind = "MariaDB"
26+
)
27+
28+
// +kubebuilder:object:root=true
29+
// +kubebuilder:subresource:status
30+
// +kubebuilder:resource:scope=Cluster
31+
32+
// MariaDB defines a backup strategy that delegates execution to the
33+
// mariadb-operator (k8s.mariadb.com). The strategy carries a templated
34+
// logical-Backup configuration; the driver materialises k8s.mariadb.com
35+
// Backup objects per BackupJob and surfaces them as Cozystack Backup
36+
// artifacts. Restores create a fresh k8s.mariadb.com/Restore CR with
37+
// mariaDbRef pointing at the target MariaDB - the operator replays the
38+
// logical dump into the live database; the driver does not touch
39+
// MariaDB.spec.bootstrapFrom.
40+
type MariaDB struct {
41+
metav1.TypeMeta `json:",inline"`
42+
metav1.ObjectMeta `json:"metadata,omitempty"`
43+
44+
Spec MariaDBSpec `json:"spec,omitempty"`
45+
Status MariaDBStatus `json:"status,omitempty"`
46+
}
47+
48+
// +kubebuilder:object:root=true
49+
50+
// MariaDBList contains a list of MariaDB backup strategies.
51+
type MariaDBList struct {
52+
metav1.TypeMeta `json:",inline"`
53+
metav1.ListMeta `json:"metadata,omitempty"`
54+
Items []MariaDB `json:"items"`
55+
}
56+
57+
// MariaDBSpec specifies the desired mariadb-operator-driven backup strategy.
58+
type MariaDBSpec struct {
59+
// Template carries the templated k8s.mariadb.com/Backup configuration.
60+
// String fields support Helm-style Go templating with two top-level
61+
// values:
62+
// .Application - the application object (apps.cozystack.io/MariaDB)
63+
// .Parameters - the parameters from the matched BackupClassStrategy.
64+
// These values MUST NOT carry credentials. Route S3
65+
// access keys through Storage.S3.AccessKeyIDSecretKeyRef
66+
// and Storage.S3.SecretAccessKeySecretKeyRef.
67+
Template MariaDBTemplate `json:"template"`
68+
}
69+
70+
// MariaDBTemplate describes the templated k8s.mariadb.com/Backup shape the
71+
// driver renders per BackupJob.
72+
type MariaDBTemplate struct {
73+
// Storage defines the final storage for backups. Field semantics mirror
74+
// k8s.mariadb.com/v1alpha1 Backup.spec.storage. Exactly one of S3,
75+
// PersistentVolumeClaim or Volume must be set.
76+
Storage MariaDBStorageTemplate `json:"storage"`
77+
78+
// Databases lists the logical databases to back up. When empty all
79+
// non-system databases are backed up. Templating is supported on each
80+
// element.
81+
// +optional
82+
Databases []string `json:"databases,omitempty"`
83+
84+
// Compression algorithm used by mariadb-dump (e.g. "gzip", "bzip2",
85+
// "none"). Defaults to operator-side default when empty.
86+
// +optional
87+
Compression string `json:"compression,omitempty"`
88+
89+
// MaxRetention is the maximum retention period for kept backups (e.g.
90+
// "720h" for 30 days). When empty, retention is unbounded and tenants
91+
// rely on Cozystack Plan-level retention only.
92+
// +optional
93+
MaxRetention *metav1.Duration `json:"maxRetention,omitempty"`
94+
95+
// LogLevel controls log verbosity for mariadb-dump and the operator
96+
// Backup Job.
97+
// +optional
98+
LogLevel string `json:"logLevel,omitempty"`
99+
}
100+
101+
// MariaDBStorageTemplate mirrors k8s.mariadb.com/v1alpha1 Backup.spec.storage.
102+
// Exactly one of S3, PersistentVolumeClaim or Volume must be set.
103+
type MariaDBStorageTemplate struct {
104+
// S3 configures an S3-compatible storage target. Templating is supported
105+
// on Bucket, Endpoint, Prefix, Region and Secret Name fields.
106+
// +optional
107+
S3 *MariaDBS3Template `json:"s3,omitempty"`
108+
109+
// PersistentVolumeClaim configures a PVC-backed storage target. When set,
110+
// the driver creates a Kubernetes PVC that mariadb-operator mounts on the
111+
// Backup Job.
112+
// +optional
113+
PersistentVolumeClaim *corev1.PersistentVolumeClaimSpec `json:"persistentVolumeClaim,omitempty"`
114+
115+
// Volume configures an arbitrary Kubernetes volume source as the backup
116+
// target.
117+
// +optional
118+
Volume *corev1.VolumeSource `json:"volume,omitempty"`
119+
}
120+
121+
// MariaDBS3Template is a typed, kubebuilder-validated mirror of the
122+
// k8s.mariadb.com/v1alpha1 Backup.spec.storage.s3 shape. The driver
123+
// translates this struct into the operator-native Backup spec.
124+
type MariaDBS3Template struct {
125+
// Bucket is the name of the S3 bucket that stores backups. Templating is
126+
// supported.
127+
// +kubebuilder:validation:MinLength=1
128+
Bucket string `json:"bucket"`
129+
130+
// Endpoint is the S3 API endpoint without scheme (e.g.
131+
// "seaweedfs-s3.tenant-root.svc:8333"). Templating is supported.
132+
// +kubebuilder:validation:MinLength=1
133+
Endpoint string `json:"endpoint"`
134+
135+
// Prefix indicates a folder/subfolder in the bucket. A trailing '/' is
136+
// added by the operator if not provided. Templating is supported.
137+
// +optional
138+
Prefix string `json:"prefix,omitempty"`
139+
140+
// Region is the S3 region name. Templating is supported.
141+
// +optional
142+
Region string `json:"region,omitempty"`
143+
144+
// AccessKeyIDSecretKeyRef references a Secret key holding the S3 access
145+
// key id. Templating is supported on Name.
146+
AccessKeyIDSecretKeyRef MariaDBSecretKeySelector `json:"accessKeyIdSecretKeyRef"`
147+
148+
// SecretAccessKeySecretKeyRef references a Secret key holding the S3
149+
// secret access key. Templating is supported on Name.
150+
SecretAccessKeySecretKeyRef MariaDBSecretKeySelector `json:"secretAccessKeySecretKeyRef"`
151+
152+
// SessionTokenSecretKeyRef references a Secret key holding an optional
153+
// S3 session token. Templating is supported on Name.
154+
// +optional
155+
SessionTokenSecretKeyRef *MariaDBSecretKeySelector `json:"sessionTokenSecretKeyRef,omitempty"`
156+
157+
// TLS configures TLS settings used by the operator when reaching the S3
158+
// endpoint.
159+
// +optional
160+
TLS *MariaDBS3TLS `json:"tls,omitempty"`
161+
}
162+
163+
// MariaDBSecretKeySelector mirrors k8s.mariadb.com SecretKeySelector. The
164+
// underlying Secret must live in the application's namespace.
165+
type MariaDBSecretKeySelector struct {
166+
// Name is the Secret name. Templating is supported.
167+
Name string `json:"name"`
168+
169+
// Key is the key within the Secret holding the value.
170+
Key string `json:"key"`
171+
}
172+
173+
// MariaDBS3TLS mirrors k8s.mariadb.com Backup.spec.storage.s3.tls.
174+
type MariaDBS3TLS struct {
175+
// Enabled toggles TLS for connections to the S3 endpoint.
176+
// +optional
177+
Enabled bool `json:"enabled,omitempty"`
178+
179+
// CASecretKeyRef references a Secret carrying a PEM-encoded CA bundle
180+
// the operator should trust when reaching a self-signed S3 endpoint
181+
// (e.g. cozystack's seaweedfs-s3). Templating is supported on Name.
182+
// +optional
183+
CASecretKeyRef *MariaDBSecretKeySelector `json:"caSecretKeyRef,omitempty"`
184+
}
185+
186+
// MariaDBStatus reports observed state for the strategy CR. Driver
187+
// controllers surface diagnostic conditions here (e.g. validation issues).
188+
type MariaDBStatus struct {
189+
// Conditions holds the latest available observations.
190+
// +optional
191+
// +listType=map
192+
// +listMapKey=type
193+
Conditions []metav1.Condition `json:"conditions,omitempty"`
194+
}

0 commit comments

Comments
 (0)