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 delete ingress objects if stopped #1082

Merged
merged 2 commits into from
Dec 17, 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
167 changes: 86 additions & 81 deletions tembo-operator/src/cloudnativepg/hibernate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,100 +146,105 @@ pub async fn reconcile_cluster_hibernation(cdb: &CoreDB, ctx: &Arc<Context>) ->
}
}

// Remove IngressRoutes for stopped instances
let ingress_route_api: Api<IngressRoute> = Api::namespaced(ctx.client.clone(), &namespace);
if let Err(err) = delete_ingress_route(ingress_route_api.clone(), &namespace, &name).await {
warn!(
"Error deleting app service IngressRoute for {}: {}",
cdb.name_any(),
err
);
return Err(Action::requeue(Duration::from_secs(300)));
}

let metrics_ing_route_name = format!("{}-metrics", cdb.name_any().as_str());
if let Err(err) = delete_ingress_route(
ingress_route_api.clone(),
&namespace,
&metrics_ing_route_name,
)
.await
{
warn!(
"Error deleting metrics IngressRoute for {}: {}",
cdb.name_any(),
err
);
return Err(Action::requeue(Duration::from_secs(300)));
}
if cdb.spec.stop {
// Remove IngressRoutes for stopped instances
let ingress_route_api: Api<IngressRoute> = Api::namespaced(ctx.client.clone(), &namespace);
if let Err(err) = delete_ingress_route(ingress_route_api.clone(), &namespace, &name).await {
warn!(
"Error deleting app service IngressRoute for {}: {}",
cdb.name_any(),
err
);
return Err(Action::requeue(Duration::from_secs(300)));
}

// Remove IngressRouteTCP route for stopped instances
let ingress_route_tcp_api = Api::namespaced(ctx.client.clone(), &namespace);
let prefix_read_only = format!("{}-ro-0", cdb.name_any().as_str());
if let Err(err) =
delete_ingress_route_tcp(ingress_route_tcp_api.clone(), &namespace, &prefix_read_only).await
{
warn!(
"Error deleting postgres IngressRouteTCP for {}: {}",
cdb.name_any(),
err
);
return Err(Action::requeue(Duration::from_secs(300)));
}
let metrics_ing_route_name = format!("{}-metrics", cdb.name_any().as_str());
if let Err(err) = delete_ingress_route(
ingress_route_api.clone(),
&namespace,
&metrics_ing_route_name,
)
.await
{
warn!(
"Error deleting metrics IngressRoute for {}: {}",
cdb.name_any(),
err
);
return Err(Action::requeue(Duration::from_secs(300)));
}

let prefix_read_write = format!("{}-rw-0", cdb.name_any().as_str());
if let Err(err) = delete_ingress_route_tcp(
ingress_route_tcp_api.clone(),
&namespace,
&prefix_read_write,
)
.await
{
warn!(
"Error deleting postgres IngressRouteTCP for {}: {}",
cdb.name_any(),
err
);
return Err(Action::requeue(Duration::from_secs(300)));
}
// Remove IngressRouteTCP route for stopped instances
let ingress_route_tcp_api = Api::namespaced(ctx.client.clone(), &namespace);
let prefix_read_only = format!("{}-ro-0", cdb.name_any().as_str());
if let Err(err) =
delete_ingress_route_tcp(ingress_route_tcp_api.clone(), &namespace, &prefix_read_only)
.await
{
warn!(
"Error deleting postgres IngressRouteTCP for {}: {}",
cdb.name_any(),
err
);
return Err(Action::requeue(Duration::from_secs(300)));
}

let prefix_pooler = format!("{}-pooler-0", cdb.name_any().as_str());
if let Err(err) =
delete_ingress_route_tcp(ingress_route_tcp_api.clone(), &namespace, &prefix_pooler).await
{
warn!(
"Error deleting pooler IngressRouteTCP for {}: {}",
cdb.name_any(),
err
);
return Err(Action::requeue(Duration::from_secs(300)));
}
let prefix_read_write = format!("{}-rw-0", cdb.name_any().as_str());
if let Err(err) = delete_ingress_route_tcp(
ingress_route_tcp_api.clone(),
&namespace,
&prefix_read_write,
)
.await
{
warn!(
"Error deleting postgres IngressRouteTCP for {}: {}",
cdb.name_any(),
err
);
return Err(Action::requeue(Duration::from_secs(300)));
}

let ferret_ing = format!("{}-fdb-api", cdb.name_any().as_str());
if let Err(err) =
delete_ingress_route_tcp(ingress_route_tcp_api.clone(), &namespace, &ferret_ing).await
{
warn!(
"Error deleting ferretdb IngressRouteTCP for {}: {}",
cdb.name_any(),
err
);
return Err(Action::requeue(Duration::from_secs(300)));
}
let prefix_pooler = format!("{}-pooler-0", cdb.name_any().as_str());
if let Err(err) =
delete_ingress_route_tcp(ingress_route_tcp_api.clone(), &namespace, &prefix_pooler)
.await
{
warn!(
"Error deleting pooler IngressRouteTCP for {}: {}",
cdb.name_any(),
err
);
return Err(Action::requeue(Duration::from_secs(300)));
}

let extra_domain_names = cdb.spec.extra_domains_rw.clone().unwrap_or_default();
if !extra_domain_names.is_empty() {
let prefix_extra = format!("extra-{}-rw", cdb.name_any().as_str());
let ferret_ing = format!("{}-fdb-api", cdb.name_any().as_str());
if let Err(err) =
delete_ingress_route_tcp(ingress_route_tcp_api.clone(), &namespace, &prefix_extra).await
delete_ingress_route_tcp(ingress_route_tcp_api.clone(), &namespace, &ferret_ing).await
{
warn!(
"Error deleting extra postgres IngressRouteTCP for {}: {}",
"Error deleting ferretdb IngressRouteTCP for {}: {}",
cdb.name_any(),
err
);
return Err(Action::requeue(Duration::from_secs(300)));
}

let extra_domain_names = cdb.spec.extra_domains_rw.clone().unwrap_or_default();
if !extra_domain_names.is_empty() {
let prefix_extra = format!("extra-{}-rw", cdb.name_any().as_str());
if let Err(err) =
delete_ingress_route_tcp(ingress_route_tcp_api.clone(), &namespace, &prefix_extra)
.await
{
warn!(
"Error deleting extra postgres IngressRouteTCP for {}: {}",
cdb.name_any(),
err
);
return Err(Action::requeue(Duration::from_secs(300)));
}
}
}

// Stop CNPG reconciliation for hibernated instances.
Expand Down
12 changes: 6 additions & 6 deletions tembo-operator/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4369,19 +4369,19 @@ CREATE EVENT TRIGGER pgrst_watch
assert!(service_items.is_empty());
// should be no Services

// ingress must be gone
// There should be 1 IngressRoute left (metrics)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These assertions were checking for 0 IngressRoutes and 0 IngressRouteTCPs. They were being deleted and re-created before introducing this fix. We expect 1 of each to be present.

let ingresses: Vec<IngressRoute> =
list_resources(client.clone(), cdb_name, &namespace, &default_params, 0)
list_resources(client.clone(), cdb_name, &namespace, &default_params, 1)
.await
.unwrap();
assert_eq!(ingresses.len(), 0);
assert_eq!(ingresses.len(), 1);

// Assert IngressRouteTCP is gone
// There should be 1 IngressRouteTCP left (postgres)
let ingresses_tcp: Vec<IngressRouteTCP> =
list_resources(client.clone(), cdb_name, &namespace, &default_params, 0)
list_resources(client.clone(), cdb_name, &namespace, &default_params, 1)
.await
.unwrap();
assert_eq!(ingresses_tcp.len(), 0);
assert_eq!(ingresses_tcp.len(), 1);

// CLEANUP TEST
// Cleanup CoreDB
Expand Down
Loading