diff --git a/policy-controller/k8s/status/src/index.rs b/policy-controller/k8s/status/src/index.rs index 573bb6134f26f..a9c674816af2b 100644 --- a/policy-controller/k8s/status/src/index.rs +++ b/policy-controller/k8s/status/src/index.rs @@ -268,19 +268,19 @@ impl Controller { // process through the updates queue but not actually patch // any resources. if is_leader { - if id.gkn.group == linkerd_k8s_api::HttpRoute::group(&()) && id.gkn.kind == linkerd_k8s_api::HttpRoute::kind(&()){ + if id.is_a::() { self.patch::(&id.gkn.name, &id.namespace, patch).await; - } else if id.gkn.group == k8s_gateway_api::HttpRoute::group(&()) && id.gkn.kind == k8s_gateway_api::HttpRoute::kind(&()) { + } else if id.is_a::() { self.patch::(&id.gkn.name, &id.namespace, patch).await; - } else if id.gkn.group == k8s_gateway_api::GrpcRoute::group(&()) && id.gkn.kind == k8s_gateway_api::GrpcRoute::kind(&()) { + } else if id.is_a::() { self.patch::(&id.gkn.name, &id.namespace, patch).await; - } else if id.gkn.group == k8s_gateway_api::TcpRoute::group(&()) && id.gkn.kind == k8s_gateway_api::TcpRoute::kind(&()) { + } else if id.is_a::() { self.patch::(&id.gkn.name, &id.namespace, patch).await; - } else if id.gkn.group == k8s_gateway_api::TlsRoute::group(&()) && id.gkn.kind == k8s_gateway_api::TlsRoute::kind(&()) { + } else if id.is_a::() { self.patch::(&id.gkn.name, &id.namespace, patch).await; - } else if id.gkn.group == linkerd_k8s_api::HttpLocalRateLimitPolicy::group(&()) && id.gkn.kind == linkerd_k8s_api::HttpLocalRateLimitPolicy::kind(&()) { + } else if id.is_a::() { self.patch::(&id.gkn.name, &id.namespace, patch).await; - } else if id.gkn.group == linkerd_k8s_api::EgressNetwork::group(&()) && id.gkn.kind == linkerd_k8s_api::EgressNetwork::kind(&()) { + } else if id.is_a::() { self.patch::(&id.gkn.name, &id.namespace, patch).await; } } else { diff --git a/policy-controller/k8s/status/src/resource_id.rs b/policy-controller/k8s/status/src/resource_id.rs index f930fe02b18d7..e5c515a14a47d 100644 --- a/policy-controller/k8s/status/src/resource_id.rs +++ b/policy-controller/k8s/status/src/resource_id.rs @@ -42,4 +42,11 @@ impl NamespaceGroupKindName { } } } + + pub fn is_a(&self) -> bool + where + K: Resource, + { + self.gkn.group == K::group(&()) && self.gkn.kind == K::kind(&()) + } }