diff --git a/tembo-operator/src/app_service/ingress.rs b/tembo-operator/src/app_service/ingress.rs index 68a497aa0..d59a1a89a 100644 --- a/tembo-operator/src/app_service/ingress.rs +++ b/tembo-operator/src/app_service/ingress.rs @@ -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"); @@ -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(()) } } diff --git a/tembo-operator/tests/integration_tests.rs b/tembo-operator/tests/integration_tests.rs index a9d4659f8..af3d9da72 100644 --- a/tembo-operator/tests/integration_tests.rs +++ b/tembo-operator/tests/integration_tests.rs @@ -6131,6 +6131,19 @@ CREATE EVENT TRIGGER pgrst_watch ); } + // Assert there are 3 IngressRouteTCPs created after starting. One for postgres, pooler, + // ferretdb + let client = test.client.clone(); + let ingresses_tcp: Vec = + list_resources(client.clone(), &name, &namespace, &default_params, 3) + .await + .unwrap(); + assert_eq!( + ingresses_tcp.len(), + 3, + "IngressRouteTCPs should be created after starting" + ); + // Stop the cluster and check to make sure it's not running to ensure // hibernate is doing its job. @@ -6146,16 +6159,14 @@ CREATE EVENT TRIGGER pgrst_watch assert_eq!(pods_list.items.len(), 0); // Assert that IngressRouteTCPs are removed after hibernation - // TODO(ianstanton) Typically there should be 0 here, but we're creating one for postgrest - // due to a bug. This should be updated to 0 after the bug is fixed. let client = test.client.clone(); let ingresses_tcp: Vec = - list_resources(client.clone(), &name, &namespace, &default_params, 1) + list_resources(client.clone(), &name, &namespace, &default_params, 0) .await .unwrap(); assert_eq!( ingresses_tcp.len(), - 1, + 0, "IngressRouteTCPs should be removed after hibernation" ); @@ -6205,17 +6216,15 @@ CREATE EVENT TRIGGER pgrst_watch ); } - // Assert there are 4 IngressRouteTCPs created after starting. One for postgres, pooler, - // ferretdb and postgrest - // TODO(ianstanton) postgrest's IngressRouteTCP is being created due to a bug. This should - // check for 3 IngressRouteTCPs after the bug is fixed. + // Assert there are 3 IngressRouteTCPs created after starting. One for postgres, pooler, + // ferretdb let ingress_tcps: Vec = - list_resources(client.clone(), &name, &namespace, &default_params, 4) + list_resources(client.clone(), &name, &namespace, &default_params, 3) .await .unwrap(); assert_eq!( ingress_tcps.len(), - 4, + 3, "IngressRouteTCPs should be created after starting" );