Skip to content

Commit

Permalink
Only reconcile ing tcp for apps with tcp route (#1079)
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Stanton <ian@tembo.io>
  • Loading branch information
ianstanton authored Dec 20, 2024
1 parent d1fc597 commit debfb55
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 22 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
29 changes: 19 additions & 10 deletions tembo-operator/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IngressRouteTCP> =
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.

Expand All @@ -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<IngressRouteTCP> =
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"
);

Expand Down Expand Up @@ -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<IngressRouteTCP> =
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"
);

Expand Down

0 comments on commit debfb55

Please sign in to comment.