Skip to content

Commit 32e459b

Browse files
authored
Update profile response to include a logical address (#954)
Profile responses optionally include a service name, but we only ever use it in the context of an address (i.e. with a port). This change introduces a `profiles::LookupAddr` param type that is used as input into the profile client -- the lookup address may hold either a named or numbered address. Service profile responses now include a `LogicalAddr` that must be a named address. This sets up for requiring that concrete addresses are named.
1 parent affd645 commit 32e459b

File tree

21 files changed

+174
-109
lines changed

21 files changed

+174
-109
lines changed

linkerd/app/gateway/src/gateway.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ where
6161
None => return Gateway::NoIdentity,
6262
};
6363

64-
let dst = match profile.as_ref().and_then(|p| p.borrow().name.clone()) {
65-
Some(name) => NameAddr::from((name, http.target.port())),
64+
let dst = match profile.as_ref().and_then(|p| p.borrow().addr.clone()) {
65+
Some(profiles::LogicalAddr(addr)) => addr,
6666
None => return Gateway::BadDomain(http.target.name().clone()),
6767
};
6868

linkerd/app/gateway/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ where
8484
O::Response:
8585
io::AsyncRead + io::AsyncWrite + tls::HasNegotiatedProtocol + Send + Unpin + 'static,
8686
O::Future: Send + Unpin + 'static,
87-
P: profiles::GetProfile<profiles::LogicalAddr> + Clone + Send + Sync + Unpin + 'static,
87+
P: profiles::GetProfile<profiles::LookupAddr> + Clone + Send + Sync + Unpin + 'static,
8888
P::Future: Send + 'static,
8989
P::Error: Send,
9090
R: Clone + Send + Sync + Unpin + 'static,
@@ -116,7 +116,7 @@ where
116116
.push_tcp_logical(resolve.clone())
117117
.into_stack()
118118
.push_request_filter(|(p, _): (Option<profiles::Receiver>, _)| match p {
119-
Some(rx) if rx.borrow().name.is_some() => Ok(outbound::tcp::Logical {
119+
Some(rx) if rx.borrow().addr.is_some() => Ok(outbound::tcp::Logical {
120120
profile: Some(rx),
121121
orig_dst: OrigDstAddr(std::net::SocketAddr::from(([0, 0, 0, 0], 0))),
122122
protocol: (),
@@ -127,7 +127,7 @@ where
127127
let allow = allow_discovery.clone();
128128
move |addr: NameAddr| {
129129
if allow.matches(addr.name()) {
130-
Ok(profiles::LogicalAddr(addr.into()))
130+
Ok(profiles::LookupAddr(addr.into()))
131131
} else {
132132
Err(RefusedNotResolved(addr))
133133
}
@@ -162,7 +162,7 @@ where
162162
.push(NewGateway::layer(local_id))
163163
.push(profiles::discover::layer(profiles, move |t: HttpTarget| {
164164
if allow_discovery.matches(t.target.name()) {
165-
Ok(profiles::LogicalAddr(t.target.into()))
165+
Ok(profiles::LookupAddr(t.target.into()))
166166
} else {
167167
Err(RefusedNotResolved(t.target))
168168
}

linkerd/app/gateway/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl Test {
104104
let allow = NameMatch::new(Some(dns::Suffix::from_str(suffix).unwrap()));
105105
let profile = if allow.matches(target.name()) {
106106
Some(support::profile::only(profiles::Profile {
107-
name: Some(target.name().clone()),
107+
addr: Some(target.clone().into()),
108108
..profiles::Profile::default()
109109
}))
110110
} else {

linkerd/app/inbound/src/allow_discovery.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
use crate::target::Target;
22
use linkerd_app_core::{
3-
discovery_rejected, profiles::LogicalAddr, svc::stack::Predicate, Error, NameMatch,
3+
discovery_rejected, profiles::LookupAddr, svc::stack::Predicate, Error, NameMatch,
44
};
55

66
#[derive(Clone, Debug)]
77
pub struct AllowProfile(pub NameMatch);
88

99
impl Predicate<Target> for AllowProfile {
10-
type Request = LogicalAddr;
10+
type Request = LookupAddr;
1111

12-
fn check(&mut self, target: Target) -> Result<LogicalAddr, Error> {
12+
fn check(&mut self, target: Target) -> Result<LookupAddr, Error> {
1313
let addr = target.dst.into_name_addr().ok_or_else(discovery_rejected)?;
1414
if self.0.matches(addr.name()) {
15-
Ok(LogicalAddr(addr.into()))
15+
Ok(LookupAddr(addr.into()))
1616
} else {
1717
Err(discovery_rejected().into())
1818
}

linkerd/app/inbound/src/http/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ where
115115
> + Clone,
116116
>
117117
where
118-
P: profiles::GetProfile<profiles::LogicalAddr> + Clone + Send + Sync + 'static,
118+
P: profiles::GetProfile<profiles::LookupAddr> + Clone + Send + Sync + 'static,
119119
P::Future: Send,
120120
P::Error: Send,
121121
{

linkerd/app/inbound/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl Inbound<()> {
135135
+ 'static,
136136
GSvc::Error: Into<Error>,
137137
GSvc::Future: Send,
138-
P: profiles::GetProfile<profiles::LogicalAddr> + Clone + Send + Sync + 'static,
138+
P: profiles::GetProfile<profiles::LookupAddr> + Clone + Send + Sync + 'static,
139139
P::Error: Send,
140140
P::Future: Send,
141141
{
@@ -225,7 +225,7 @@ where
225225
GSvc: svc::Service<direct::GatewayIo<I>, Response = ()> + Send + 'static,
226226
GSvc::Error: Into<Error>,
227227
GSvc::Future: Send,
228-
P: profiles::GetProfile<profiles::LogicalAddr> + Clone + Send + Sync + 'static,
228+
P: profiles::GetProfile<profiles::LookupAddr> + Clone + Send + Sync + 'static,
229229
P::Error: Send,
230230
P::Future: Send,
231231
{

linkerd/app/inbound/src/target.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ impl From<Logical> for Target {
207207
}
208208
}
209209

210-
impl Param<profiles::LogicalAddr> for Target {
211-
fn param(&self) -> profiles::LogicalAddr {
212-
profiles::LogicalAddr(self.dst.clone())
210+
impl Param<profiles::LookupAddr> for Target {
211+
fn param(&self) -> profiles::LookupAddr {
212+
profiles::LookupAddr(self.dst.clone())
213213
}
214214
}
215215

linkerd/app/outbound/src/discover.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl<N> Outbound<N> {
2525
N: svc::NewService<tcp::Logical, Service = NSvc> + Clone + Send + 'static,
2626
NSvc: svc::Service<SensorIo<I>, Response = (), Error = Error> + Send + 'static,
2727
NSvc::Future: Send,
28-
P: profiles::GetProfile<profiles::LogicalAddr> + Clone + Send + 'static,
28+
P: profiles::GetProfile<profiles::LookupAddr> + Clone + Send + 'static,
2929
P::Future: Send,
3030
P::Error: Send,
3131
{
@@ -73,11 +73,11 @@ struct AllowProfile(pub IpMatch);
7373
// === impl AllowProfile ===
7474

7575
impl svc::stack::Predicate<tcp::Accept> for AllowProfile {
76-
type Request = profiles::LogicalAddr;
76+
type Request = profiles::LookupAddr;
7777

78-
fn check(&mut self, a: tcp::Accept) -> Result<profiles::LogicalAddr, Error> {
78+
fn check(&mut self, a: tcp::Accept) -> Result<profiles::LookupAddr, Error> {
7979
if self.0.matches(a.orig_dst.0.ip()) {
80-
Ok(profiles::LogicalAddr(a.orig_dst.0.into()))
80+
Ok(profiles::LookupAddr(a.orig_dst.0.into()))
8181
} else {
8282
Err(discovery_rejected().into())
8383
}

linkerd/app/outbound/src/http/endpoint.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ impl<C> Outbound<C> {
5252
// HTTP/1.x fallback is supported as needed.
5353
let stack = connect
5454
.push(http::client::layer(h1_settings, h2_settings))
55+
.check_service::<T>()
5556
// Re-establishes a connection when the client fails.
5657
.push(reconnect::layer({
5758
let backoff = backoff;

linkerd/app/outbound/src/http/logical.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl<E> Outbound<E> {
178178
let should_resolve = match logical.profile.as_ref() {
179179
Some(p) => {
180180
let p = p.borrow();
181-
p.endpoint.is_none() && (p.name.is_some() || !p.targets.is_empty())
181+
p.endpoint.is_none() && (p.addr.is_some() || !p.targets.is_empty())
182182
}
183183
None => false,
184184
};

0 commit comments

Comments
 (0)