From 60ae97bc9cbe58c7de1fc484ab07d4c668723638 Mon Sep 17 00:00:00 2001 From: Joshua Jerin Date: Wed, 27 Nov 2024 00:25:57 +0300 Subject: [PATCH] requested changes 3 --- tembo-operator/src/cloudnativepg/hibernate.rs | 25 +++++++++++-------- tembo-operator/tests/integration_tests.rs | 14 +++++++++++ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/tembo-operator/src/cloudnativepg/hibernate.rs b/tembo-operator/src/cloudnativepg/hibernate.rs index 523f9b3c8..340ed019e 100644 --- a/tembo-operator/src/cloudnativepg/hibernate.rs +++ b/tembo-operator/src/cloudnativepg/hibernate.rs @@ -176,7 +176,7 @@ pub async fn reconcile_cluster_hibernation(cdb: &CoreDB, ctx: &Arc) -> 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 { @@ -188,16 +188,19 @@ pub async fn reconcile_cluster_hibernation(cdb: &CoreDB, ctx: &Arc) -> 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. diff --git a/tembo-operator/tests/integration_tests.rs b/tembo-operator/tests/integration_tests.rs index 53f00a9d0..d570ca3bf 100644 --- a/tembo-operator/tests/integration_tests.rs +++ b/tembo-operator/tests/integration_tests.rs @@ -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 @@ -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 = + 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.