k8s_openapi/v1_34/apimachinery/pkg/apis/meta/v1/
condition.rs

1// Generated from definition io.k8s.apimachinery.pkg.apis.meta.v1.Condition
2
3/// Condition contains details for one aspect of the current state of this API Resource.
4#[derive(Clone, Debug, PartialEq)]
5pub struct Condition {
6    /// lastTransitionTime is the last time the condition transitioned from one status to another. This should be when the underlying condition changed.  If that is not known, then using the time when the API field changed is acceptable.
7    pub last_transition_time: crate::apimachinery::pkg::apis::meta::v1::Time,
8
9    /// message is a human readable message indicating details about the transition. This may be an empty string.
10    pub message: std::string::String,
11
12    /// observedGeneration represents the .metadata.generation that the condition was set based upon. For instance, if .metadata.generation is currently 12, but the .status.conditions\[x\].observedGeneration is 9, the condition is out of date with respect to the current state of the instance.
13    pub observed_generation: Option<i64>,
14
15    /// reason contains a programmatic identifier indicating the reason for the condition's last transition. Producers of specific condition types may define expected values and meanings for this field, and whether the values are considered a guaranteed API. The value should be a CamelCase string. This field may not be empty.
16    pub reason: std::string::String,
17
18    /// status of the condition, one of True, False, Unknown.
19    pub status: std::string::String,
20
21    /// type of condition in CamelCase or in foo.example.com/CamelCase.
22    pub type_: std::string::String,
23}
24
25impl crate::DeepMerge for Condition {
26    fn merge_from(&mut self, other: Self) {
27        crate::DeepMerge::merge_from(&mut self.last_transition_time, other.last_transition_time);
28        crate::DeepMerge::merge_from(&mut self.message, other.message);
29        crate::DeepMerge::merge_from(&mut self.observed_generation, other.observed_generation);
30        crate::DeepMerge::merge_from(&mut self.reason, other.reason);
31        crate::DeepMerge::merge_from(&mut self.status, other.status);
32        crate::DeepMerge::merge_from(&mut self.type_, other.type_);
33    }
34}
35
36impl<'de> crate::serde::Deserialize<'de> for Condition {
37    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
38        #[allow(non_camel_case_types)]
39        enum Field {
40            Key_last_transition_time,
41            Key_message,
42            Key_observed_generation,
43            Key_reason,
44            Key_status,
45            Key_type_,
46            Other,
47        }
48
49        impl<'de> crate::serde::Deserialize<'de> for Field {
50            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
51                struct Visitor;
52
53                impl crate::serde::de::Visitor<'_> for Visitor {
54                    type Value = Field;
55
56                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
57                        f.write_str("field identifier")
58                    }
59
60                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
61                        Ok(match v {
62                            "lastTransitionTime" => Field::Key_last_transition_time,
63                            "message" => Field::Key_message,
64                            "observedGeneration" => Field::Key_observed_generation,
65                            "reason" => Field::Key_reason,
66                            "status" => Field::Key_status,
67                            "type" => Field::Key_type_,
68                            _ => Field::Other,
69                        })
70                    }
71                }
72
73                deserializer.deserialize_identifier(Visitor)
74            }
75        }
76
77        struct Visitor;
78
79        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
80            type Value = Condition;
81
82            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
83                f.write_str("Condition")
84            }
85
86            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
87                let mut value_last_transition_time: Option<crate::apimachinery::pkg::apis::meta::v1::Time> = None;
88                let mut value_message: Option<std::string::String> = None;
89                let mut value_observed_generation: Option<i64> = None;
90                let mut value_reason: Option<std::string::String> = None;
91                let mut value_status: Option<std::string::String> = None;
92                let mut value_type_: Option<std::string::String> = None;
93
94                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
95                    match key {
96                        Field::Key_last_transition_time => value_last_transition_time = Some(crate::serde::de::MapAccess::next_value(&mut map)?),
97                        Field::Key_message => value_message = crate::serde::de::MapAccess::next_value(&mut map)?,
98                        Field::Key_observed_generation => value_observed_generation = crate::serde::de::MapAccess::next_value(&mut map)?,
99                        Field::Key_reason => value_reason = crate::serde::de::MapAccess::next_value(&mut map)?,
100                        Field::Key_status => value_status = crate::serde::de::MapAccess::next_value(&mut map)?,
101                        Field::Key_type_ => value_type_ = crate::serde::de::MapAccess::next_value(&mut map)?,
102                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
103                    }
104                }
105
106                Ok(Condition {
107                    last_transition_time: value_last_transition_time.ok_or_else(|| crate::serde::de::Error::missing_field("lastTransitionTime"))?,
108                    message: value_message.unwrap_or_default(),
109                    observed_generation: value_observed_generation,
110                    reason: value_reason.unwrap_or_default(),
111                    status: value_status.unwrap_or_default(),
112                    type_: value_type_.unwrap_or_default(),
113                })
114            }
115        }
116
117        deserializer.deserialize_struct(
118            "Condition",
119            &[
120                "lastTransitionTime",
121                "message",
122                "observedGeneration",
123                "reason",
124                "status",
125                "type",
126            ],
127            Visitor,
128        )
129    }
130}
131
132impl crate::serde::Serialize for Condition {
133    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
134        let mut state = serializer.serialize_struct(
135            "Condition",
136            5 +
137            self.observed_generation.as_ref().map_or(0, |_| 1),
138        )?;
139        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "lastTransitionTime", &self.last_transition_time)?;
140        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "message", &self.message)?;
141        if let Some(value) = &self.observed_generation {
142            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "observedGeneration", value)?;
143        }
144        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "reason", &self.reason)?;
145        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "status", &self.status)?;
146        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "type", &self.type_)?;
147        crate::serde::ser::SerializeStruct::end(state)
148    }
149}
150
151#[cfg(feature = "schemars")]
152impl crate::schemars::JsonSchema for Condition {
153    fn schema_name() -> std::borrow::Cow<'static, str> {
154        "io.k8s.apimachinery.pkg.apis.meta.v1.Condition".into()
155    }
156
157    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
158        crate::schemars::json_schema!({
159            "description": "Condition contains details for one aspect of the current state of this API Resource.",
160            "type": "object",
161            "properties": {
162                "lastTransitionTime": ({
163                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::Time>();
164                    schema_obj.ensure_object().insert("description".into(), "lastTransitionTime is the last time the condition transitioned from one status to another. This should be when the underlying condition changed.  If that is not known, then using the time when the API field changed is acceptable.".into());
165                    schema_obj
166                }),
167                "message": {
168                    "description": "message is a human readable message indicating details about the transition. This may be an empty string.",
169                    "type": "string",
170                },
171                "observedGeneration": {
172                    "description": "observedGeneration represents the .metadata.generation that the condition was set based upon. For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date with respect to the current state of the instance.",
173                    "type": "integer",
174                    "format": "int64",
175                },
176                "reason": {
177                    "description": "reason contains a programmatic identifier indicating the reason for the condition's last transition. Producers of specific condition types may define expected values and meanings for this field, and whether the values are considered a guaranteed API. The value should be a CamelCase string. This field may not be empty.",
178                    "type": "string",
179                },
180                "status": {
181                    "description": "status of the condition, one of True, False, Unknown.",
182                    "type": "string",
183                },
184                "type": {
185                    "description": "type of condition in CamelCase or in foo.example.com/CamelCase.",
186                    "type": "string",
187                },
188            },
189            "required": [
190                "lastTransitionTime",
191                "message",
192                "reason",
193                "status",
194                "type",
195            ],
196        })
197    }
198}