forked from linkerd/linkerd2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresource_id.rs
36 lines (32 loc) · 1.12 KB
/
resource_id.rs
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
use crate::index::{GATEWAY_API_GROUP, POLICY_API_GROUP};
use linkerd_policy_controller_core::http_route::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(&())),
(GATEWAY_API_GROUP, "HTTPRoute") => Ok(k8s_gateway_api::HttpRoute::api_version(&())),
(group, kind) => {
anyhow::bail!("unknown group + kind combination: ({}, {})", group, kind)
}
}
}
}