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

Update matcher #431

Merged
merged 9 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
7 changes: 4 additions & 3 deletions tembo-operator/src/app_service/ingress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ pub fn generate_ingress_tcp_routes(
appsvc: &AppService,
resource_name: &str,
namespace: &str,
host_matcher: String,
host_matcher_tcp: String,
coredb_name: &str,
) -> Option<Vec<IngressRouteTCPRoutes>> {
match appsvc.routing.clone() {
Expand All @@ -269,7 +269,7 @@ pub fn generate_ingress_tcp_routes(
continue;
}

let matcher = format!("{host_matcher} && PathPrefix(`{}`)", path);
let matcher = format!("{}", host_matcher_tcp);
ChuckHend marked this conversation as resolved.
Show resolved Hide resolved
let middlewares: Option<Vec<IngressRouteTCPRoutesMiddlewares>> =
route.middlewares.clone().map(|names| {
names
Expand Down Expand Up @@ -398,9 +398,10 @@ pub async fn reconcile_ingress_tcp(
desired_routes: Vec<IngressRouteTCPRoutes>,
desired_middlewares: Vec<Middleware>,
entry_points_tcp: Vec<String>,
app_name: &str,
) -> Result<(), kube::Error> {
let ingress_api: Api<IngressRouteTCP> = Api::namespaced(client.clone(), ns);
let name = format!("{}-apps", coredb_name);
let name = format!("{}-{}", coredb_name, app_name);
Copy link
Member

Choose a reason for hiding this comment

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

👌


let middleware_api: Api<TraefikMiddleware> = Api::namespaced(client.clone(), ns);
let desired_middlewares = generate_middlewares(&name, ns, oref.clone(), desired_middlewares);
Expand Down
58 changes: 36 additions & 22 deletions tembo-operator/src/app_service/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,15 @@ fn generate_resource(
host_matcher.clone(),
coredb_name,
);

let host_matcher_tcp = format!(
"HostSNI(`{subdomain}.{domain}`)",
subdomain = coredb_name,
domain = domain
);

let ingress_tcp_routes =
generate_ingress_tcp_routes(appsvc, &resource_name, namespace, host_matcher, coredb_name);
generate_ingress_tcp_routes(appsvc, &resource_name, namespace, host_matcher_tcp, coredb_name);
// fetch entry points where ingress type is http
let entry_points: Option<Vec<String>> = appsvc.routing.as_ref().map(|routes| {
routes
Expand Down Expand Up @@ -633,6 +640,9 @@ pub async fn reconcile_app_services(cdb: &CoreDB, ctx: Arc<Context>) -> Result<(
"localhost".to_string()
}
};

// Iterate over each AppService and process routes

let resources: Vec<AppServiceResources> = appsvcs
.iter()
.map(|appsvc| generate_resource(appsvc, &coredb_name, &ns, oref.clone(), domain.to_owned()))
Expand Down Expand Up @@ -692,29 +702,33 @@ pub async fn reconcile_app_services(cdb: &CoreDB, ctx: Arc<Context>) -> Result<(
}
}

match reconcile_ingress_tcp(
client.clone(),
&coredb_name,
&ns,
oref.clone(),
desired_tcp_routes,
desired_middlewares,
desired_entry_points_tcp,
)
.await
{
Ok(_) => {
debug!("Updated/applied IngressRouteTCP for {}.{}", ns, coredb_name,);
}
Err(e) => {
error!(
"Failed to update/apply IngressRouteTCP {}.{}: {}",
ns, coredb_name, e
);
has_errors = true;
for appsvc in appsvcs.iter() {
Copy link
Member

Choose a reason for hiding this comment

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

As a follow-up, let's make sure the expected IngressRouteTCP resources are created when we have multiple apps that use IngressType: tcp

let app_name = appsvc.name.clone();

match reconcile_ingress_tcp(
client.clone(),
&coredb_name,
&ns,
oref.clone(),
desired_tcp_routes.clone(),
desired_middlewares.clone(),
desired_entry_points_tcp.clone(),
&app_name,
)
.await
{
Ok(_) => {
debug!("Updated/applied IngressRouteTCP for {}.{}", ns, coredb_name,);
}
Err(e) => {
error!(
"Failed to update/apply IngressRouteTCP {}.{}: {}",
ns, coredb_name, e
);
has_errors = true;
}
}
}

if has_errors || apply_errored {
return Err(Action::requeue(Duration::from_secs(300)));
}
Expand Down
7 changes: 2 additions & 5 deletions tembo-operator/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3170,7 +3170,7 @@ mod test {
);

// Check for IngressRouteTCP
let ing_name = format!("{}-apps", cdb_name);
let ing_name = format!("{cdb_name}-ferretdb");
let ingresses_tcp: Result<Vec<IngressRouteTCP>, errors::OperatorError> =
list_resources(client.clone(), &ing_name, &namespace, 1).await;
let ingress_tcp = ingresses_tcp.unwrap();
Expand All @@ -3179,10 +3179,7 @@ mod test {
let routes_tcp = ingress_route_tcp.spec.clone().routes.clone();
assert_eq!(routes.len(), 1);
let route_tcp = routes_tcp[0].clone();
assert_eq!(
route_tcp.r#match,
format!("Host(`{}.localhost`) && PathPrefix(`/ferretdb/v1`)", cdb_name)
);
assert_eq!(route_tcp.r#match, format!("HostSNI(`{}.localhost`)", cdb_name));

// Assert entry_points includes only ferretdb
assert_eq!(
Expand Down
Loading