mirror of https://github.com/linkerd/linkerd2.git
Add Service backend metadata to outbound policy API (#10513)
When the outbound policy API was returning backends which corresponded to Service resources, those backends were missing metadata information. We update the policy controller to populate Service metadata for those backends. Signed-off-by: Alex Leong <alex@buoyant.io>
This commit is contained in:
parent
08f97cc26f
commit
dbefd38695
|
|
@ -52,8 +52,8 @@ pub struct OutboundHttpRouteRule {
|
|||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum Backend {
|
||||
Addr(WeightedAddr),
|
||||
Dst(WeightedDst),
|
||||
InvalidDst { weight: u32, message: String },
|
||||
Service(WeightedService),
|
||||
Invalid { weight: u32, message: String },
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
|
|
@ -64,9 +64,11 @@ pub struct WeightedAddr {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct WeightedDst {
|
||||
pub struct WeightedService {
|
||||
pub weight: u32,
|
||||
pub authority: String,
|
||||
pub name: String,
|
||||
pub namespace: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
|
|
|
|||
|
|
@ -776,18 +776,26 @@ fn convert_http_backend(backend: Backend) -> outbound::http_route::WeightedRoute
|
|||
}),
|
||||
}
|
||||
}
|
||||
Backend::Dst(dst) => outbound::http_route::WeightedRouteBackend {
|
||||
weight: dst.weight,
|
||||
Backend::Service(svc) => outbound::http_route::WeightedRouteBackend {
|
||||
weight: svc.weight,
|
||||
backend: Some(outbound::http_route::RouteBackend {
|
||||
backend: Some(outbound::Backend {
|
||||
metadata: None,
|
||||
metadata: Some(Metadata {
|
||||
kind: Some(metadata::Kind::Resource(api::meta::Resource {
|
||||
group: "core".to_string(),
|
||||
kind: "Service".to_string(),
|
||||
name: svc.name,
|
||||
namespace: svc.namespace,
|
||||
section: String::default(),
|
||||
})),
|
||||
}),
|
||||
queue: Some(default_queue_config()),
|
||||
kind: Some(outbound::backend::Kind::Balancer(
|
||||
outbound::backend::BalanceP2c {
|
||||
discovery: Some(outbound::backend::EndpointDiscovery {
|
||||
kind: Some(outbound::backend::endpoint_discovery::Kind::Dst(
|
||||
outbound::backend::endpoint_discovery::DestinationGet {
|
||||
path: dst.authority,
|
||||
path: svc.authority,
|
||||
},
|
||||
)),
|
||||
}),
|
||||
|
|
@ -798,7 +806,7 @@ fn convert_http_backend(backend: Backend) -> outbound::http_route::WeightedRoute
|
|||
filters: Default::default(),
|
||||
}),
|
||||
},
|
||||
Backend::InvalidDst { weight, message } => outbound::http_route::WeightedRouteBackend {
|
||||
Backend::Invalid { weight, message } => outbound::http_route::WeightedRouteBackend {
|
||||
weight,
|
||||
backend: Some(outbound::http_route::RouteBackend {
|
||||
backend: None,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use ahash::AHashMap as HashMap;
|
|||
use anyhow::Result;
|
||||
use k8s_gateway_api::{BackendObjectReference, HttpBackendRef, ParentReference};
|
||||
use linkerd_policy_controller_core::{
|
||||
http_route::{Backend, OutboundHttpRoute, OutboundHttpRouteRule, WeightedDst},
|
||||
http_route::{Backend, OutboundHttpRoute, OutboundHttpRouteRule, WeightedService},
|
||||
OutboundPolicy,
|
||||
};
|
||||
use linkerd_policy_controller_k8s_api::{
|
||||
|
|
@ -320,7 +320,7 @@ fn convert_backend(
|
|||
) -> Option<Backend> {
|
||||
backend.backend_ref.map(|backend| {
|
||||
if !is_backend_service(&backend.inner) {
|
||||
return Backend::InvalidDst {
|
||||
return Backend::Invalid {
|
||||
weight: backend.weight.unwrap_or(1).into(),
|
||||
message: format!(
|
||||
"unsupported backend type {group} {kind}",
|
||||
|
|
@ -343,7 +343,7 @@ fn convert_backend(
|
|||
{
|
||||
Some(port) => port,
|
||||
None => {
|
||||
return Backend::InvalidDst {
|
||||
return Backend::Invalid {
|
||||
weight: weight.into(),
|
||||
message: format!("missing port for backend Service {name}"),
|
||||
}
|
||||
|
|
@ -351,15 +351,17 @@ fn convert_backend(
|
|||
};
|
||||
|
||||
if !services.contains_key(&name) {
|
||||
return Backend::InvalidDst {
|
||||
return Backend::Invalid {
|
||||
weight: weight.into(),
|
||||
message: format!("Service not found {name}"),
|
||||
};
|
||||
}
|
||||
|
||||
Backend::Dst(WeightedDst {
|
||||
Backend::Service(WeightedService {
|
||||
weight: weight.into(),
|
||||
authority: cluster.service_dns_authority(ns, &name, port),
|
||||
name,
|
||||
namespace: ns.to_string(),
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue