use FQDN which makes sure things conform to RFC 1035, as k8s spec says it should

This commit is contained in:
tahahawa 2025-05-14 23:26:05 -04:00
parent ebde55affd
commit 3ca42b30f0
4 changed files with 35 additions and 9 deletions

17
Cargo.lock generated
View File

@ -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"

View File

@ -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",
] }

View File

@ -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<String>,
pub path_type: Option<String>,
pub namespace: Option<String>,
@ -67,6 +67,6 @@ impl<T: Topology + K8sclient> Score<T> for K8sIngressScore {
}
fn name(&self) -> String {
"K8sIngressScore".to_string()
format!("{} K8sIngressScore", self.name)
}
}

View File

@ -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<T: Topology + K8sclient + HelmCommand> Interpret<T> 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()),