Skip to content

Commit

Permalink
fix: Correctly set internal and external urls
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzalezzfelipe committed Oct 30, 2024
1 parent bb418ab commit 66c1225
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
15 changes: 3 additions & 12 deletions src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
22 changes: 20 additions & 2 deletions src/custom_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand All @@ -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()),
Expand Down

0 comments on commit 66c1225

Please sign in to comment.