Skip to content

Commit

Permalink
Merge branch 'main' into fix-app-svc-ing
Browse files Browse the repository at this point in the history
  • Loading branch information
ianstanton authored Dec 17, 2024
2 parents 5cadb65 + e33bffc commit 37d82d9
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 88 deletions.
2 changes: 1 addition & 1 deletion conductor/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM quay.io/tembo/rust:1.79-slim as builder
FROM quay.io/tembo/rust:1.81-bookworm as builder

RUN apt-get update && \
apt-get install -y pkg-config libssl-dev && apt-get clean && \
Expand Down
167 changes: 86 additions & 81 deletions tembo-operator/src/cloudnativepg/hibernate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,100 +146,105 @@ pub async fn reconcile_cluster_hibernation(cdb: &CoreDB, ctx: &Arc<Context>) ->
}
}

// Remove IngressRoutes for stopped instances
let ingress_route_api: Api<IngressRoute> = Api::namespaced(ctx.client.clone(), &namespace);
if let Err(err) = delete_ingress_route(ingress_route_api.clone(), &namespace, &name).await {
warn!(
"Error deleting app service IngressRoute for {}: {}",
cdb.name_any(),
err
);
return Err(Action::requeue(Duration::from_secs(300)));
}

let metrics_ing_route_name = format!("{}-metrics", cdb.name_any().as_str());
if let Err(err) = delete_ingress_route(
ingress_route_api.clone(),
&namespace,
&metrics_ing_route_name,
)
.await
{
warn!(
"Error deleting metrics IngressRoute for {}: {}",
cdb.name_any(),
err
);
return Err(Action::requeue(Duration::from_secs(300)));
}
if cdb.spec.stop {
// Remove IngressRoutes for stopped instances
let ingress_route_api: Api<IngressRoute> = Api::namespaced(ctx.client.clone(), &namespace);
if let Err(err) = delete_ingress_route(ingress_route_api.clone(), &namespace, &name).await {
warn!(
"Error deleting app service IngressRoute for {}: {}",
cdb.name_any(),
err
);
return Err(Action::requeue(Duration::from_secs(300)));
}

// 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 IngressRouteTCP for {}: {}",
cdb.name_any(),
err
);
return Err(Action::requeue(Duration::from_secs(300)));
}
let metrics_ing_route_name = format!("{}-metrics", cdb.name_any().as_str());
if let Err(err) = delete_ingress_route(
ingress_route_api.clone(),
&namespace,
&metrics_ing_route_name,
)
.await
{
warn!(
"Error deleting metrics IngressRoute 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 IngressRouteTCP for {}: {}",
cdb.name_any(),
err
);
return Err(Action::requeue(Duration::from_secs(300)));
}
// 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 IngressRouteTCP 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 pooler IngressRouteTCP 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 IngressRouteTCP for {}: {}",
cdb.name_any(),
err
);
return Err(Action::requeue(Duration::from_secs(300)));
}

let ferret_ing = format!("{}-fdb-api", cdb.name_any().as_str());
if let Err(err) =
delete_ingress_route_tcp(ingress_route_tcp_api.clone(), &namespace, &ferret_ing).await
{
warn!(
"Error deleting ferretdb IngressRouteTCP 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 pooler IngressRouteTCP 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());
let ferret_ing = format!("{}-fdb-api", cdb.name_any().as_str());
if let Err(err) =
delete_ingress_route_tcp(ingress_route_tcp_api.clone(), &namespace, &prefix_extra).await
delete_ingress_route_tcp(ingress_route_tcp_api.clone(), &namespace, &ferret_ing).await
{
warn!(
"Error deleting extra postgres IngressRouteTCP for {}: {}",
"Error deleting ferretdb IngressRouteTCP 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 IngressRouteTCP for {}: {}",
cdb.name_any(),
err
);
return Err(Action::requeue(Duration::from_secs(300)));
}
}
}

// Stop CNPG reconciliation for hibernated instances.
Expand Down
12 changes: 6 additions & 6 deletions tembo-operator/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4369,19 +4369,19 @@ CREATE EVENT TRIGGER pgrst_watch
assert!(service_items.is_empty());
// should be no Services

// ingress must be gone
// There should be 1 IngressRoute left (metrics)
let ingresses: Vec<IngressRoute> =
list_resources(client.clone(), cdb_name, &namespace, &default_params, 0)
list_resources(client.clone(), cdb_name, &namespace, &default_params, 1)
.await
.unwrap();
assert_eq!(ingresses.len(), 0);
assert_eq!(ingresses.len(), 1);

// Assert IngressRouteTCP is gone
// There should be 1 IngressRouteTCP left (postgres)
let ingresses_tcp: Vec<IngressRouteTCP> =
list_resources(client.clone(), cdb_name, &namespace, &default_params, 0)
list_resources(client.clone(), cdb_name, &namespace, &default_params, 1)
.await
.unwrap();
assert_eq!(ingresses_tcp.len(), 0);
assert_eq!(ingresses_tcp.len(), 1);

// CLEANUP TEST
// Cleanup CoreDB
Expand Down

0 comments on commit 37d82d9

Please sign in to comment.