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

Remove IngressRouteTCP for Stopped Instances #1058

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
58 changes: 58 additions & 0 deletions tembo-operator/src/cloudnativepg/hibernate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::cloudnativepg::clusters::{ClusterStatusConditions, ClusterStatusCondi
use crate::cloudnativepg::cnpg::{get_cluster, get_pooler, get_scheduled_backups};
use crate::cloudnativepg::poolers::Pooler;
use crate::cloudnativepg::scheduledbackups::ScheduledBackup;
use crate::ingress::delete_ingress_route_tcp;
use crate::Error;

use crate::{patch_cdb_status_merge, requeue_normal_with_jitter, Context};
Expand Down Expand Up @@ -145,6 +146,63 @@ pub async fn reconcile_cluster_hibernation(cdb: &CoreDB, ctx: &Arc<Context>) ->
}
}

// Remove IngressRouteTCP route for stopped instances
let ingress_route_tcp_api = Api::namespaced(ctx.client.clone(), &namespace);
let prefix_read_only = format!("{}-ro-0", cdb.name_any().as_str());
if let Err(err) =
delete_ingress_route_tcp(ingress_route_tcp_api.clone(), &namespace, &prefix_read_only).await
{
warn!(
"Error deleting postgres ingress route for {}: {}",
cdb.name_any(),
err
);
return Err(Action::requeue(Duration::from_secs(300)));
}

let prefix_read_write = format!("{}-rw-0", cdb.name_any().as_str());
if let Err(err) = delete_ingress_route_tcp(
ingress_route_tcp_api.clone(),
&namespace,
&prefix_read_write,
)
.await
{
warn!(
"Error deleting postgres ingress route for {}: {}",
cdb.name_any(),
err
);
return Err(Action::requeue(Duration::from_secs(300)));
}

let prefix_pooler = format!("{}-pooler-0", cdb.name_any().as_str());
if let Err(err) =
delete_ingress_route_tcp(ingress_route_tcp_api.clone(), &namespace, &prefix_pooler).await
{
warn!(
"Error deleting postgres ingress route for {}: {}",
cdb.name_any(),
err
);
return Err(Action::requeue(Duration::from_secs(300)));
}

let extra_domain_names = cdb.spec.extra_domains_rw.clone().unwrap_or_default();
if !extra_domain_names.is_empty() {
let prefix_extra = format!("extra-{}-rw", cdb.name_any().as_str());
if let Err(err) =
delete_ingress_route_tcp(ingress_route_tcp_api.clone(), &namespace, &prefix_extra).await
{
warn!(
"Error deleting extra postgres ingress route for {}: {}",
cdb.name_any(),
err
);
return Err(Action::requeue(Duration::from_secs(300)));
}
}

// Stop CNPG reconciliation for hibernated instances.
// We should not stop CNPG reconciliation until hibernation is fully completed,
// as the instance may not finish hibernating otherwise.
Expand Down
2 changes: 1 addition & 1 deletion tembo-operator/src/ingress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ async fn apply_ingress_route_tcp(
Ok(())
}

async fn delete_ingress_route_tcp(
pub async fn delete_ingress_route_tcp(
ingress_route_tcp_api: Api<IngressRouteTCP>,
namespace: &str,
ingress_route_tcp_name: &String,
Expand Down
14 changes: 14 additions & 0 deletions tembo-operator/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5808,6 +5808,7 @@ CREATE EVENT TRIGGER pgrst_watch
let test = TestCore::new(test_name).await;
let name = test.name.clone();
let pooler_name = format!("{}-pooler", name);
let namespace = test.namespace.clone();

// Generate very simple CoreDB JSON definitions. The first will be for
// initializing and starting the cluster, and the second for stopping
Expand Down Expand Up @@ -5850,6 +5851,19 @@ CREATE EVENT TRIGGER pgrst_watch
.await
.not());

// Assert that ingress routes are removed after hibernation

let client = test.client.clone();
let ingresses_tcp: Vec<IngressRouteTCP> =
list_resources(client.clone(), &name, &namespace, 0)
.await
.unwrap();
assert_eq!(
ingresses_tcp.len(),
0,
"Ingress routes should be removed after hibernation"
);

// Patch the cluster to start it up again, then check to ensure it
// actually did so. This proves hibernation can be reversed.

Expand Down
Loading