k8s_openapi/v1_34/api/core/v1/
toleration.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct Toleration {
6 pub effect: Option<std::string::String>,
8
9 pub key: Option<std::string::String>,
11
12 pub operator: Option<std::string::String>,
14
15 pub toleration_seconds: Option<i64>,
17
18 pub value: Option<std::string::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 core::fmt::Formatter<'_>) -> core::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 core::fmt::Formatter<'_>) -> core::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<std::string::String> = None;
82 let mut value_key: Option<std::string::String> = None;
83 let mut value_operator: Option<std::string::String> = None;
84 let mut value_toleration_seconds: Option<i64> = None;
85 let mut value_value: Option<std::string::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() -> std::borrow::Cow<'static, str> {
154 "io.k8s.api.core.v1.Toleration".into()
155 }
156
157 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
158 crate::schemars::json_schema!({
159 "description": "The pod this Toleration is attached to tolerates any taint that matches the triple <key,value,effect> using the matching operator <operator>.",
160 "type": "object",
161 "properties": {
162 "effect": {
163 "description": "Effect indicates the taint effect to match. Empty means match all taint effects. When specified, allowed values are NoSchedule, PreferNoSchedule and NoExecute.",
164 "type": "string",
165 },
166 "key": {
167 "description": "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.",
168 "type": "string",
169 },
170 "operator": {
171 "description": "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.",
172 "type": "string",
173 },
174 "tolerationSeconds": {
175 "description": "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.",
176 "type": "integer",
177 "format": "int64",
178 },
179 "value": {
180 "description": "Value is the taint value the toleration matches to. If the operator is Exists, the value should be empty, otherwise just a regular string.",
181 "type": "string",
182 },
183 },
184 })
185 }
186}