Skip to content

Commit

Permalink
implement volume snapshot backups and restore (#557)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhudson committed Feb 23, 2024
1 parent dadd6c2 commit 9a4fe38
Show file tree
Hide file tree
Showing 15 changed files with 1,203 additions and 76 deletions.
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

0 comments on commit 9a4fe38

Please sign in to comment.