Skip to content

Commit dd789cd

Browse files
authored
chore(policy): simplify status controller type matching (#13395)
This change reduces boilerplate when switching between types in the status controller. No functional changes.
1 parent 6a46f69 commit dd789cd

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

policy-controller/k8s/status/src/index.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,19 +268,19 @@ impl Controller {
268268
// process through the updates queue but not actually patch
269269
// any resources.
270270
if is_leader {
271-
if id.gkn.group == linkerd_k8s_api::HttpRoute::group(&()) && id.gkn.kind == linkerd_k8s_api::HttpRoute::kind(&()){
271+
if id.is_a::<linkerd_k8s_api::HttpRoute>() {
272272
self.patch::<linkerd_k8s_api::HttpRoute>(&id.gkn.name, &id.namespace, patch).await;
273-
} else if id.gkn.group == k8s_gateway_api::HttpRoute::group(&()) && id.gkn.kind == k8s_gateway_api::HttpRoute::kind(&()) {
273+
} else if id.is_a::<k8s_gateway_api::HttpRoute>() {
274274
self.patch::<k8s_gateway_api::HttpRoute>(&id.gkn.name, &id.namespace, patch).await;
275-
} else if id.gkn.group == k8s_gateway_api::GrpcRoute::group(&()) && id.gkn.kind == k8s_gateway_api::GrpcRoute::kind(&()) {
275+
} else if id.is_a::<k8s_gateway_api::GrpcRoute>() {
276276
self.patch::<k8s_gateway_api::GrpcRoute>(&id.gkn.name, &id.namespace, patch).await;
277-
} else if id.gkn.group == k8s_gateway_api::TcpRoute::group(&()) && id.gkn.kind == k8s_gateway_api::TcpRoute::kind(&()) {
277+
} else if id.is_a::<k8s_gateway_api::TcpRoute>() {
278278
self.patch::<k8s_gateway_api::TcpRoute>(&id.gkn.name, &id.namespace, patch).await;
279-
} else if id.gkn.group == k8s_gateway_api::TlsRoute::group(&()) && id.gkn.kind == k8s_gateway_api::TlsRoute::kind(&()) {
279+
} else if id.is_a::<k8s_gateway_api::TlsRoute>() {
280280
self.patch::<k8s_gateway_api::TlsRoute>(&id.gkn.name, &id.namespace, patch).await;
281-
} else if id.gkn.group == linkerd_k8s_api::HttpLocalRateLimitPolicy::group(&()) && id.gkn.kind == linkerd_k8s_api::HttpLocalRateLimitPolicy::kind(&()) {
281+
} else if id.is_a::<linkerd_k8s_api::HttpLocalRateLimitPolicy>() {
282282
self.patch::<linkerd_k8s_api::HttpLocalRateLimitPolicy>(&id.gkn.name, &id.namespace, patch).await;
283-
} else if id.gkn.group == linkerd_k8s_api::EgressNetwork::group(&()) && id.gkn.kind == linkerd_k8s_api::EgressNetwork::kind(&()) {
283+
} else if id.is_a::<linkerd_k8s_api::EgressNetwork>() {
284284
self.patch::<linkerd_k8s_api::EgressNetwork>(&id.gkn.name, &id.namespace, patch).await;
285285
}
286286
} else {

policy-controller/k8s/status/src/resource_id.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,11 @@ impl NamespaceGroupKindName {
4242
}
4343
}
4444
}
45+
46+
pub fn is_a<K>(&self) -> bool
47+
where
48+
K: Resource<DynamicType = ()>,
49+
{
50+
self.gkn.group == K::group(&()) && self.gkn.kind == K::kind(&())
51+
}
4552
}

0 commit comments

Comments
 (0)