k8s_openapi/v1_30/api/core/v1/
component_condition.rs

1// Generated from definition io.k8s.api.core.v1.ComponentCondition
2
3/// Information about the condition of a component.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ComponentCondition {
6    /// Condition error code for a component. For example, a health check error code.
7    pub error: Option<std::string::String>,
8
9    /// Message about the condition for a component. For example, information about a health check.
10    pub message: Option<std::string::String>,
11
12    /// Status of the condition for a component. Valid values for "Healthy": "True", "False", or "Unknown".
13    pub status: std::string::String,
14
15    /// Type of condition for a component. Valid value: "Healthy"
16    pub type_: std::string::String,
17}
18
19impl crate::DeepMerge for ComponentCondition {
20    fn merge_from(&mut self, other: Self) {
21        crate::DeepMerge::merge_from(&mut self.error, other.error);
22        crate::DeepMerge::merge_from(&mut self.message, other.message);
23        crate::DeepMerge::merge_from(&mut self.status, other.status);
24        crate::DeepMerge::merge_from(&mut self.type_, other.type_);
25    }
26}
27
28impl<'de> crate::serde::Deserialize<'de> for ComponentCondition {
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_error,
33            Key_message,
34            Key_status,
35            Key_type_,
36            Other,
37        }
38
39        impl<'de> crate::serde::Deserialize<'de> for Field {
40            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
41                struct Visitor;
42
43                impl crate::serde::de::Visitor<'_> for Visitor {
44                    type Value = Field;
45
46                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
47                        f.write_str("field identifier")
48                    }
49
50                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
51                        Ok(match v {
52                            "error" => Field::Key_error,
53                            "message" => Field::Key_message,
54                            "status" => Field::Key_status,
55                            "type" => Field::Key_type_,
56                            _ => Field::Other,
57                        })
58                    }
59                }
60
61                deserializer.deserialize_identifier(Visitor)
62            }
63        }
64
65        struct Visitor;
66
67        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
68            type Value = ComponentCondition;
69
70            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
71                f.write_str("ComponentCondition")
72            }
73
74            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
75                let mut value_error: Option<std::string::String> = None;
76                let mut value_message: Option<std::string::String> = None;
77                let mut value_status: Option<std::string::String> = None;
78                let mut value_type_: Option<std::string::String> = None;
79
80                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
81                    match key {
82                        Field::Key_error => value_error = crate::serde::de::MapAccess::next_value(&mut map)?,
83                        Field::Key_message => value_message = crate::serde::de::MapAccess::next_value(&mut map)?,
84                        Field::Key_status => value_status = crate::serde::de::MapAccess::next_value(&mut map)?,
85                        Field::Key_type_ => value_type_ = crate::serde::de::MapAccess::next_value(&mut map)?,
86                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
87                    }
88                }
89
90                Ok(ComponentCondition {
91                    error: value_error,
92                    message: value_message,
93                    status: value_status.unwrap_or_default(),
94                    type_: value_type_.unwrap_or_default(),
95                })
96            }
97        }
98
99        deserializer.deserialize_struct(
100            "ComponentCondition",
101            &[
102                "error",
103                "message",
104                "status",
105                "type",
106            ],
107            Visitor,
108        )
109    }
110}
111
112impl crate::serde::Serialize for ComponentCondition {
113    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
114        let mut state = serializer.serialize_struct(
115            "ComponentCondition",
116            2 +
117            self.error.as_ref().map_or(0, |_| 1) +
118            self.message.as_ref().map_or(0, |_| 1),
119        )?;
120        if let Some(value) = &self.error {
121            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "error", value)?;
122        }
123        if let Some(value) = &self.message {
124            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "message", value)?;
125        }
126        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "status", &self.status)?;
127        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "type", &self.type_)?;
128        crate::serde::ser::SerializeStruct::end(state)
129    }
130}
131
132#[cfg(feature = "schemars")]
133impl crate::schemars::JsonSchema for ComponentCondition {
134    fn schema_name() -> std::borrow::Cow<'static, str> {
135        "io.k8s.api.core.v1.ComponentCondition".into()
136    }
137
138    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
139        crate::schemars::json_schema!({
140            "description": "Information about the condition of a component.",
141            "type": "object",
142            "properties": {
143                "error": {
144                    "description": "Condition error code for a component. For example, a health check error code.",
145                    "type": "string",
146                },
147                "message": {
148                    "description": "Message about the condition for a component. For example, information about a health check.",
149                    "type": "string",
150                },
151                "status": {
152                    "description": "Status of the condition for a component. Valid values for \"Healthy\": \"True\", \"False\", or \"Unknown\".",
153                    "type": "string",
154                },
155                "type": {
156                    "description": "Type of condition for a component. Valid value: \"Healthy\"",
157                    "type": "string",
158                },
159            },
160            "required": [
161                "status",
162                "type",
163            ],
164        })
165    }
166}