From 66c1225583a4474bd44a28f95e23b9cae0dc8f64 Mon Sep 17 00:00:00 2001 From: gonzalezzfelipe Date: Wed, 30 Oct 2024 19:26:37 -0300 Subject: [PATCH] fix: Correctly set internal and external urls --- src/controller.rs | 15 +++------------ src/custom_resource.rs | 22 ++++++++++++++++++++-- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/controller.rs b/src/controller.rs index d05f720..060b01e 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -129,20 +129,11 @@ impl K8sContext { // Create or patch the deployment let status = serde_json::to_value(HydraDoomNodeStatus { - local_url: format!( - "ws://{}.{}.svc.cluster.local:{}", - crd.name_any(), - crd.namespace().unwrap(), - self.constants.port - ), - external_url: format!( - "wss://{}.{}:{}", - crd.name_any(), - self.config.external_domain, - self.config.external_port - ), + local_url: crd.internal_url(&self.config, &self.constants), + external_url: crd.external_url(&self.config, &self.constants), }) .unwrap(); + api.patch( &crd.name_any(), &PatchParams::default(), diff --git a/src/custom_resource.rs b/src/custom_resource.rs index 026b4ef..fac212d 100644 --- a/src/custom_resource.rs +++ b/src/custom_resource.rs @@ -68,6 +68,24 @@ impl HydraDoomNode { ]) } + pub fn internal_url(&self, _config: &Config, constants: &K8sConstants) -> String { + format!( + "ws://{}.{}.svc.cluster.local:{}", + self.name_any(), + self.namespace().unwrap(), + constants.port + ) + } + + pub fn external_url(&self, config: &Config, _constants: &K8sConstants) -> String { + format!( + "ws://{}.{}:{}", + self.name_any(), + config.external_domain, + config.external_port + ) + } + pub fn deployment(&self, config: &Config, constants: &K8sConstants) -> Deployment { let name = self.internal_name(); let labels = self.internal_labels(); @@ -237,7 +255,7 @@ impl HydraDoomNode { } } - pub fn ingress(&self, _config: &Config, constants: &K8sConstants) -> Ingress { + pub fn ingress(&self, config: &Config, constants: &K8sConstants) -> Ingress { let name = self.internal_name(); Ingress { metadata: ObjectMeta { @@ -248,7 +266,7 @@ impl HydraDoomNode { spec: Some(IngressSpec { ingress_class_name: Some(constants.ingress_class_name.clone()), rules: Some(vec![IngressRule { - host: Some("aaaaaaaa".to_string()), + host: Some(self.external_url(config, constants)), http: Some(HTTPIngressRuleValue { paths: vec![HTTPIngressPath { path: Some("/".to_string()),