Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Roadmap item 7 in #65 asks for automated backups to S3. Today the operator has no way to back up or
restore a cluster, so users run their own CronJobs or sidecars.
This PR adds backups and restores built on the native
BACKUP/RESTOREstatements. The data goesfrom the ClickHouse pods to the storage directly: there is no sidecar, no extra pod, and the operator
needs no access to the storage.
What
Three new resources in
clickhouse.com/v1alpha1. They are separate kinds, soClickHouseClusterandKeeperClusterare not changed.ClickHouseBackupruns one backup. The controller submitsBACKUP ... ON CLUSTER 'default' TO S3(...) SETTINGS id = '<object UID>' ASYNCto the first reachablereplica and polls
system.backupson that replica until the operation finishes.spec.scopeselects databases and tables. The default isALL EXCEPT DATABASES system.spec.baseBackupRefmakes the backup incremental (base_backup).spec.storage.s3.credentialsreferences Secret keys. When omitted, the server credentials are used(IRSA, instance profile).
s3_allow_server_credentials_in_user_queriesis added on servers thatknow the setting.
ClickHouseScheduledBackupcreatesClickHouseBackupresources on a cron schedule.fullBackupInterval: Ntakes one full backup followed byN - 1incremental backups based on it.ClickHouseBackupresources and never remove the latest full backupor the base of a kept incremental backup.
ClickHouseRestoreruns oneRESTORE ... ON CLUSTERfrom aClickHouseBackup(backupRef) or from alocation in the storage (
source), which covers restoring into a new Kubernetes cluster.Behavior worth reviewing:
id. A repeated submission (operator restart between thestatement and the status update) is rejected by ClickHouse with "another backup with the same ID" and
is treated as already submitted.
system.backupsis in memory. If the replica that executes the operation restarts, the operation isreported as
Failedwith reasonStateLost.backup_logis not enabled by the operator, and enablingit would restart existing clusters, so it is not used.
operator never logs the statement and removes the secret from error messages before storing them.
Not in this PR:
lifecycle rules are expected to expire the data.
spec.storageis a union so that more can be added.New dependency:
github.com/robfig/cron/v3to parse cron schedules, the parser Kubernetes CronJobs use.Tests:
envtesttests for the three controllers with a fake executor, including the CEL rules.commandersuite that run backup, incremental backup, restore anda failing backup against real ClickHouse and an S3 mock (
adobe/s3mock).Label("clickhouse", "backup")) that takes a full and an incremental backup, restores adropped table, reports a failed backup and runs a schedule.
Docs:
docs/guides/backup.mdx, events reference, API reference,examples/scheduled_backup_s3.yaml.Run locally:
make lint,make test,make check-crd-compat, and the new e2e spec on a kind cluster(
--ginkgo.focus="Backup controller"). The full e2e suite was not run. All runs used an S3 mock, sothe server-credentials path is not exercised against real AWS.
Related Issues
Fixes #393
Related to #65