k8s_openapi/v1_32/api/core/v1/
toleration.rs

1// Generated from definition io.k8s.api.core.v1.Toleration
2
3/// The pod this Toleration is attached to tolerates any taint that matches the triple \<key,value,effect\> using the matching operator \<operator\>.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct Toleration {
6    /// Effect indicates the taint effect to match. Empty means match all taint effects. When specified, allowed values are NoSchedule, PreferNoSchedule and NoExecute.
7    pub effect: Option<String>,
8
9    /// Key is the taint key that the toleration applies to. Empty means match all taint keys. If the key is empty, operator must be Exists; this combination means to match all values and all keys.
10    pub key: Option<String>,
11
12    /// Operator represents a key's relationship to the value. Valid operators are Exists and Equal. Defaults to Equal. Exists is equivalent to wildcard for value, so that a pod can tolerate all taints of a particular category.
13    pub operator: Option<String>,
14
15    /// TolerationSeconds represents the period of time the toleration (which must be of effect NoExecute, otherwise this field is ignored) tolerates the taint. By default, it is not set, which means tolerate the taint forever (do not evict). Zero and negative values will be treated as 0 (evict immediately) by the system.
16    pub toleration_seconds: Option<i64>,
17
18    /// Value is the taint value the toleration matches to. If the operator is Exists, the value should be empty, otherwise just a regular string.
19    pub value: Option<String>,
20}
21
22impl crate::DeepMerge for Toleration {
23    fn merge_from(&mut self, other: Self) {
24        crate::DeepMerge::merge_from(&mut self.effect, other.effect);
25        crate::DeepMerge::merge_from(&mut self.key, other.key);
26        crate::DeepMerge::merge_from(&mut self.operator, other.operator);
27        crate::DeepMerge::merge_from(&mut self.toleration_seconds, other.toleration_seconds);
28        crate::DeepMerge::merge_from(&mut self.value, other.value);
29    }
30}
31
32impl<'de> crate::serde::Deserialize<'de> for Toleration {
33    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
34        #[allow(non_camel_case_types)]
35        enum Field {
36            Key_effect,
37            Key_key,
38            Key_operator,
39            Key_toleration_seconds,
40            Key_value,
41            Other,
42        }
43
44        impl<'de> crate::serde::Deserialize<'de> for Field {
45            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
46                struct Visitor;
47
48                impl crate::serde::de::Visitor<'_> for Visitor {
49                    type Value = Field;
50
51                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
52                        f.write_str("field identifier")
53                    }
54
55                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
56                        Ok(match v {
57                            "effect" => Field::Key_effect,
58                            "key" => Field::Key_key,
59                            "operator" => Field::Key_operator,
60                            "tolerationSeconds" => Field::Key_toleration_seconds,
61                            "value" => Field::Key_value,
62                            _ => Field::Other,
63                        })
64                    }
65                }
66
67                deserializer.deserialize_identifier(Visitor)
68            }
69        }
70
71        struct Visitor;
72
73        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
74            type Value = Toleration;
75
76            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
77                f.write_str("Toleration")
78            }
79
80            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
81                let mut value_effect: Option<String> = None;
82                let mut value_key: Option<String> = None;
83                let mut value_operator: Option<String> = None;
84                let mut value_toleration_seconds: Option<i64> = None;
85                let mut value_value: Option<String> = None;
86
87                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
88                    match key {
89                        Field::Key_effect => value_effect = crate::serde::de::MapAccess::next_value(&mut map)?,
90                        Field::Key_key => value_key = crate::serde::de::MapAccess::next_value(&mut map)?,
91                        Field::Key_operator => value_operator = crate::serde::de::MapAccess::next_value(&mut map)?,
92                        Field::Key_toleration_seconds => value_toleration_seconds = crate::serde::de::MapAccess::next_value(&mut map)?,
93                        Field::Key_value => value_value = crate::serde::de::MapAccess::next_value(&mut map)?,
94                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
95                    }
96                }
97
98                Ok(Toleration {
99                    effect: value_effect,
100                    key: value_key,
101                    operator: value_operator,
102                    toleration_seconds: value_toleration_seconds,
103                    value: value_value,
104                })
105            }
106        }
107
108        deserializer.deserialize_struct(
109            "Toleration",
110            &[
111                "effect",
112                "key",
113                "operator",
114                "tolerationSeconds",
115                "value",
116            ],
117            Visitor,
118        )
119    }
120}
121
122impl crate::serde::Serialize for Toleration {
123    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
124        let mut state = serializer.serialize_struct(
125            "Toleration",
126            self.effect.as_ref().map_or(0, |_| 1) +
127            self.key.as_ref().map_or(0, |_| 1) +
128            self.operator.as_ref().map_or(0, |_| 1) +
129            self.toleration_seconds.as_ref().map_or(0, |_| 1) +
130            self.value.as_ref().map_or(0, |_| 1),
131        )?;
132        if let Some(value) = &self.effect {
133            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "effect", value)?;
134        }
135        if let Some(value) = &self.key {
136            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "key", value)?;
137        }
138        if let Some(value) = &self.operator {
139            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "operator", value)?;
140        }
141        if let Some(value) = &self.toleration_seconds {
142            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "tolerationSeconds", value)?;
143        }
144        if let Some(value) = &self.value {
145            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "value", value)?;
146        }
147        crate::serde::ser::SerializeStruct::end(state)
148    }
149}
150
151#[cfg(feature = "schemars")]
152impl crate::schemars::JsonSchema for Toleration {
153    fn schema_name() -> String {
154        "io.k8s.api.core.v1.Toleration".to_owned()
155    }
156
157    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
158        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
159            metadata: Some(Box::new(crate::schemars::schema::Metadata {
160                description: Some("The pod this Toleration is attached to tolerates any taint that matches the triple <key,value,effect> using the matching operator <operator>.".to_owned()),
161                ..Default::default()
162            })),
163            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
164            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
165                properties: [
166                    (
167                        "effect".to_owned(),
168                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
169                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
170                                description: Some("Effect indicates the taint effect to match. Empty means match all taint effects. When specified, allowed values are NoSchedule, PreferNoSchedule and NoExecute.".to_owned()),
171                                ..Default::default()
172                            })),
173                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
174                            ..Default::default()
175                        }),
176                    ),
177                    (
178                        "key".to_owned(),
179                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
180                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
181                                description: Some("Key is the taint key that the toleration applies to. Empty means match all taint keys. If the key is empty, operator must be Exists; this combination means to match all values and all keys.".to_owned()),
182                                ..Default::default()
183                            })),
184                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
185                            ..Default::default()
186                        }),
187                    ),
188                    (
189                        "operator".to_owned(),
190                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
191                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
192                                description: Some("Operator represents a key's relationship to the value. Valid operators are Exists and Equal. Defaults to Equal. Exists is equivalent to wildcard for value, so that a pod can tolerate all taints of a particular category.".to_owned()),
193                                ..Default::default()
194                            })),
195                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
196                            ..Default::default()
197                        }),
198                    ),
199                    (
200                        "tolerationSeconds".to_owned(),
201                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
202                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
203                                description: Some("TolerationSeconds represents the period of time the toleration (which must be of effect NoExecute, otherwise this field is ignored) tolerates the taint. By default, it is not set, which means tolerate the taint forever (do not evict). Zero and negative values will be treated as 0 (evict immediately) by the system.".to_owned()),
204                                ..Default::default()
205                            })),
206                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Integer))),
207                            format: Some("int64".to_owned()),
208                            ..Default::default()
209                        }),
210                    ),
211                    (
212                        "value".to_owned(),
213                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
214                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
215                                description: Some("Value is the taint value the toleration matches to. If the operator is Exists, the value should be empty, otherwise just a regular string.".to_owned()),
216                                ..Default::default()
217                            })),
218                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
219                            ..Default::default()
220                        }),
221                    ),
222                ].into(),
223                ..Default::default()
224            })),
225            ..Default::default()
226        })
227    }
228}