k8s_openapi/v1_35/api/core/v1/
pod_affinity_term.rs

1// Generated from definition io.k8s.api.core.v1.PodAffinityTerm
2
3/// Defines a set of pods (namely those matching the labelSelector relative to the given namespace(s)) that this pod should be co-located (affinity) or not co-located (anti-affinity) with, where co-located is defined as running on a node whose value of the label with key \<topologyKey\> matches that of any node on which a pod of the set of pods is running
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct PodAffinityTerm {
6    /// A label query over a set of resources, in this case pods. If it's null, this PodAffinityTerm matches with no Pods.
7    pub label_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>,
8
9    /// MatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both matchLabelKeys and labelSelector. Also, matchLabelKeys cannot be set when labelSelector isn't set.
10    pub match_label_keys: Option<std::vec::Vec<std::string::String>>,
11
12    /// MismatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both mismatchLabelKeys and labelSelector. Also, mismatchLabelKeys cannot be set when labelSelector isn't set.
13    pub mismatch_label_keys: Option<std::vec::Vec<std::string::String>>,
14
15    /// A label query over the set of namespaces that the term applies to. The term is applied to the union of the namespaces selected by this field and the ones listed in the namespaces field. null selector and null or empty namespaces list means "this pod's namespace". An empty selector ({}) matches all namespaces.
16    pub namespace_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>,
17
18    /// namespaces specifies a static list of namespace names that the term applies to. The term is applied to the union of the namespaces listed in this field and the ones selected by namespaceSelector. null or empty namespaces list and null namespaceSelector means "this pod's namespace".
19    pub namespaces: Option<std::vec::Vec<std::string::String>>,
20
21    /// This pod should be co-located (affinity) or not co-located (anti-affinity) with the pods matching the labelSelector in the specified namespaces, where co-located is defined as running on a node whose value of the label with key topologyKey matches that of any node on which any of the selected pods is running. Empty topologyKey is not allowed.
22    pub topology_key: std::string::String,
23}
24
25impl crate::DeepMerge for PodAffinityTerm {
26    fn merge_from(&mut self, other: Self) {
27        crate::DeepMerge::merge_from(&mut self.label_selector, other.label_selector);
28        crate::merge_strategies::list::atomic(&mut self.match_label_keys, other.match_label_keys);
29        crate::merge_strategies::list::atomic(&mut self.mismatch_label_keys, other.mismatch_label_keys);
30        crate::DeepMerge::merge_from(&mut self.namespace_selector, other.namespace_selector);
31        crate::merge_strategies::list::atomic(&mut self.namespaces, other.namespaces);
32        crate::DeepMerge::merge_from(&mut self.topology_key, other.topology_key);
33    }
34}
35
36impl<'de> crate::serde::Deserialize<'de> for PodAffinityTerm {
37    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
38        #[allow(non_camel_case_types)]
39        enum Field {
40            Key_label_selector,
41            Key_match_label_keys,
42            Key_mismatch_label_keys,
43            Key_namespace_selector,
44            Key_namespaces,
45            Key_topology_key,
46            Other,
47        }
48
49        impl<'de> crate::serde::Deserialize<'de> for Field {
50            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
51                struct Visitor;
52
53                impl crate::serde::de::Visitor<'_> for Visitor {
54                    type Value = Field;
55
56                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
57                        f.write_str("field identifier")
58                    }
59
60                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
61                        Ok(match v {
62                            "labelSelector" => Field::Key_label_selector,
63                            "matchLabelKeys" => Field::Key_match_label_keys,
64                            "mismatchLabelKeys" => Field::Key_mismatch_label_keys,
65                            "namespaceSelector" => Field::Key_namespace_selector,
66                            "namespaces" => Field::Key_namespaces,
67                            "topologyKey" => Field::Key_topology_key,
68                            _ => Field::Other,
69                        })
70                    }
71                }
72
73                deserializer.deserialize_identifier(Visitor)
74            }
75        }
76
77        struct Visitor;
78
79        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
80            type Value = PodAffinityTerm;
81
82            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
83                f.write_str("PodAffinityTerm")
84            }
85
86            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
87                let mut value_label_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector> = None;
88                let mut value_match_label_keys: Option<std::vec::Vec<std::string::String>> = None;
89                let mut value_mismatch_label_keys: Option<std::vec::Vec<std::string::String>> = None;
90                let mut value_namespace_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector> = None;
91                let mut value_namespaces: Option<std::vec::Vec<std::string::String>> = None;
92                let mut value_topology_key: Option<std::string::String> = None;
93
94                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
95                    match key {
96                        Field::Key_label_selector => value_label_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
97                        Field::Key_match_label_keys => value_match_label_keys = crate::serde::de::MapAccess::next_value(&mut map)?,
98                        Field::Key_mismatch_label_keys => value_mismatch_label_keys = crate::serde::de::MapAccess::next_value(&mut map)?,
99                        Field::Key_namespace_selector => value_namespace_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
100                        Field::Key_namespaces => value_namespaces = crate::serde::de::MapAccess::next_value(&mut map)?,
101                        Field::Key_topology_key => value_topology_key = crate::serde::de::MapAccess::next_value(&mut map)?,
102                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
103                    }
104                }
105
106                Ok(PodAffinityTerm {
107                    label_selector: value_label_selector,
108                    match_label_keys: value_match_label_keys,
109                    mismatch_label_keys: value_mismatch_label_keys,
110                    namespace_selector: value_namespace_selector,
111                    namespaces: value_namespaces,
112                    topology_key: value_topology_key.unwrap_or_default(),
113                })
114            }
115        }
116
117        deserializer.deserialize_struct(
118            "PodAffinityTerm",
119            &[
120                "labelSelector",
121                "matchLabelKeys",
122                "mismatchLabelKeys",
123                "namespaceSelector",
124                "namespaces",
125                "topologyKey",
126            ],
127            Visitor,
128        )
129    }
130}
131
132impl crate::serde::Serialize for PodAffinityTerm {
133    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
134        let mut state = serializer.serialize_struct(
135            "PodAffinityTerm",
136            1 +
137            self.label_selector.as_ref().map_or(0, |_| 1) +
138            self.match_label_keys.as_ref().map_or(0, |_| 1) +
139            self.mismatch_label_keys.as_ref().map_or(0, |_| 1) +
140            self.namespace_selector.as_ref().map_or(0, |_| 1) +
141            self.namespaces.as_ref().map_or(0, |_| 1),
142        )?;
143        if let Some(value) = &self.label_selector {
144            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "labelSelector", value)?;
145        }
146        if let Some(value) = &self.match_label_keys {
147            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "matchLabelKeys", value)?;
148        }
149        if let Some(value) = &self.mismatch_label_keys {
150            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "mismatchLabelKeys", value)?;
151        }
152        if let Some(value) = &self.namespace_selector {
153            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "namespaceSelector", value)?;
154        }
155        if let Some(value) = &self.namespaces {
156            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "namespaces", value)?;
157        }
158        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "topologyKey", &self.topology_key)?;
159        crate::serde::ser::SerializeStruct::end(state)
160    }
161}
162
163#[cfg(feature = "schemars")]
164impl crate::schemars::JsonSchema for PodAffinityTerm {
165    fn schema_name() -> std::borrow::Cow<'static, str> {
166        "io.k8s.api.core.v1.PodAffinityTerm".into()
167    }
168
169    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
170        crate::schemars::json_schema!({
171            "description": "Defines a set of pods (namely those matching the labelSelector relative to the given namespace(s)) that this pod should be co-located (affinity) or not co-located (anti-affinity) with, where co-located is defined as running on a node whose value of the label with key <topologyKey> matches that of any node on which a pod of the set of pods is running",
172            "type": "object",
173            "properties": {
174                "labelSelector": ({
175                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>();
176                    schema_obj.ensure_object().insert("description".into(), "A label query over a set of resources, in this case pods. If it's null, this PodAffinityTerm matches with no Pods.".into());
177                    schema_obj
178                }),
179                "matchLabelKeys": {
180                    "description": "MatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both matchLabelKeys and labelSelector. Also, matchLabelKeys cannot be set when labelSelector isn't set.",
181                    "type": "array",
182                    "items": {
183                        "type": "string",
184                    },
185                },
186                "mismatchLabelKeys": {
187                    "description": "MismatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both mismatchLabelKeys and labelSelector. Also, mismatchLabelKeys cannot be set when labelSelector isn't set.",
188                    "type": "array",
189                    "items": {
190                        "type": "string",
191                    },
192                },
193                "namespaceSelector": ({
194                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>();
195                    schema_obj.ensure_object().insert("description".into(), "A label query over the set of namespaces that the term applies to. The term is applied to the union of the namespaces selected by this field and the ones listed in the namespaces field. null selector and null or empty namespaces list means \"this pod's namespace\". An empty selector ({}) matches all namespaces.".into());
196                    schema_obj
197                }),
198                "namespaces": {
199                    "description": "namespaces specifies a static list of namespace names that the term applies to. The term is applied to the union of the namespaces listed in this field and the ones selected by namespaceSelector. null or empty namespaces list and null namespaceSelector means \"this pod's namespace\".",
200                    "type": "array",
201                    "items": {
202                        "type": "string",
203                    },
204                },
205                "topologyKey": {
206                    "description": "This pod should be co-located (affinity) or not co-located (anti-affinity) with the pods matching the labelSelector in the specified namespaces, where co-located is defined as running on a node whose value of the label with key topologyKey matches that of any node on which any of the selected pods is running. Empty topologyKey is not allowed.",
207                    "type": "string",
208                },
209            },
210            "required": [
211                "topologyKey",
212            ],
213        })
214    }
215}