Skip to content

Commit

Permalink
Cleanup unused ingressroutetcp
Browse files Browse the repository at this point in the history
  • Loading branch information
sjmiller609 committed Jun 24, 2024
1 parent f073e9d commit ed8399a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 28 deletions.
53 changes: 25 additions & 28 deletions tembo-operator/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ use crate::{
postgres_certificates::reconcile_certificates,
psql::{PsqlCommand, PsqlOutput},
secret::{reconcile_postgres_role_secret, reconcile_secret},
telemetry,
Error,
Metrics,
Result,
telemetry, Error, Metrics, Result,
};
use k8s_openapi::{
api::core::v1::{Namespace, Pod},
Expand Down Expand Up @@ -228,6 +225,7 @@ impl CoreDB {
service_name_read_only.as_str(),
IntOrString::Int(5432),
vec![middleware_name.clone()],
self.spec.replicas < 2 || self.spec.stop,
)
.await
.map_err(|e| {
Expand All @@ -250,6 +248,7 @@ impl CoreDB {
service_name_read_write.as_str(),
IntOrString::Int(5432),
vec![middleware_name.clone()],
self.spec.replicas < 1 || self.spec.stop,
)
.await
.map_err(|e| {
Expand Down Expand Up @@ -277,30 +276,28 @@ impl CoreDB {
Action::requeue(Duration::from_secs(300))
})?;

// If pooler is enabled, reconcile ingress route tcp for pooler
if self.spec.connectionPooler.enabled {
let name_pooler = format!("{}-pooler", self.name_any().as_str());
let prefix_pooler = format!("{}-pooler-", self.name_any().as_str());
reconcile_postgres_ing_route_tcp(
self,
ctx.clone(),
name_pooler.as_str(),
basedomain.as_str(),
ns.as_str(),
prefix_pooler.as_str(),
name_pooler.as_str(),
IntOrString::Int(5432),
vec![middleware_name.clone()],
)
.await
.map_err(|e| {
error!("Error reconciling pooler ingress route: {:?}", e);
// For unexpected errors, we should requeue for several minutes at least,
// for expected, "waiting" type of requeuing, those should be shorter, just a few seconds.
// IngressRouteTCP does not have expected errors during reconciliation.
Action::requeue(Duration::from_secs(300))
})?;
}
let name_pooler = format!("{}-pooler", self.name_any().as_str());
let prefix_pooler = format!("{}-pooler-", self.name_any().as_str());
reconcile_postgres_ing_route_tcp(
self,
ctx.clone(),
name_pooler.as_str(),
basedomain.as_str(),
ns.as_str(),
prefix_pooler.as_str(),
name_pooler.as_str(),
IntOrString::Int(5432),
vec![middleware_name.clone()],
self.spec.replicas < 1 || self.spec.stop || !self.spec.connectionPooler.enabled,
)
.await
.map_err(|e| {
error!("Error reconciling pooler ingress route: {:?}", e);
// For unexpected errors, we should requeue for several minutes at least,
// for expected, "waiting" type of requeuing, those should be shorter, just a few seconds.
// IngressRouteTCP does not have expected errors during reconciliation.
Action::requeue(Duration::from_secs(300))
})?;
}
Err(_e) => {
warn!(
Expand Down
11 changes: 11 additions & 0 deletions tembo-operator/src/ingress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ async fn delete_ingress_route_tcp(
Ok(())
}

#[allow(clippy::too_many_arguments)]
pub async fn reconcile_postgres_ing_route_tcp(
cdb: &CoreDB,
ctx: Arc<Context>,
Expand All @@ -247,13 +248,23 @@ pub async fn reconcile_postgres_ing_route_tcp(
service_name: &str,
port: IntOrString,
middleware_names: Vec<String>,
delete: bool,
) -> Result<(), OperatorError> {
let client = ctx.client.clone();
// Initialize kube api for ingress route tcp
let ingress_route_tcp_api: Api<IngressRouteTCP> = Api::namespaced(client, namespace);
let owner_reference = cdb.controller_owner_ref(&()).unwrap();
let ingress_route_tcp_name = format!("{}0", ingress_name_prefix);
let newest_matcher = format!("HostSNI(`{subdomain}.{basedomain}`)");
if delete {
delete_ingress_route_tcp(
ingress_route_tcp_api.clone(),
namespace,
&ingress_route_tcp_name,
)
.await?;
return Ok(());
}

let ingress_route_tcp_to_apply = postgres_ingress_route_tcp(
ingress_route_tcp_name.clone(),
Expand Down

0 comments on commit ed8399a

Please sign in to comment.