Skip to content

Commit 424f302

Browse files
committed
lookup waypoint svc by proxy port
avoids needing the service to specify the zTunnel's HBONE port
1 parent 478c99d commit 424f302

File tree

2 files changed

+46
-21
lines changed

2 files changed

+46
-21
lines changed

src/proxy/outbound.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,18 @@ impl OutboundConnection {
432432
self.pi.metrics.clone(),
433433
)
434434
.await?;
435-
let wp_socket_addr = SocketAddr::new(waypoint_ip, waypoint_us.port);
435+
436+
// For sandwich, the inbound side resolves the waypoints port.
437+
// When using PROXY we want to use the Waypoint's zTunnel
438+
// TODO tunnel protocol should hint this to allow PROXY + HBONE?
439+
let wp_port = mutable_us
440+
.workload
441+
.waypoint
442+
.as_ref()
443+
.map(|w| w.proxy_protocol_port)
444+
.map_or_else(|| waypoint_us.port, |_| self.pi.hbone_port);
445+
446+
let wp_socket_addr = SocketAddr::new(waypoint_ip, wp_port);
436447
return Ok(Request {
437448
// Always use HBONE here
438449
protocol: Protocol::HBONE,

src/state.rs

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -451,15 +451,16 @@ impl DemandProxyState {
451451
target_addr: &NetworkAddress,
452452
waypoint_addr: &NetworkAddress,
453453
) -> Option<GatewayAddress> {
454-
let fetch =
455-
|target_addr: &NetworkAddress, waypoint_addr: &NetworkAddress| -> Result<Option<GatewayAddress>, Error> {
456-
let state = self.state.read().unwrap();
454+
let fetch = |target_addr: &NetworkAddress,
455+
waypoint_addr: &NetworkAddress|
456+
-> Result<Option<GatewayAddress>, Error> {
457+
let state = self.state.read().unwrap();
457458

458-
// Collect all the possible waypoints for the target.
459-
let Some(target) = state.find_address(target_addr) else {
459+
// Collect all the possible waypoints for the target.
460+
let Some(target) = state.find_address(target_addr) else {
460461
return Err(Error::UnknownDestination(target_addr.address));
461462
};
462-
let Some(mut target_waypoints) = (match target {
463+
let Some(mut target_waypoints) = (match target {
463464
Address::Workload(wl) => wl
464465
.waypoint
465466
.map(|addr| vec![(addr.destination.clone(), (1, addr))].into_iter().collect()),
@@ -468,27 +469,35 @@ impl DemandProxyState {
468469
debug!("No waypoints for target workload: {target_addr}");
469470
return Ok(None);
470471
};
471-
if target_waypoints.is_empty() {
472-
debug!("No waypoints for target service: {target_addr}");
473-
return Ok(None);
474-
}
472+
if target_waypoints.is_empty() {
473+
debug!("No waypoints for target service: {target_addr}");
474+
return Ok(None);
475+
}
475476

476-
// Waypoint instance is referenced directly
477-
if let Some((_, gw_addr)) = target_waypoints.remove(&Destination::Address(waypoint_addr.clone())) {
478-
return Ok(Some(gw_addr));
479-
}
477+
// Waypoint instance is referenced directly
478+
if let Some((_, gw_addr)) =
479+
target_waypoints.remove(&Destination::Address(waypoint_addr.clone()))
480+
{
481+
return Ok(Some(gw_addr));
482+
}
480483

481-
// Waypoint is referenced by the service it's part of
482-
Ok(state.workloads.find_address(waypoint_addr).map(|wl| {
484+
// Waypoint is referenced by the service it's part of
485+
Ok(state
486+
.workloads
487+
.find_address(waypoint_addr)
488+
.map(|wl| {
483489
state
484490
.services
485491
.get_by_workload(&wl)
486492
.iter()
487493
.flat_map(|svc| &svc.vips)
488-
.find_map(|wp_vip| target_waypoints.remove(&Destination::Address(wp_vip.clone())))
494+
.find_map(|wp_vip| {
495+
target_waypoints.remove(&Destination::Address(wp_vip.clone()))
496+
})
489497
.map(|el| el.1)
490-
}).flatten())
491-
};
498+
})
499+
.flatten())
500+
};
492501
if let Ok(result) = fetch(target_addr, waypoint_addr) {
493502
return result;
494503
}
@@ -565,7 +574,12 @@ impl DemandProxyState {
565574
));
566575
}
567576
};
568-
let wp_socket_addr = SocketAddr::new(wp_nw_addr.address, gw_address.hbone_mtls_port);
577+
let wp_socket_addr = SocketAddr::new(
578+
wp_nw_addr.address,
579+
gw_address
580+
.proxy_protocol_port
581+
.unwrap_or(gw_address.hbone_mtls_port),
582+
);
569583
match self
570584
.fetch_upstream(&wp_nw_addr.network, wp_socket_addr)
571585
.await

0 commit comments

Comments
 (0)