Skip to content

Commit

Permalink
chore(policy): simplify status controller type matching (#13395)
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 authored Nov 25, 2024
1 parent 6a46f69 commit dd789cd
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 @@ -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::<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 dd789cd

Please sign in to comment.