-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathresource_id.rs
More file actions
45 lines (41 loc) · 1.69 KB
/
resource_id.rs
File metadata and controls
45 lines (41 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use crate::index::{GATEWAY_API_GROUP, POLICY_API_GROUP};
use linkerd_policy_controller_core::routes::GroupKindName;
use linkerd_policy_controller_k8s_api::{
gateway as k8s_gateway_api, policy as linkerd_k8s_api, Resource,
};
use std::borrow::Cow;
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct ResourceId {
pub namespace: String,
pub name: String,
}
impl ResourceId {
pub fn new(namespace: String, name: String) -> Self {
Self { namespace, name }
}
}
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct NamespaceGroupKindName {
pub namespace: String,
pub gkn: GroupKindName,
}
impl NamespaceGroupKindName {
pub fn api_version(&self) -> anyhow::Result<Cow<'static, str>> {
match (self.gkn.group.as_ref(), self.gkn.kind.as_ref()) {
(POLICY_API_GROUP, "HTTPRoute") => Ok(linkerd_k8s_api::HttpRoute::api_version(&())),
(POLICY_API_GROUP, "HTTPLocalRateLimitPolicy") => {
Ok(linkerd_k8s_api::HttpLocalRateLimitPolicy::api_version(&()))
}
(POLICY_API_GROUP, "EgressNetwork") => {
Ok(linkerd_k8s_api::EgressNetwork::api_version(&()))
}
(GATEWAY_API_GROUP, "HTTPRoute") => Ok(k8s_gateway_api::HttpRoute::api_version(&())),
(GATEWAY_API_GROUP, "GRPCRoute") => Ok(k8s_gateway_api::GrpcRoute::api_version(&())),
(GATEWAY_API_GROUP, "TCPRoute") => Ok(k8s_gateway_api::TcpRoute::api_version(&())),
(GATEWAY_API_GROUP, "TLSRoute") => Ok(k8s_gateway_api::TlsRoute::api_version(&())),
(group, kind) => {
anyhow::bail!("unknown group + kind combination: ({}, {})", group, kind)
}
}
}
}