k8_types/
lib.rs

1mod crd;
2mod int_or_string;
3mod metadata;
4pub mod options;
5pub mod store;
6#[cfg(feature = "core")]
7pub mod core;
8#[cfg(feature = "app")]
9pub mod app;
10#[cfg(feature = "storage")]
11pub mod storage;
12#[cfg(feature = "batch")]
13pub mod batch;
14
15pub use self::crd::*;
16pub use self::metadata::*;
17pub use self::spec_def::*;
18
19mod spec_def {
20
21    use std::fmt::Debug;
22
23    use serde::de::DeserializeOwned;
24    use serde::Deserialize;
25    use serde::Serialize;
26
27    use super::Crd;
28
29    pub trait Status:
30        Sized + Debug + Clone + Default + Serialize + DeserializeOwned + Send + Sync
31    {
32    }
33
34    pub trait Header:
35        Sized + Debug + Clone + Default + Serialize + DeserializeOwned + Send + Sync
36    {
37    }
38
39    /// Kubernetes Spec
40    pub trait Spec:
41        Sized + Debug + Clone + Default + Serialize + DeserializeOwned + Send + Sync
42    {
43        type Status: Status;
44
45        type Header: Header;
46
47        /// if true, spec is namespaced
48        const NAME_SPACED: bool = true;
49
50        /// return uri for single instance
51        fn metadata() -> &'static Crd;
52
53        fn label() -> &'static str {
54            Self::metadata().names.kind
55        }
56
57        fn api_version() -> String {
58            let metadata = Self::metadata();
59            if metadata.group == "core" {
60                return metadata.version.to_owned();
61            }
62            format!("{}/{}", metadata.group, metadata.version)
63        }
64
65        fn kind() -> String {
66            Self::metadata().names.kind.to_owned()
67        }
68
69        /// in case of applying, we have some fields that are generated
70        /// or override.  So need to special logic to reset them so we can do proper comparison
71        fn make_same(&mut self, _other: &Self) {}
72    }
73
74    #[derive(Deserialize, Serialize, Debug, Default, Clone)]
75    pub struct DefaultHeader {}
76
77    impl Header for DefaultHeader {}
78}
79
80pub use int_or_string::Int32OrString;