From 2817939b180b63e1fac60cf48e220c94e72aaae3 Mon Sep 17 00:00:00 2001 From: tahahawa Date: Thu, 15 May 2025 11:22:35 -0400 Subject: [PATCH] Create enum for PathType and use FQDN for namespace (RFC 1035 is more strict than RFC 1123, but very similar) --- harmony/src/modules/k8s/ingress.rs | 32 +++++++++++++++++++++++++----- harmony/src/modules/lamp.rs | 4 +++- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/harmony/src/modules/k8s/ingress.rs b/harmony/src/modules/k8s/ingress.rs index 76fd987..b7b5a63 100644 --- a/harmony/src/modules/k8s/ingress.rs +++ b/harmony/src/modules/k8s/ingress.rs @@ -10,6 +10,23 @@ use crate::{ use super::resource::{K8sResourceInterpret, K8sResourceScore}; +#[derive(Debug, Clone, Serialize)] +pub enum PathType { + ImplementationSpecific, + Exact, + Prefix, +} + +impl PathType { + fn as_str(&self) -> &'static str { + match self { + PathType::ImplementationSpecific => "ImplementationSpecific", + PathType::Exact => "Exact", + PathType::Prefix => "Prefix", + } + } +} + #[derive(Debug, Clone, Serialize)] pub struct K8sIngressScore { pub name: fqdn::FQDN, @@ -17,8 +34,8 @@ pub struct K8sIngressScore { pub backend_service: fqdn::FQDN, pub port: u16, pub path: Option, - pub path_type: Option, - pub namespace: Option, + pub path_type: Option, + pub namespace: Option, } impl Score for K8sIngressScore { @@ -29,7 +46,7 @@ impl Score for K8sIngressScore { }; let path_type = match self.path_type.clone() { Some(p) => p, - None => "Prefix".to_string(), + None => PathType::Prefix, }; let ingress = json!( @@ -44,7 +61,7 @@ impl Score for K8sIngressScore { "paths": [ { "path": path, - "pathType": path_type, + "pathType": path_type.as_str(), "backend": [ { "service": self.backend_service, @@ -62,7 +79,12 @@ impl Score for K8sIngressScore { let ingress: Ingress = serde_json::from_value(ingress).unwrap(); Box::new(K8sResourceInterpret { - score: K8sResourceScore::single(ingress.clone(), self.namespace.clone()), + score: K8sResourceScore::single( + ingress.clone(), + self.namespace + .clone() + .map(|f| f.as_c_str().to_str().unwrap().to_string()), + ), }) } diff --git a/harmony/src/modules/lamp.rs b/harmony/src/modules/lamp.rs index 2fbb408..2c96101 100644 --- a/harmony/src/modules/lamp.rs +++ b/harmony/src/modules/lamp.rs @@ -145,7 +145,9 @@ impl Interpret for LAMPInterpret { port: 8080, path: None, path_type: None, - namespace: self.get_namespace().map(|nbs| nbs.to_string()), + namespace: self + .get_namespace() + .map(|nbs| fqdn!(nbs.to_string().as_str())), }; lamp_ingress