Skip to content

Commit

Permalink
requested changes 3
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuajerin committed Nov 26, 2024
1 parent 691b30e commit 60ae97b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
25 changes: 14 additions & 11 deletions tembo-operator/src/cloudnativepg/hibernate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub async fn reconcile_cluster_hibernation(cdb: &CoreDB, ctx: &Arc<Context>) ->
return Err(Action::requeue(Duration::from_secs(300)));
}

let prefix_pooler = format!("{}-poller-0", cdb.name_any().as_str());
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
{
Expand All @@ -188,16 +188,19 @@ pub async fn reconcile_cluster_hibernation(cdb: &CoreDB, ctx: &Arc<Context>) ->
return Err(Action::requeue(Duration::from_secs(300)));
}

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)));
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.
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

0 comments on commit 60ae97b

Please sign in to comment.