Skip to content

Commit 5e86a33

Browse files
committed
feat(platform): add default backupclass
Signed-off-by: Andrey Kolkov <[email protected]>
1 parent 1810263 commit 5e86a33

49 files changed

Lines changed: 2688 additions & 133 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

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

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

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

‎api/backups/v1alpha1/DESIGN.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ It does **not** implement the backup logic itself.
1818

1919
This document covers only the **core** API and its contracts with drivers, not driver implementations.
2020

21+
### Platform-managed default flow
22+
23+
As of Phase 2, Cozystack also ships **opinionated defaults** for the entire stack:
24+
25+
* A platform-managed S3 bucket `cozy-backups` (provisioned through `apps.cozystack.io/Bucket` in `cozy-backup-controller`).
26+
* Pre-rendered `Strategy` CRs `cozy-default-{cnpg,mariadb,etcd,altinity,foundationdb,velero-vminstance,velero-vmdisk}`.
27+
* A single cluster-wide `BackupClass` `cozy-default` whose `spec.strategies[]` binds each supported `apps.cozystack.io/<Kind>` to the matching strategy.
28+
* A `CredentialsProjector` inside `backupstrategy-controller` that copies the bucket-controller Secret into each tenant namespace as `cozy-backups-creds` on demand (per `BackupJob`/`RestoreJob` reconcile) and into a configured list of system namespaces (e.g. `cozy-velero`) on a periodic tick.
29+
30+
Tenants reference `cozy-default` from `BackupJob`/`Plan`/`RestoreJob`; they never see the bucket controller Secret, never write to a Secret in their own namespace (default RBAC denies it), and never share an S3 path with another tenant (every default strategy template prefixes the object key with `<namespace>/<application>`).
31+
32+
The platform-managed flow is layered *on top of* — not in place of — the core API. Custom `BackupClass`/Strategy CRs targeting other buckets continue to work; tenants picking `cozy-default` simply opt into the platform's pre-wired stack.
33+
34+
**Open gap (FoundationDB):** the `cozy-default-foundationdb` Strategy CR is shipped but **not** bound by `cozy-default`. Restore for FoundationDB runs `fdbrestore` from inside the `cozy-foundationdb-operator` deployment, which does not yet mount `cozy-backups-creds` with the blob credentials file. Admins who want platform-default FDB backups today must either wire the operator deployment manually or use a custom BackupClass — see [Backup Classes](../../../docs/operations/backup-classes.md) for the follow-up plan.
35+
36+
**Tenant visibility:** projected Secrets carry no `internal.cozystack.io/tenantresource` label, so the lineage-controller webhook does not promote them to a `TenantSecret` view. Combined with the default RBAC (no core/v1.Secret verbs on tenant ServiceAccounts), the projected credentials are unreadable from a tenant kubeconfig even when they sit in the tenant's own namespace; the operator Pods mount the Secret via kubelet, which bypasses tenant RBAC.
37+
2138
---
2239

2340
## 2. Goals and non-goals

‎cmd/backupstrategy-controller/main.go‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,19 +174,36 @@ func main() {
174174
os.Exit(1)
175175
}
176176

177+
credentialsConfig := backupcontroller.BackupCredentialsConfig{
178+
SourceNamespace: os.Getenv("BACKUP_STORAGE_SECRET_NAMESPACE"),
179+
SourceSecretName: os.Getenv("BACKUP_STORAGE_SECRET_NAME"),
180+
TargetSecretName: os.Getenv("BACKUP_STORAGE_CREDS_SECRET_NAME"),
181+
Endpoint: os.Getenv("BACKUP_STORAGE_ENDPOINT"),
182+
Region: os.Getenv("BACKUP_STORAGE_REGION"),
183+
}
184+
185+
if systemNamespaces := os.Getenv("BACKUP_STORAGE_SYSTEM_NAMESPACES"); systemNamespaces != "" {
186+
if err := mgr.Add(backupcontroller.NewSystemCredentialsProjector(mgr.GetClient(), credentialsConfig, systemNamespaces, 0)); err != nil {
187+
setupLog.Error(err, "unable to add SystemCredentialsProjector runnable")
188+
os.Exit(1)
189+
}
190+
}
191+
177192
if err = (&backupcontroller.BackupJobReconciler{
178-
Client: mgr.GetClient(),
179-
Scheme: mgr.GetScheme(),
180-
Recorder: mgr.GetEventRecorderFor("backup-controller"),
193+
Client: mgr.GetClient(),
194+
Scheme: mgr.GetScheme(),
195+
Recorder: mgr.GetEventRecorderFor("backup-controller"),
196+
CredentialsConfig: credentialsConfig,
181197
}).SetupWithManager(mgr); err != nil {
182198
setupLog.Error(err, "unable to create controller", "controller", "BackupJob")
183199
os.Exit(1)
184200
}
185201

186202
if err = (&backupcontroller.RestoreJobReconciler{
187-
Client: mgr.GetClient(),
188-
Scheme: mgr.GetScheme(),
189-
Recorder: mgr.GetEventRecorderFor("restore-controller"),
203+
Client: mgr.GetClient(),
204+
Scheme: mgr.GetScheme(),
205+
Recorder: mgr.GetEventRecorderFor("restore-controller"),
206+
CredentialsConfig: credentialsConfig,
190207
}).SetupWithManager(mgr); err != nil {
191208
setupLog.Error(err, "unable to create controller", "controller", "RestoreJob")
192209
os.Exit(1)

0 commit comments

Comments
 (0)