fix: K8s ingress module was completely broken, fixed resource definition structure and types

This commit is contained in:
Jean-Gabriel Gill-Couture 2025-06-09 14:00:46 -04:00
parent 6cf61ae67c
commit 8d8120bbfd
2 changed files with 21 additions and 11 deletions

View File

@ -26,7 +26,11 @@ impl K8sClient {
<K as Resource>::Scope: ApplyStrategy<K>,
<K as kube::Resource>::DynamicType: Default,
{
debug!("Applying resource {:?} with ns {:?}", resource.meta().name, ns);
debug!(
"Applying resource {:?} with ns {:?}",
resource.meta().name,
ns
);
trace!("{:#?}", serde_json::to_string(resource));
let api: Api<K> = <<K as Resource>::Scope as ApplyStrategy<K>>::get_api(&self.client, ns);

View File

@ -1,5 +1,6 @@
use harmony_macros::ingress_path;
use k8s_openapi::api::networking::v1::Ingress;
use log::{debug, trace};
use serde::Serialize;
use serde_json::json;
@ -56,22 +57,24 @@ impl<T: Topology + K8sclient> Score<T> for K8sIngressScore {
let ingress = json!(
{
"metadata": {
"name": self.name
"name": self.name.to_string(),
},
"spec": {
"rules": [
{ "host": self.host,
{ "host": self.host.to_string(),
"http": {
"paths": [
{
"path": path,
"pathType": path_type.as_str(),
"backend": [
{
"service": self.backend_service,
"port": self.port
"backend": {
"service": {
"name": self.backend_service.to_string(),
"port": {
"number": self.port,
}
}
]
}
}
]
}
@ -81,13 +84,16 @@ impl<T: Topology + K8sclient> Score<T> for K8sIngressScore {
}
);
trace!("Building ingresss object from Value {ingress:#}");
let ingress: Ingress = serde_json::from_value(ingress).unwrap();
debug!(
"Successfully built Ingress for host {:?}",
ingress.metadata.name
);
Box::new(K8sResourceInterpret {
score: K8sResourceScore::single(
ingress.clone(),
self.namespace
.clone()
.map(|f| f.as_c_str().to_str().unwrap().to_string()),
self.namespace.clone().map(|f| f.to_string()),
),
})
}