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

Reenable snapshots in the operator #889

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
103 changes: 41 additions & 62 deletions tembo-operator/Cargo.lock

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

2 changes: 1 addition & 1 deletion tembo-operator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "controller"
description = "Tembo Operator for Postgres"
version = "0.49.6"
version = "0.50.0"
edition = "2021"
default-run = "controller"
license = "Apache-2.0"
Expand Down
65 changes: 34 additions & 31 deletions tembo-operator/src/cloudnativepg/cnpg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ use crate::{
ClusterBackupVolumeSnapshotOnlineConfiguration,
ClusterBackupVolumeSnapshotSnapshotOwnerReference, ClusterBootstrap,
ClusterBootstrapInitdb, ClusterBootstrapRecovery,
ClusterBootstrapRecoveryRecoveryTarget, ClusterCertificates, ClusterExternalClusters,
ClusterExternalClustersBarmanObjectStore,
ClusterBootstrapRecoveryRecoveryTarget, ClusterBootstrapRecoveryVolumeSnapshots,
ClusterBootstrapRecoveryVolumeSnapshotsStorage, ClusterCertificates,
ClusterExternalClusters, ClusterExternalClustersBarmanObjectStore,
ClusterExternalClustersBarmanObjectStoreS3Credentials,
ClusterExternalClustersBarmanObjectStoreS3CredentialsAccessKeyId,
ClusterExternalClustersBarmanObjectStoreS3CredentialsRegion,
Expand All @@ -45,6 +46,7 @@ use crate::{
ClusterServiceAccountTemplate, ClusterServiceAccountTemplateMetadata, ClusterSpec,
ClusterStorage, ClusterSuperuserSecret,
},
cnpg_backups::create_backup_if_needed,
cnpg_utils::{
get_pooler_instances, is_image_updated, patch_cluster, restart_and_wait_for_restart,
},
Expand All @@ -64,6 +66,7 @@ use crate::{
is_postgres_ready,
postgres_exporter::EXPORTER_CONFIGMAP_PREFIX,
psql::PsqlOutput,
snapshots::volumesnapshots::reconcile_volume_snapshot_restore,
trunk::extensions_that_require_load,
Context,
};
Expand Down Expand Up @@ -496,7 +499,7 @@ fn cnpg_cluster_bootstrap(cdb: &CoreDB, restore: bool) -> ClusterBootstrap {
}
}),
// TODO: reenable this once we have a work around for snapshots
// volume_snapshots: cnpg_cluster_bootstrap_recovery_volume_snapshots(cdb),
volume_snapshots: cnpg_cluster_bootstrap_recovery_volume_snapshots(cdb),
..ClusterBootstrapRecovery::default()
}),
..ClusterBootstrap::default()
Expand All @@ -512,25 +515,25 @@ fn cnpg_cluster_bootstrap(cdb: &CoreDB, restore: bool) -> ClusterBootstrap {
}

// TODO: reenable this once we have a work around for snapshots
// fn cnpg_cluster_bootstrap_recovery_volume_snapshots(
// _cdb: &CoreDB,
// ) -> Option<ClusterBootstrapRecoveryVolumeSnapshots> {
// if let Some(restore) = &cdb.spec.restore {
// if restore.volume_snapshot == Some(true) {
// return Some(ClusterBootstrapRecoveryVolumeSnapshots {
// storage: ClusterBootstrapRecoveryVolumeSnapshotsStorage {
// // todo: Work on getting this from the VolumeSnapshot we created
// // during the restore process
// name: format!("{}-restore-vs", cdb.name_any()),
// kind: "VolumeSnapshot".to_string(),
// api_group: Some("snapshot.storage.k8s.io".to_string()),
// },
// ..ClusterBootstrapRecoveryVolumeSnapshots::default()
// });
// }
// }
// None
// }
fn cnpg_cluster_bootstrap_recovery_volume_snapshots(
cdb: &CoreDB,
) -> Option<ClusterBootstrapRecoveryVolumeSnapshots> {
if let Some(restore) = &cdb.spec.restore {
if restore.volume_snapshot == Some(true) {
return Some(ClusterBootstrapRecoveryVolumeSnapshots {
storage: ClusterBootstrapRecoveryVolumeSnapshotsStorage {
// todo: Work on getting this from the VolumeSnapshot we created
// during the restore process
name: format!("{}-restore-vs", cdb.name_any()),
kind: "VolumeSnapshot".to_string(),
api_group: Some("snapshot.storage.k8s.io".to_string()),
},
..ClusterBootstrapRecoveryVolumeSnapshots::default()
});
}
}
None
}

// Get PGConfig from CoreDB and convert it to a postgres_parameters and shared_preload_libraries
fn cnpg_postgres_config(
Expand Down Expand Up @@ -1003,12 +1006,12 @@ pub async fn reconcile_cnpg(cdb: &CoreDB, ctx: Arc<Context>) -> Result<(), Actio
// If we are restoring and have volume snapshots enabled, make sure we setup
// the VolumeSnapshotContent and VolumeSnapshot so that the Cluster will have
// something to restore from.
// if let Some(restore) = &cdb.spec.restore {
// if restore.volume_snapshot == Some(true) {
// debug!("Reconciling VolumeSnapshotContent and VolumeSnapshot for restore");
// reconcile_volume_snapshot_restore(cdb, ctx.clone()).await?;
// }
// }
if let Some(restore) = &cdb.spec.restore {
if restore.volume_snapshot == Some(true) {
debug!("Reconciling VolumeSnapshotContent and VolumeSnapshot for restore");
reconcile_volume_snapshot_restore(cdb, ctx.clone()).await?;
}
}

debug!("Generating CNPG spec");
let mut cluster = cnpg_cluster_from_cdb(cdb, Some(pods_to_fence), requires_load);
Expand Down Expand Up @@ -1145,9 +1148,9 @@ pub async fn reconcile_cnpg(cdb: &CoreDB, ctx: Arc<Context>) -> Result<(), Actio
}

// TODO: Add back support for using VolumeSnapshots
// if let Ok(cluster) = maybe_cluster {
// create_backup_if_needed(cdb, &ctx, &cluster).await?;
// }
if let Ok(cluster) = maybe_cluster {
create_backup_if_needed(cdb, &ctx, &cluster).await?;
}

// For manual changes conflicting with the operator, we have .force()
//
Expand Down
4 changes: 2 additions & 2 deletions tembo-operator/src/cloudnativepg/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pub(crate) mod archive;
pub mod backups;
pub mod clusters;
pub(crate) mod cnpg;
// pub(crate) mod cnpg_backups;
pub(crate) mod archive;
pub(crate) mod cnpg_backups;
pub mod cnpg_utils;
pub mod hibernate;
pub(crate) mod placement;
Expand Down
Loading