Skip to content

Commit

Permalink
Move check to reconcile_ingress_tcp
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Stanton <ian@tembo.io>
  • Loading branch information
ianstanton committed Dec 19, 2024
1 parent e5353a5 commit 59bee60
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 43 deletions.
39 changes: 27 additions & 12 deletions tembo-operator/src/app_service/ingress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,6 @@ pub async fn reconcile_ingress_tcp(
}
}

let ingress = generate_ingress_tcp(&name, ns, oref, desired_routes.clone(), entry_points_tcp);
if desired_routes.is_empty() {
// we don't need an IngressRouteTCP when there are no routes
let lp = ListParams::default().labels("component=appService");
Expand Down Expand Up @@ -488,18 +487,34 @@ pub async fn reconcile_ingress_tcp(
}
return Ok(());
}
match apply_ingress_route_tcp(ingress_api, &name, &ingress).await {
Ok(_) => {
debug!("Updated/applied IngressRouteTCP for {}.{}", ns, &name,);
Ok(())
}
Err(e) => {
error!(
"Failed to update/apply IngressRouteTCP {}.{}: {}",
ns, &name, e
);
Err(e)

// Only create IngressRouteTCP if there are routes for apps that need them. Check if the app
// name is in the desired_routes.
if desired_routes.iter().any(|r| {
r.services
.as_ref()
.unwrap_or(&vec![])
.iter()
.any(|s| s.name == name)
}) {
let ingress_tcp =
generate_ingress_tcp(&name, ns, oref, desired_routes.clone(), entry_points_tcp);
match apply_ingress_route_tcp(ingress_api, &name, &ingress_tcp).await {
Ok(_) => {
debug!("Updated/applied IngressRouteTCP for {}.{}", ns, &name,);
Ok(())
}
Err(e) => {
error!(
"Failed to update/apply IngressRouteTCP {}.{}: {}",
ns, &name, e
);
Err(e)
}
}
} else {
debug!("No IngressRouteTCP routes match the app name: {}", app_name);
Ok(())
}
}

Expand Down
54 changes: 23 additions & 31 deletions tembo-operator/src/app_service/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,37 +1010,29 @@ pub async fn reconcile_app_services(
for appsvc in appsvcs.iter() {
let app_name = appsvc.name.clone();

// Only reconcile IngressRouteTCP if the AppService has a TCP route
if appsvc.routing.is_some() {
for route in appsvc.routing.as_ref().unwrap() {
if route.ingress_type == Some(IngressType::tcp) {
match reconcile_ingress_tcp(
client.clone(),
&coredb_name,
&ns,
oref.clone(),
desired_tcp_routes.clone(),
vec![],
desired_entry_points_tcp.clone(),
&app_name,
)
.await
{
Ok(_) => {
debug!(
"Updated/applied IngressRouteTCP for {}.{}",
ns, coredb_name,
);
}
Err(e) => {
error!(
"Failed to update/apply IngressRouteTCP {}.{}: {}",
ns, coredb_name, e
);
has_errors = true;
}
}
}
match reconcile_ingress_tcp(
client.clone(),
&coredb_name,
&ns,
oref.clone(),
desired_tcp_routes.clone(),
// TODO: fill with actual MiddlewareTCPs when it is supported
// first supported MiddlewareTCP will be for custom domains
vec![],
desired_entry_points_tcp.clone(),
&app_name,
)
.await
{
Ok(_) => {
debug!("Updated/applied IngressRouteTCP for {}.{}", ns, coredb_name,);
}
Err(e) => {
error!(
"Failed to update/apply IngressRouteTCP {}.{}: {}",
ns, coredb_name, e
);
has_errors = true;
}
}
}
Expand Down

0 comments on commit 59bee60

Please sign in to comment.