Skip to content

Commit 63e911b

Browse files
committed
Respect preferred address type for LoadBalancer and ClusterIP services too
1 parent 380ff9b commit 63e911b

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

rust/operator-binary/src/listener_controller.rs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ use stackable_operator::{
2828
};
2929
use strum::IntoStaticStr;
3030

31-
use crate::{csi_server::node::NODE_TOPOLOGY_LABEL_HOSTNAME, utils::node_primary_address};
31+
use crate::{
32+
csi_server::node::NODE_TOPOLOGY_LABEL_HOSTNAME,
33+
utils::{node_primary_address, AddressCandidates},
34+
};
3235

3336
#[cfg(doc)]
3437
use stackable_operator::k8s_openapi::api::core::v1::Pod;
@@ -269,6 +272,7 @@ pub async fn reconcile(listener: Arc<Listener>, ctx: Arc<Ctx>) -> Result<control
269272
})?;
270273

271274
let nodes: Vec<Node>;
275+
let kubernetes_service_fqdn: String;
272276
let addresses: Vec<(&str, AddressType)>;
273277
let ports: BTreeMap<String, i32>;
274278
match listener_class.spec.service_type {
@@ -306,11 +310,11 @@ pub async fn reconcile(listener: Arc<Listener>, ctx: Arc<Ctx>) -> Result<control
306310
.flat_map(|ss| ss.load_balancer.as_ref()?.ingress.as_ref())
307311
.flatten()
308312
.flat_map(|ingress| {
309-
ingress
310-
.hostname
311-
.as_deref()
312-
.zip(Some(AddressType::Hostname))
313-
.or_else(|| ingress.ip.as_deref().zip(Some(AddressType::Ip)))
313+
AddressCandidates {
314+
ip: ingress.ip.as_deref(),
315+
hostname: ingress.hostname.as_deref(),
316+
}
317+
.pick(listener_class.spec.preferred_address_type)
314318
})
315319
.collect();
316320
ports = svc
@@ -323,13 +327,19 @@ pub async fn reconcile(listener: Arc<Listener>, ctx: Arc<Ctx>) -> Result<control
323327
.collect();
324328
}
325329
ServiceType::ClusterIP => {
326-
addresses = svc
327-
.spec
328-
.iter()
329-
.flat_map(|s| &s.cluster_ips)
330-
.flatten()
331-
.map(|addr| (&**addr, AddressType::Ip))
332-
.collect::<Vec<_>>();
330+
addresses = match listener_class.spec.preferred_address_type {
331+
AddressType::Ip => svc
332+
.spec
333+
.iter()
334+
.flat_map(|s| &s.cluster_ips)
335+
.flatten()
336+
.map(|addr| (&**addr, AddressType::Ip))
337+
.collect::<Vec<_>>(),
338+
AddressType::Hostname => {
339+
kubernetes_service_fqdn = format!("{svc_name}.{ns}.svc.cluster.local");
340+
vec![(&kubernetes_service_fqdn, AddressType::Hostname)]
341+
}
342+
};
333343
ports = svc
334344
.spec
335345
.as_ref()

0 commit comments

Comments
 (0)