k8s_openapi/v1_35/api/core/v1/
resource_health.rs

1// Generated from definition io.k8s.api.core.v1.ResourceHealth
2
3/// ResourceHealth represents the health of a resource. It has the latest device health information. This is a part of KEP https://kep.k8s.io/4680.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ResourceHealth {
6    /// Health of the resource. can be one of:
7    ///  - Healthy: operates as normal
8    ///  - Unhealthy: reported unhealthy. We consider this a temporary health issue
9    ///               since we do not have a mechanism today to distinguish
10    ///               temporary and permanent issues.
11    ///  - Unknown: The status cannot be determined.
12    ///             For example, Device Plugin got unregistered and hasn't been re-registered since.
13    ///
14    /// In future we may want to introduce the PermanentlyUnhealthy Status.
15    pub health: Option<std::string::String>,
16
17    /// ResourceID is the unique identifier of the resource. See the ResourceID type for more information.
18    pub resource_id: std::string::String,
19}
20
21impl crate::DeepMerge for ResourceHealth {
22    fn merge_from(&mut self, other: Self) {
23        crate::DeepMerge::merge_from(&mut self.health, other.health);
24        crate::DeepMerge::merge_from(&mut self.resource_id, other.resource_id);
25    }
26}
27
28impl<'de> crate::serde::Deserialize<'de> for ResourceHealth {
29    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
30        #[allow(non_camel_case_types)]
31        enum Field {
32            Key_health,
33            Key_resource_id,
34            Other,
35        }
36
37        impl<'de> crate::serde::Deserialize<'de> for Field {
38            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
39                struct Visitor;
40
41                impl crate::serde::de::Visitor<'_> for Visitor {
42                    type Value = Field;
43
44                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
45                        f.write_str("field identifier")
46                    }
47
48                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
49                        Ok(match v {
50                            "health" => Field::Key_health,
51                            "resourceID" => Field::Key_resource_id,
52                            _ => Field::Other,
53                        })
54                    }
55                }
56
57                deserializer.deserialize_identifier(Visitor)
58            }
59        }
60
61        struct Visitor;
62
63        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
64            type Value = ResourceHealth;
65
66            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
67                f.write_str("ResourceHealth")
68            }
69
70            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
71                let mut value_health: Option<std::string::String> = None;
72                let mut value_resource_id: Option<std::string::String> = None;
73
74                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
75                    match key {
76                        Field::Key_health => value_health = crate::serde::de::MapAccess::next_value(&mut map)?,
77                        Field::Key_resource_id => value_resource_id = crate::serde::de::MapAccess::next_value(&mut map)?,
78                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
79                    }
80                }
81
82                Ok(ResourceHealth {
83                    health: value_health,
84                    resource_id: value_resource_id.unwrap_or_default(),
85                })
86            }
87        }
88
89        deserializer.deserialize_struct(
90            "ResourceHealth",
91            &[
92                "health",
93                "resourceID",
94            ],
95            Visitor,
96        )
97    }
98}
99
100impl crate::serde::Serialize for ResourceHealth {
101    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
102        let mut state = serializer.serialize_struct(
103            "ResourceHealth",
104            1 +
105            self.health.as_ref().map_or(0, |_| 1),
106        )?;
107        if let Some(value) = &self.health {
108            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "health", value)?;
109        }
110        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resourceID", &self.resource_id)?;
111        crate::serde::ser::SerializeStruct::end(state)
112    }
113}
114
115#[cfg(feature = "schemars")]
116impl crate::schemars::JsonSchema for ResourceHealth {
117    fn schema_name() -> std::borrow::Cow<'static, str> {
118        "io.k8s.api.core.v1.ResourceHealth".into()
119    }
120
121    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
122        crate::schemars::json_schema!({
123            "description": "ResourceHealth represents the health of a resource. It has the latest device health information. This is a part of KEP https://kep.k8s.io/4680.",
124            "type": "object",
125            "properties": {
126                "health": {
127                    "description": "Health of the resource. can be one of:\n - Healthy: operates as normal\n - Unhealthy: reported unhealthy. We consider this a temporary health issue\n              since we do not have a mechanism today to distinguish\n              temporary and permanent issues.\n - Unknown: The status cannot be determined.\n            For example, Device Plugin got unregistered and hasn't been re-registered since.\n\nIn future we may want to introduce the PermanentlyUnhealthy Status.",
128                    "type": "string",
129                },
130                "resourceID": {
131                    "description": "ResourceID is the unique identifier of the resource. See the ResourceID type for more information.",
132                    "type": "string",
133                },
134            },
135            "required": [
136                "resourceID",
137            ],
138        })
139    }
140}