Skip to content

Commit

Permalink
chore(policy): simplify status controller type matching
Browse files Browse the repository at this point in the history
This change reduces boilerplate when switching between types in the status
controller.

No functional changes.
  • Loading branch information
olix0r committed Nov 25, 2024
1 parent 8565694 commit 49495a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 7 additions & 7 deletions policy-controller/k8s/status/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,19 +269,19 @@ impl Controller {
// process through the updates queue but not actually patch
// any resources.
if self.leader {
if id.gkn.group == linkerd_k8s_api::HttpRoute::group(&()) && id.gkn.kind == linkerd_k8s_api::HttpRoute::kind(&()){
if id.is_a::<linkerd_k8s_api::HttpRoute>() {
self.patch::<linkerd_k8s_api::HttpRoute>(&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::<k8s_gateway_api::HttpRoute>() {
self.patch::<k8s_gateway_api::HttpRoute>(&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::<k8s_gateway_api::GrpcRoute>() {
self.patch::<k8s_gateway_api::GrpcRoute>(&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::<k8s_gateway_api::TcpRoute>() {
self.patch::<k8s_gateway_api::TcpRoute>(&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::<k8s_gateway_api::TlsRoute>() {
self.patch::<k8s_gateway_api::TlsRoute>(&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::<linkerd_k8s_api::HttpLocalRateLimitPolicy>() {
self.patch::<linkerd_k8s_api::HttpLocalRateLimitPolicy>(&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::<linkerd_k8s_api::EgressNetwork>() {
self.patch::<linkerd_k8s_api::EgressNetwork>(&id.gkn.name, &id.namespace, patch).await;
}
} else {
Expand Down
7 changes: 7 additions & 0 deletions policy-controller/k8s/status/src/resource_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,11 @@ impl NamespaceGroupKindName {
}
}
}

pub fn is_a<K>(&self) -> bool
where
K: Resource<DynamicType = ()>,
{
self.gkn.group == K::group(&()) && self.gkn.kind == K::kind(&())
}
}

0 comments on commit 49495a0

Please sign in to comment.