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

Revert "Remove IngressRouteTCP and IngressRoute for Stopped Instances" #1074

Merged
merged 1 commit into from
Dec 13, 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
89 changes: 2 additions & 87 deletions tembo-operator/src/cloudnativepg/hibernate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::cloudnativepg::clusters::{ClusterStatusConditions, ClusterStatusCondi
use crate::cloudnativepg::cnpg::{get_cluster, get_pooler, get_scheduled_backups};
use crate::cloudnativepg::poolers::Pooler;
use crate::cloudnativepg::scheduledbackups::ScheduledBackup;
use crate::ingress::{delete_ingress_route, delete_ingress_route_tcp};
use crate::Error;

use crate::{patch_cdb_status_merge, requeue_normal_with_jitter, Context};
Expand All @@ -14,17 +13,17 @@ use serde_json::json;

use k8s_openapi::api::apps::v1::Deployment;

use super::clusters::Cluster;
use crate::app_service::manager::get_appservice_deployment_objects;
use crate::cloudnativepg::cnpg_utils::{
get_pooler_instances, patch_cluster_merge, patch_pooler_merge, patch_scheduled_backup_merge,
removed_stalled_backups,
};
use crate::ingress_route_crd::IngressRoute;
use std::sync::Arc;
use std::time::Duration;
use tracing::{debug, error, info, warn};

use super::clusters::Cluster;

/// Resolves hibernation in the Cluster and related services of the CoreDB
///
/// If the cluster is in spec.stop state, this will activate the CNPG hibernation
Expand Down Expand Up @@ -146,90 +145,6 @@ 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)));
}

// 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_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 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 postgres 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.
// We should not stop CNPG reconciliation until hibernation is fully completed,
// as the instance may not finish hibernating otherwise.
Expand Down
44 changes: 1 addition & 43 deletions tembo-operator/src/ingress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use kube::{
use regex::Regex;
use std::sync::Arc;

use crate::ingress_route_crd::IngressRoute;
use crate::{
apis::coredb_types::CoreDB,
errors::OperatorError,
Expand Down Expand Up @@ -197,48 +196,7 @@ async fn apply_ingress_route_tcp(
Ok(())
}

pub async fn delete_ingress_route(
ingress_route_api: Api<IngressRoute>,
namespace: &str,
ingress_route_name: &String,
) -> Result<(), OperatorError> {
// Check if the resource exists
if ingress_route_api
.get(&ingress_route_name.clone())
.await
.is_ok()
{
// If it exists, proceed with the deletion
let delete_parameters = DeleteParams::default();
match ingress_route_api
.delete(&ingress_route_name.clone(), &delete_parameters)
.await
{
Ok(_) => {
info!(
"Deleted IngressRoute {}.{}",
ingress_route_name.clone(),
namespace
);
}
Err(e) => {
error!(
"Failed to delete IngressRoute {}.{}: {}",
ingress_route_name, namespace, e
);
return Err(OperatorError::IngressRouteError);
}
}
} else {
debug!(
"IngressRoute {}.{} was not found. Assuming it's already deleted.",
ingress_route_name, namespace
);
}
Ok(())
}

pub async fn delete_ingress_route_tcp(
async fn delete_ingress_route_tcp(
ingress_route_tcp_api: Api<IngressRouteTCP>,
namespace: &str,
ingress_route_tcp_name: &String,
Expand Down
Loading