k8s_openapi/v1_35/api/resource/v1beta2/
device_taint.rs

1// Generated from definition io.k8s.api.resource.v1beta2.DeviceTaint
2
3/// The device this taint is attached to has the "effect" on any claim which does not tolerate the taint and, through the claim, to pods using the claim.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct DeviceTaint {
6    /// The effect of the taint on claims that do not tolerate the taint and through such claims on the pods using them.
7    ///
8    /// Valid effects are None, NoSchedule and NoExecute. PreferNoSchedule as used for nodes is not valid here. More effects may get added in the future. Consumers must treat unknown effects like None.
9    pub effect: std::string::String,
10
11    /// The taint key to be applied to a device. Must be a label name.
12    pub key: std::string::String,
13
14    /// TimeAdded represents the time at which the taint was added. Added automatically during create or update if not set.
15    pub time_added: Option<crate::apimachinery::pkg::apis::meta::v1::Time>,
16
17    /// The taint value corresponding to the taint key. Must be a label value.
18    pub value: Option<std::string::String>,
19}
20
21impl crate::DeepMerge for DeviceTaint {
22    fn merge_from(&mut self, other: Self) {
23        crate::DeepMerge::merge_from(&mut self.effect, other.effect);
24        crate::DeepMerge::merge_from(&mut self.key, other.key);
25        crate::DeepMerge::merge_from(&mut self.time_added, other.time_added);
26        crate::DeepMerge::merge_from(&mut self.value, other.value);
27    }
28}
29
30impl<'de> crate::serde::Deserialize<'de> for DeviceTaint {
31    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
32        #[allow(non_camel_case_types)]
33        enum Field {
34            Key_effect,
35            Key_key,
36            Key_time_added,
37            Key_value,
38            Other,
39        }
40
41        impl<'de> crate::serde::Deserialize<'de> for Field {
42            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
43                struct Visitor;
44
45                impl crate::serde::de::Visitor<'_> for Visitor {
46                    type Value = Field;
47
48                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
49                        f.write_str("field identifier")
50                    }
51
52                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
53                        Ok(match v {
54                            "effect" => Field::Key_effect,
55                            "key" => Field::Key_key,
56                            "timeAdded" => Field::Key_time_added,
57                            "value" => Field::Key_value,
58                            _ => Field::Other,
59                        })
60                    }
61                }
62
63                deserializer.deserialize_identifier(Visitor)
64            }
65        }
66
67        struct Visitor;
68
69        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
70            type Value = DeviceTaint;
71
72            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
73                f.write_str("DeviceTaint")
74            }
75
76            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
77                let mut value_effect: Option<std::string::String> = None;
78                let mut value_key: Option<std::string::String> = None;
79                let mut value_time_added: Option<crate::apimachinery::pkg::apis::meta::v1::Time> = None;
80                let mut value_value: Option<std::string::String> = None;
81
82                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
83                    match key {
84                        Field::Key_effect => value_effect = crate::serde::de::MapAccess::next_value(&mut map)?,
85                        Field::Key_key => value_key = crate::serde::de::MapAccess::next_value(&mut map)?,
86                        Field::Key_time_added => value_time_added = crate::serde::de::MapAccess::next_value(&mut map)?,
87                        Field::Key_value => value_value = crate::serde::de::MapAccess::next_value(&mut map)?,
88                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
89                    }
90                }
91
92                Ok(DeviceTaint {
93                    effect: value_effect.unwrap_or_default(),
94                    key: value_key.unwrap_or_default(),
95                    time_added: value_time_added,
96                    value: value_value,
97                })
98            }
99        }
100
101        deserializer.deserialize_struct(
102            "DeviceTaint",
103            &[
104                "effect",
105                "key",
106                "timeAdded",
107                "value",
108            ],
109            Visitor,
110        )
111    }
112}
113
114impl crate::serde::Serialize for DeviceTaint {
115    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
116        let mut state = serializer.serialize_struct(
117            "DeviceTaint",
118            2 +
119            self.time_added.as_ref().map_or(0, |_| 1) +
120            self.value.as_ref().map_or(0, |_| 1),
121        )?;
122        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "effect", &self.effect)?;
123        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "key", &self.key)?;
124        if let Some(value) = &self.time_added {
125            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "timeAdded", value)?;
126        }
127        if let Some(value) = &self.value {
128            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "value", value)?;
129        }
130        crate::serde::ser::SerializeStruct::end(state)
131    }
132}
133
134#[cfg(feature = "schemars")]
135impl crate::schemars::JsonSchema for DeviceTaint {
136    fn schema_name() -> std::borrow::Cow<'static, str> {
137        "io.k8s.api.resource.v1beta2.DeviceTaint".into()
138    }
139
140    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
141        crate::schemars::json_schema!({
142            "description": "The device this taint is attached to has the \"effect\" on any claim which does not tolerate the taint and, through the claim, to pods using the claim.",
143            "type": "object",
144            "properties": {
145                "effect": {
146                    "description": "The effect of the taint on claims that do not tolerate the taint and through such claims on the pods using them.\n\nValid effects are None, NoSchedule and NoExecute. PreferNoSchedule as used for nodes is not valid here. More effects may get added in the future. Consumers must treat unknown effects like None.",
147                    "type": "string",
148                },
149                "key": {
150                    "description": "The taint key to be applied to a device. Must be a label name.",
151                    "type": "string",
152                },
153                "timeAdded": ({
154                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::Time>();
155                    schema_obj.ensure_object().insert("description".into(), "TimeAdded represents the time at which the taint was added. Added automatically during create or update if not set.".into());
156                    schema_obj
157                }),
158                "value": {
159                    "description": "The taint value corresponding to the taint key. Must be a label value.",
160                    "type": "string",
161                },
162            },
163            "required": [
164                "effect",
165                "key",
166            ],
167        })
168    }
169}