From a7d9156de42b5018abe0cac54deaf5a0b03d90d1 Mon Sep 17 00:00:00 2001 From: wgjak47 Date: Thu, 31 Jul 2025 22:16:24 +0800 Subject: [PATCH] fix(outbound): fix clientpolicy not work after remvoe service profile This is a preview PR for https://github.com/linkerd/linkerd2/issues/14274. In linkerd/idle-cache/src/lib.rs get_or_insert_with function, seems the sidercar with service profile and sidercar with client policy has the same key, which cause the cache didn't expire after we delete serviceprofile and create the new httproute for the target sevice for pods that keep requesting the target service. this pr try to create different keys for service profile httpsidecar and client policy httpsidecar Signed-off-by: Guanjie Wang --- linkerd/app/outbound/src/sidecar.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/linkerd/app/outbound/src/sidecar.rs b/linkerd/app/outbound/src/sidecar.rs index d04d5c6543..085813e9a4 100644 --- a/linkerd/app/outbound/src/sidecar.rs +++ b/linkerd/app/outbound/src/sidecar.rs @@ -30,6 +30,7 @@ struct HttpSidecar { orig_dst: OrigDstAddr, version: http::Variant, routes: watch::Receiver, + provider: RouteProvider, } #[derive(Clone, Debug)] @@ -44,6 +45,21 @@ struct OpaqSidecar { routes: watch::Receiver, } +#[derive(Copy, Clone, PartialEq, Eq, Hash)] +pub enum RouteProvider { + ServiceProfile, + ClientPolicy, +} + +impl std::fmt::Debug for RouteProvider { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::ServiceProfile => write!(f, "ServiceProfile"), + Self::ClientPolicy => write!(f, "ClientPolicy"), + } + } +} + // === impl Outbound === impl Outbound<()> { @@ -196,10 +212,12 @@ impl From> for HttpSidecar { http::spawn_routes(profile, init, move |profile: &profiles::Profile| { Some(Self::mk_profile_routes(addr.clone(), profile)) }); + let provider = RouteProvider::ServiceProfile; return HttpSidecar { orig_dst, version, routes, + provider, }; } } @@ -210,10 +228,12 @@ impl From> for HttpSidecar { let routes = http::spawn_routes(policy, init, move |policy: &policy::ClientPolicy| { Self::mk_policy_routes(orig_dst, version, policy) }); + let provider = RouteProvider::ClientPolicy; HttpSidecar { orig_dst, version, routes, + provider, } } } @@ -334,6 +354,7 @@ impl std::hash::Hash for HttpSidecar { fn hash(&self, state: &mut H) { self.orig_dst.hash(state); self.version.hash(state); + self.provider.hash(state); } }