Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement volume snapshot backups and restore #557

Merged
merged 26 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8101b0e
implement volume snapshot backups
nhudson Feb 19, 2024
9ffcd12
make volumeSnapshot disabled by default
nhudson Feb 19, 2024
c4cc9bb
fix test
nhudson Feb 19, 2024
2901554
add scheduled backups for both object store and snapshots if snapshot…
nhudson Feb 20, 2024
5eaccd5
Merge branch 'main' into nhudson/TEM-3089
nhudson Feb 20, 2024
44b3591
Merge branch 'main' into nhudson/TEM-3089
nhudson Feb 21, 2024
830830f
implement volume snapshot restores
nhudson Feb 21, 2024
9f19ff5
update crd manifest
nhudson Feb 21, 2024
88a7926
fix fmt
nhudson Feb 21, 2024
d30023d
Merge branch 'main' into nhudson/TEM-3089
nhudson Feb 21, 2024
2fecb6b
fix namespace lookup for volumesnapshot, update rbac
nhudson Feb 21, 2024
e953d6c
patch/create a volumesnapshotcontent
nhudson Feb 21, 2024
bb3e6dd
make sure when patching to supply the correct name
nhudson Feb 21, 2024
745a25f
make sure to use snapshotHandle instead of volumeHandle
nhudson Feb 22, 2024
8aef2c6
fix tests
nhudson Feb 22, 2024
4d4f925
clean up snapshot stuff
nhudson Feb 22, 2024
8570fcb
Merge branch 'main' into nhudson/TEM-3089
nhudson Feb 22, 2024
86a544d
fix snapshot test
nhudson Feb 22, 2024
9d8b5ef
adding check to make sure volumesnapshot is ready prior to creating t…
nhudson Feb 22, 2024
bf35335
fix issue with pointing to the incorrect snapshot
nhudson Feb 22, 2024
77d9479
add missing crate
nhudson Feb 22, 2024
053f3cf
make sure scheduledbackup job name is <=63 chars
nhudson Feb 22, 2024
1bb6af3
Merge branch 'main' into nhudson/TEM-3089
nhudson Feb 23, 2024
f1cfb43
Merge branch 'main' into nhudson/TEM-3089
nhudson Feb 23, 2024
9372806
add better error logging
nhudson Feb 23, 2024
9d28f45
better logging
nhudson Feb 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions charts/tembo-operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: tembo-operator
description: 'Helm chart to deploy the tembo-operator'
type: application
icon: https://cloud.tembo.io/images/TemboElephant.png
version: 0.3.0
version: 0.3.1
home: https://tembo.io
sources:
- https://github.com/tembo-io/tembo-stacks
- https://github.com/tembo-io/tembo
- https://github.com/cloudnative-pg/cloudnative-pg
keywords:
- postgresql
Expand Down
22 changes: 22 additions & 0 deletions charts/tembo-operator/templates/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,8 @@ spec:
endpointURL: null
s3Credentials:
inheritFromIAMRole: true
volumeSnapshot:
enabled: false
description: |-
The backup configuration for the CoreDB instance to facilitate database backups and WAL archive uploads to an S3 compatible object store.

Expand Down Expand Up @@ -1432,6 +1434,22 @@ spec:
description: The backup schedule set with cron syntax
nullable: true
type: string
volumeSnapshot:
default:
enabled: false
description: Enable using Volume Snapshots for backups instead of Object Storage
nullable: true
properties:
enabled:
description: Enable the volume snapshots for backups
type: boolean
snapshotClass:
description: The reference to the snapshot class
nullable: true
type: string
required:
- enabled
type: object
type: object
connectionPooler:
default:
Expand Down Expand Up @@ -1803,6 +1821,10 @@ spec:

This assumes you are keeping the backups in the new instance in the same root bucket path of `s3://my-bucket/`.
type: string
volumeSnapshot:
description: volumeSnapshot is a boolean to enable restoring from a Volume Snapshot
nullable: true
type: boolean
required:
- serverName
type: object
Expand Down
3 changes: 3 additions & 0 deletions charts/tembo-operator/templates/rbac-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,8 @@ rules:
- apiGroups: [""]
resources: ["namespaces"]
verbs: ["get", "list", "watch"]
- apiGroups: ["snapshot.storage.k8s.io"]
resources: ["volumesnapshots", "volumesnapshotcontents"]
verbs: ["create", "delete", "get", "list", "patch", "update", "watch"]
{{- end }}
{{- end }}
2 changes: 1 addition & 1 deletion tembo-operator/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 33 additions & 1 deletion tembo-operator/src/apis/coredb_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,29 @@ pub struct S3CredentialsSessionToken {
pub name: String,
}

/// VolumeSnapshots is the type for the configuration of the volume snapshots
/// to be used for backups instead of object storage
#[derive(Serialize, Deserialize, Clone, Debug, Default, JsonSchema)]
pub struct VolumeSnapshot {
/// Enable the volume snapshots for backups
pub enabled: bool,

/// The reference to the snapshot class
#[serde(
default,
skip_serializing_if = "Option::is_none",
rename = "snapshotClass"
)]
pub snapshot_class: Option<String>,
}

/// CoreDB Backup configuration
/// The backup configuration for the CoreDB instance to facilitate database
/// backups and WAL archive uploads to an S3 compatible object store.
/// backups uploads to an S3 compatible object store or using Volume Snapshots
/// For WAL archive uploads utilite an S3 compatible object store.
///
/// **Example**: A typical S3 backup configuration using IAM Role for authentication
/// with Volume Snapshots enabled
///
/// See `ServiceAccountTemplate` for to map the IAM role ARN to a Kubernetes service account.
///
Expand All @@ -178,6 +196,9 @@ pub struct S3CredentialsSessionToken {
/// s3Credentials:
/// inheritFromIAMRole: true
/// schedule: "0 0 * * *" #every day at midnight
/// volumeSnapshots:
/// enabled: true
/// snapshotClass: my-snapshot-class-name
/// ```
#[derive(Deserialize, Serialize, Clone, Debug, Default, JsonSchema)]
#[allow(non_snake_case)]
Expand Down Expand Up @@ -205,6 +226,13 @@ pub struct Backup {
/// The S3 credentials to use for backups (if not using IAM Role)
#[serde(default = "defaults::default_s3_credentials", rename = "s3Credentials")]
pub s3_credentials: Option<S3Credentials>,

/// Enable using Volume Snapshots for backups instead of Object Storage
#[serde(
default = "defaults::default_volume_snapshot",
rename = "volumeSnapshot"
)]
pub volume_snapshot: Option<VolumeSnapshot>,
}

/// Restore configuration provides a way to restore a database from a backup
Expand Down Expand Up @@ -249,6 +277,10 @@ pub struct Restore {
/// s3Credentials is the S3 credentials to use for backups.
#[serde(rename = "s3Credentials")]
pub s3_credentials: Option<S3Credentials>,

/// volumeSnapshot is a boolean to enable restoring from a Volume Snapshot
#[serde(rename = "volumeSnapshot")]
pub volume_snapshot: Option<bool>,
}

/// A connection pooler is a tool used to manage database connections, sitting
Expand Down
6 changes: 3 additions & 3 deletions tembo-operator/src/cloudnativepg/clusters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ pub enum ClusterBackupTarget {
}

/// VolumeSnapshot provides the configuration for the execution of volume snapshot backups.
#[derive(Serialize, Deserialize, Clone, Debug, Default, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, Default, JsonSchema, PartialEq)]
pub struct ClusterBackupVolumeSnapshot {
/// Annotations key-value pairs that will be added to .metadata.annotations snapshot resources.
#[serde(default, skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -1202,7 +1202,7 @@ pub struct ClusterBackupVolumeSnapshot {
}

/// Configuration parameters to control the online/hot backup with volume snapshots
#[derive(Serialize, Deserialize, Clone, Debug, Default, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, Default, JsonSchema, PartialEq)]
pub struct ClusterBackupVolumeSnapshotOnlineConfiguration {
/// Control whether the I/O workload for the backup initial checkpoint will be limited, according to the `checkpoint_completion_target` setting on the PostgreSQL server. If set to true, an immediate checkpoint will be used, meaning PostgreSQL will complete the checkpoint as soon as possible. `false` by default.
#[serde(
Expand All @@ -1221,7 +1221,7 @@ pub struct ClusterBackupVolumeSnapshotOnlineConfiguration {
}

/// VolumeSnapshot provides the configuration for the execution of volume snapshot backups.
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema, PartialEq)]
pub enum ClusterBackupVolumeSnapshotSnapshotOwnerReference {
#[serde(rename = "none")]
None,
Expand Down
Loading
Loading