k8s_openapi/v1_32/api/discovery/v1/
endpoint_conditions.rs

1// Generated from definition io.k8s.api.discovery.v1.EndpointConditions
2
3/// EndpointConditions represents the current condition of an endpoint.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct EndpointConditions {
6    /// ready indicates that this endpoint is prepared to receive traffic, according to whatever system is managing the endpoint. A nil value indicates an unknown state. In most cases consumers should interpret this unknown state as ready. For compatibility reasons, ready should never be "true" for terminating endpoints, except when the normal readiness behavior is being explicitly overridden, for example when the associated Service has set the publishNotReadyAddresses flag.
7    pub ready: Option<bool>,
8
9    /// serving is identical to ready except that it is set regardless of the terminating state of endpoints. This condition should be set to true for a ready endpoint that is terminating. If nil, consumers should defer to the ready condition.
10    pub serving: Option<bool>,
11
12    /// terminating indicates that this endpoint is terminating. A nil value indicates an unknown state. Consumers should interpret this unknown state to mean that the endpoint is not terminating.
13    pub terminating: Option<bool>,
14}
15
16impl crate::DeepMerge for EndpointConditions {
17    fn merge_from(&mut self, other: Self) {
18        crate::DeepMerge::merge_from(&mut self.ready, other.ready);
19        crate::DeepMerge::merge_from(&mut self.serving, other.serving);
20        crate::DeepMerge::merge_from(&mut self.terminating, other.terminating);
21    }
22}
23
24impl<'de> crate::serde::Deserialize<'de> for EndpointConditions {
25    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
26        #[allow(non_camel_case_types)]
27        enum Field {
28            Key_ready,
29            Key_serving,
30            Key_terminating,
31            Other,
32        }
33
34        impl<'de> crate::serde::Deserialize<'de> for Field {
35            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
36                struct Visitor;
37
38                impl crate::serde::de::Visitor<'_> for Visitor {
39                    type Value = Field;
40
41                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42                        f.write_str("field identifier")
43                    }
44
45                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
46                        Ok(match v {
47                            "ready" => Field::Key_ready,
48                            "serving" => Field::Key_serving,
49                            "terminating" => Field::Key_terminating,
50                            _ => Field::Other,
51                        })
52                    }
53                }
54
55                deserializer.deserialize_identifier(Visitor)
56            }
57        }
58
59        struct Visitor;
60
61        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
62            type Value = EndpointConditions;
63
64            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
65                f.write_str("EndpointConditions")
66            }
67
68            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
69                let mut value_ready: Option<bool> = None;
70                let mut value_serving: Option<bool> = None;
71                let mut value_terminating: Option<bool> = None;
72
73                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
74                    match key {
75                        Field::Key_ready => value_ready = crate::serde::de::MapAccess::next_value(&mut map)?,
76                        Field::Key_serving => value_serving = crate::serde::de::MapAccess::next_value(&mut map)?,
77                        Field::Key_terminating => value_terminating = 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(EndpointConditions {
83                    ready: value_ready,
84                    serving: value_serving,
85                    terminating: value_terminating,
86                })
87            }
88        }
89
90        deserializer.deserialize_struct(
91            "EndpointConditions",
92            &[
93                "ready",
94                "serving",
95                "terminating",
96            ],
97            Visitor,
98        )
99    }
100}
101
102impl crate::serde::Serialize for EndpointConditions {
103    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
104        let mut state = serializer.serialize_struct(
105            "EndpointConditions",
106            self.ready.as_ref().map_or(0, |_| 1) +
107            self.serving.as_ref().map_or(0, |_| 1) +
108            self.terminating.as_ref().map_or(0, |_| 1),
109        )?;
110        if let Some(value) = &self.ready {
111            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "ready", value)?;
112        }
113        if let Some(value) = &self.serving {
114            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "serving", value)?;
115        }
116        if let Some(value) = &self.terminating {
117            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "terminating", value)?;
118        }
119        crate::serde::ser::SerializeStruct::end(state)
120    }
121}
122
123#[cfg(feature = "schemars")]
124impl crate::schemars::JsonSchema for EndpointConditions {
125    fn schema_name() -> String {
126        "io.k8s.api.discovery.v1.EndpointConditions".to_owned()
127    }
128
129    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
130        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
131            metadata: Some(Box::new(crate::schemars::schema::Metadata {
132                description: Some("EndpointConditions represents the current condition of an endpoint.".to_owned()),
133                ..Default::default()
134            })),
135            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
136            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
137                properties: [
138                    (
139                        "ready".to_owned(),
140                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
141                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
142                                description: Some("ready indicates that this endpoint is prepared to receive traffic, according to whatever system is managing the endpoint. A nil value indicates an unknown state. In most cases consumers should interpret this unknown state as ready. For compatibility reasons, ready should never be \"true\" for terminating endpoints, except when the normal readiness behavior is being explicitly overridden, for example when the associated Service has set the publishNotReadyAddresses flag.".to_owned()),
143                                ..Default::default()
144                            })),
145                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Boolean))),
146                            ..Default::default()
147                        }),
148                    ),
149                    (
150                        "serving".to_owned(),
151                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
152                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
153                                description: Some("serving is identical to ready except that it is set regardless of the terminating state of endpoints. This condition should be set to true for a ready endpoint that is terminating. If nil, consumers should defer to the ready condition.".to_owned()),
154                                ..Default::default()
155                            })),
156                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Boolean))),
157                            ..Default::default()
158                        }),
159                    ),
160                    (
161                        "terminating".to_owned(),
162                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
163                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
164                                description: Some("terminating indicates that this endpoint is terminating. A nil value indicates an unknown state. Consumers should interpret this unknown state to mean that the endpoint is not terminating.".to_owned()),
165                                ..Default::default()
166                            })),
167                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Boolean))),
168                            ..Default::default()
169                        }),
170                    ),
171                ].into(),
172                ..Default::default()
173            })),
174            ..Default::default()
175        })
176    }
177}