From 3ca42b30f02049c9101bc7b25202c66c1d5b65c1 Mon Sep 17 00:00:00 2001 From: tahahawa Date: Wed, 14 May 2025 23:26:05 -0400 Subject: [PATCH] use FQDN which makes sure things conform to RFC 1035, as k8s spec says it should --- Cargo.lock | 17 +++++++++++++++++ harmony/Cargo.toml | 8 ++++++++ harmony/src/modules/k8s/ingress.rs | 10 +++++----- harmony/src/modules/lamp.rs | 9 +++++---- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f84d847..ea6c0c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1172,6 +1172,16 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fqdn" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0f5d7f7b3eed2f771fc7f6fcb651f9560d7b0c483d75876082acb4649d266b3" +dependencies = [ + "punycode", + "serde", +] + [[package]] name = "funty" version = "2.0.0" @@ -1397,6 +1407,7 @@ dependencies = [ "directories", "dockerfile_builder", "env_logger", + "fqdn", "harmony_macros", "harmony_types", "helm-wrapper-rs", @@ -3016,6 +3027,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "punycode" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9e1dcb320d6839f6edb64f7a4a59d39b30480d4d1765b56873f7c858538a5fe" + [[package]] name = "quote" version = "1.0.40" diff --git a/harmony/Cargo.toml b/harmony/Cargo.toml index 02a0ce7..a079bd6 100644 --- a/harmony/Cargo.toml +++ b/harmony/Cargo.toml @@ -39,3 +39,11 @@ lazy_static = "1.5.0" dockerfile_builder = "0.1.5" temp-file = "0.1.9" convert_case.workspace = true +fqdn = { version = "0.4.6", features = [ + "domain-label-cannot-start-or-end-with-hyphen", + "domain-label-length-limited-to-63", + "domain-name-without-special-chars", + "domain-name-length-limited-to-255", + "punycode", + "serde", +] } diff --git a/harmony/src/modules/k8s/ingress.rs b/harmony/src/modules/k8s/ingress.rs index fb511a7..76fd987 100644 --- a/harmony/src/modules/k8s/ingress.rs +++ b/harmony/src/modules/k8s/ingress.rs @@ -12,10 +12,10 @@ use super::resource::{K8sResourceInterpret, K8sResourceScore}; #[derive(Debug, Clone, Serialize)] pub struct K8sIngressScore { - pub name: String, - pub host: String, - pub backend_service: String, - pub port: String, + pub name: fqdn::FQDN, + pub host: fqdn::FQDN, + pub backend_service: fqdn::FQDN, + pub port: u16, pub path: Option, pub path_type: Option, pub namespace: Option, @@ -67,6 +67,6 @@ impl Score for K8sIngressScore { } fn name(&self) -> String { - "K8sIngressScore".to_string() + format!("{} K8sIngressScore", self.name) } } diff --git a/harmony/src/modules/lamp.rs b/harmony/src/modules/lamp.rs index f1e3fe8..157334c 100644 --- a/harmony/src/modules/lamp.rs +++ b/harmony/src/modules/lamp.rs @@ -1,6 +1,7 @@ use convert_case::{Case, Casing}; use dockerfile_builder::instruction::{CMD, COPY, ENV, EXPOSE, FROM, RUN, WORKDIR}; use dockerfile_builder::{Dockerfile, instruction_builder::EnvBuilder}; +use fqdn::fqdn; use non_blank_string_rs::NonBlankString; use serde_json::json; use std::collections::HashMap; @@ -134,10 +135,10 @@ impl Interpret for LAMPInterpret { info!("LAMP deployment_score {deployment_score:?}"); let lamp_ingress = K8sIngressScore { - name: "lamp-ingress".to_string(), - host: "test".to_string(), - backend_service: "test".to_string(), - port: "8080".to_string(), + name: fqdn!("lamp-ingress"), + host: fqdn!("test"), + backend_service: fqdn!("test"), + port: 8080, path: None, path_type: None, namespace: self.get_namespace().map(|nbs| nbs.to_string()),