Files
cozystack/packages/apps
Alexey ArtamonovandYan Bondarenko 564bdd3a79 fix(clickhouse): delete the archive when its Backup is deleted
Deleting a Backup taken with the Altinity strategy released its
finalizer at once and left the archive in the bucket. On the system
bucket nothing else prunes it, so every ClickHouse backup stayed until
someone called the sidecar by hand.

Deleting such a Backup now runs a one-shot Job that asks the
application's sidecar to delete the archive the Backup records, and
holds the finalizer until the Job completes. The driver creates the
Backup with the finalizer already set, so a Backup deleted before the
reconciler first sees it still gets its archive deleted. An archive
that is already gone counts as deleted. The sidecar refuses a delete
while another operation runs, and cannot be reached while the
ClickHouse Pod restarts, so the Job waits both out within its
deadline; any other refusal fails the Job, which is reported as an
ArtifactCleanupFailed Warning Event carrying the reason it failed.

Each failure doubles the wait before the next cleanup Job, from 30
seconds up to 30 minutes, so a delete the sidecar refuses for good,
such as one made with a wrong password, does not cost a Job, its Pod
and a Warning Event every few seconds. The count of failures and the
time the next Job may start are kept on the Backup, because the Backup
controller does not watch Jobs; a start time further ahead than the
longest wait, from a skewed clock or a hand edit, is logged and
ignored. A Job the namespace's Job quota refuses is retried once a
slot frees up rather than released, since the Backup would be gone by
then and nothing would delete the archive.

The Job is built by the controller, not rendered from the strategy
template, because the shipped and the example templates run a restore
for every mode other than backup. Only the image, how to pull it, and
the node selector, tolerations, affinity and priority class come from
the template, rendered against the application and the Backup as for
the strategy's own Pods, so the cleanup Pod can be scheduled where
they are. The strategy is read only when a Job has to be created, so a
running delete outlives it. The Job also waits for the projected
credentials to reach the sidecar, as the backup and restore Jobs do: a
sidecar still serving the previous bucket answers "not found", and the
delete would count as done.

When the delete cannot run, the Backup is released with an
ArtifactNotDeleted Warning Event naming the archive left behind: the
namespace is terminating, the strategy, the application or its API
Secret is gone, the application has left the system bucket, the
platform's system bucket is no longer the one the Backup records (also
when it changes while the delete runs), another Job holds the cleanup
Job name, or the API server refuses the Job. An archive named without
its BackupJob's UID is released the same way: such a name comes from a
run that crossed the controller upgrade, and another run started in
the same second may share it. The
backups.cozystack.io/skip-artifact-cleanup annotation releases the
Backup without starting a delete. An application on its own bucket
keeps the archive's lifecycle, as with MongoDB.

The restore scenario and the chart comments told tenants to delete an
archive with DELETE /backup/<name>/remote, which clickhouse-backup 2.7
answers with 404; they now name POST /backup/delete/remote/<name>.

Co-authored-by: Yan Bondarenko <202671653+yankawai@users.noreply.github.com>
Assisted-by: LLM
Signed-off-by: Alexey Artamonov <aleksei.artamonov@aenix.io>
Signed-off-by: Yan Bondarenko <202671653+yankawai@users.noreply.github.com>
2026-11-23 12:15:05 +03:00
..
2025-08-07 14:07:05 +03:00

How to test packages local

cd packages/core/installer
make image-cozystack REGISTRY=YOUR_CUSTOM_REGISTRY
make apply
kubectl delete po -l app=source-controller -n cozy-fluxcd