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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
mod crd;
mod metadata;
pub mod options;
pub mod store;
#[cfg(feature = "core")]
pub mod core;
#[cfg(feature = "app")]
pub mod app;
#[cfg(feature = "storage")]
pub mod storage;
#[cfg(feature = "batch")]
pub mod batch;

pub use self::crd::*;
pub use self::metadata::*;
pub use self::spec_def::*;

mod spec_def {

    use std::fmt::Debug;

    use serde::de::DeserializeOwned;
    use serde::Deserialize;
    use serde::Serialize;

    use super::Crd;

    pub trait Status:
        Sized + Debug + Clone + Default + Serialize + DeserializeOwned + Send + Sync
    {
    }

    pub trait Header:
        Sized + Debug + Clone + Default + Serialize + DeserializeOwned + Send + Sync
    {
    }

    /// Kubernetes Spec
    pub trait Spec:
        Sized + Debug + Clone + Default + Serialize + DeserializeOwned + Send + Sync
    {
        type Status: Status;

        type Header: Header;

        /// if true, spec is namespaced
        const NAME_SPACED: bool = true;

        /// return uri for single instance
        fn metadata() -> &'static Crd;

        fn label() -> &'static str {
            Self::metadata().names.kind
        }

        fn api_version() -> String {
            let metadata = Self::metadata();
            if metadata.group == "core" {
                return metadata.version.to_owned();
            }
            format!("{}/{}", metadata.group, metadata.version)
        }

        fn kind() -> String {
            Self::metadata().names.kind.to_owned()
        }

        /// in case of applying, we have some fields that are generated
        /// or override.  So need to special logic to reset them so we can do proper comparison
        fn make_same(&mut self, _other: &Self) {}
    }

    #[derive(Deserialize, Serialize, Debug, Default, Clone)]
    pub struct DefaultHeader {}

    impl Header for DefaultHeader {}
}