k8s_openapi/v1_30/api/core/v1/
node_selector_requirement.rs

1// Generated from definition io.k8s.api.core.v1.NodeSelectorRequirement
2
3/// A node selector requirement is a selector that contains values, a key, and an operator that relates the key and values.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct NodeSelectorRequirement {
6    /// The label key that the selector applies to.
7    pub key: String,
8
9    /// Represents a key's relationship to a set of values. Valid operators are In, NotIn, Exists, DoesNotExist. Gt, and Lt.
10    pub operator: String,
11
12    /// An array of string values. If the operator is In or NotIn, the values array must be non-empty. If the operator is Exists or DoesNotExist, the values array must be empty. If the operator is Gt or Lt, the values array must have a single element, which will be interpreted as an integer. This array is replaced during a strategic merge patch.
13    pub values: Option<Vec<String>>,
14}
15
16impl crate::DeepMerge for NodeSelectorRequirement {
17    fn merge_from(&mut self, other: Self) {
18        crate::DeepMerge::merge_from(&mut self.key, other.key);
19        crate::DeepMerge::merge_from(&mut self.operator, other.operator);
20        crate::merge_strategies::list::atomic(&mut self.values, other.values);
21    }
22}
23
24impl<'de> crate::serde::Deserialize<'de> for NodeSelectorRequirement {
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_key,
29            Key_operator,
30            Key_values,
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                            "key" => Field::Key_key,
48                            "operator" => Field::Key_operator,
49                            "values" => Field::Key_values,
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 = NodeSelectorRequirement;
63
64            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
65                f.write_str("NodeSelectorRequirement")
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_key: Option<String> = None;
70                let mut value_operator: Option<String> = None;
71                let mut value_values: Option<Vec<String>> = None;
72
73                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
74                    match key {
75                        Field::Key_key => value_key = crate::serde::de::MapAccess::next_value(&mut map)?,
76                        Field::Key_operator => value_operator = crate::serde::de::MapAccess::next_value(&mut map)?,
77                        Field::Key_values => value_values = 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(NodeSelectorRequirement {
83                    key: value_key.unwrap_or_default(),
84                    operator: value_operator.unwrap_or_default(),
85                    values: value_values,
86                })
87            }
88        }
89
90        deserializer.deserialize_struct(
91            "NodeSelectorRequirement",
92            &[
93                "key",
94                "operator",
95                "values",
96            ],
97            Visitor,
98        )
99    }
100}
101
102impl crate::serde::Serialize for NodeSelectorRequirement {
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            "NodeSelectorRequirement",
106            2 +
107            self.values.as_ref().map_or(0, |_| 1),
108        )?;
109        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "key", &self.key)?;
110        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "operator", &self.operator)?;
111        if let Some(value) = &self.values {
112            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "values", value)?;
113        }
114        crate::serde::ser::SerializeStruct::end(state)
115    }
116}
117
118#[cfg(feature = "schemars")]
119impl crate::schemars::JsonSchema for NodeSelectorRequirement {
120    fn schema_name() -> String {
121        "io.k8s.api.core.v1.NodeSelectorRequirement".to_owned()
122    }
123
124    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
125        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
126            metadata: Some(Box::new(crate::schemars::schema::Metadata {
127                description: Some("A node selector requirement is a selector that contains values, a key, and an operator that relates the key and values.".to_owned()),
128                ..Default::default()
129            })),
130            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
131            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
132                properties: [
133                    (
134                        "key".to_owned(),
135                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
136                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
137                                description: Some("The label key that the selector applies to.".to_owned()),
138                                ..Default::default()
139                            })),
140                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
141                            ..Default::default()
142                        }),
143                    ),
144                    (
145                        "operator".to_owned(),
146                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
147                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
148                                description: Some("Represents a key's relationship to a set of values. Valid operators are In, NotIn, Exists, DoesNotExist. Gt, and Lt.".to_owned()),
149                                ..Default::default()
150                            })),
151                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
152                            ..Default::default()
153                        }),
154                    ),
155                    (
156                        "values".to_owned(),
157                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
158                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
159                                description: Some("An array of string values. If the operator is In or NotIn, the values array must be non-empty. If the operator is Exists or DoesNotExist, the values array must be empty. If the operator is Gt or Lt, the values array must have a single element, which will be interpreted as an integer. This array is replaced during a strategic merge patch.".to_owned()),
160                                ..Default::default()
161                            })),
162                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
163                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
164                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
165                                    crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
166                                        instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
167                                        ..Default::default()
168                                    })
169                                ))),
170                                ..Default::default()
171                            })),
172                            ..Default::default()
173                        }),
174                    ),
175                ].into(),
176                required: [
177                    "key".to_owned(),
178                    "operator".to_owned(),
179                ].into(),
180                ..Default::default()
181            })),
182            ..Default::default()
183        })
184    }
185}