Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only reconcile ing tcp for apps with tcp route #1079

Merged
merged 7 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -6062,6 +6062,19 @@ CREATE EVENT TRIGGER pgrst_watch
let pods_list = pods.list(&Default::default()).await.unwrap();
assert_eq!(pods_list.items.len(), 4);

// 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 @@ -6077,16 +6090,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 @@ -6115,17 +6126,15 @@ CREATE EVENT TRIGGER pgrst_watch
let pods_list = pods.list(&Default::default()).await.unwrap();
assert_eq!(pods_list.items.len(), 4);

// 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