use std::borrow::Cow;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct GroupVersionKind {
pub group: &'static str,
pub version: &'static str,
pub kind: &'static str,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct GroupVersionResource {
pub group: &'static str,
pub version: &'static str,
pub resource: &'static str,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Scope {
Namespaced,
Cluster,
}
pub trait KubeResource: serde::Serialize + serde::de::DeserializeOwned + Clone {
const GVK: GroupVersionKind;
const GVR: GroupVersionResource;
const SCOPE: Scope;
fn name(&self) -> Cow<'_, str>;
fn namespace(&self) -> Option<Cow<'_, str>>;
fn resource_version(&self) -> Option<Cow<'_, str>>;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn gvk_equality_is_trivial() {
let a = GroupVersionKind { group: "", version: "v1", kind: "Pod" };
let b = GroupVersionKind { group: "", version: "v1", kind: "Pod" };
assert_eq!(a, b);
}
#[test]
fn scope_round_trips() {
assert_eq!(Scope::Namespaced, Scope::Namespaced);
assert_ne!(Scope::Namespaced, Scope::Cluster);
}
}