k8s_openapi/v1_30/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. This is an alpha field and requires enabling MatchLabelKeysInPodAffinity feature gate.
10    pub match_label_keys: Option<Vec<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. This is an alpha field and requires enabling MatchLabelKeysInPodAffinity feature gate.
13    pub mismatch_label_keys: Option<Vec<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<Vec<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: 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 std::fmt::Formatter<'_>) -> std::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 std::fmt::Formatter<'_>) -> std::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<Vec<String>> = None;
89                let mut value_mismatch_label_keys: Option<Vec<String>> = None;
90                let mut value_namespace_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector> = None;
91                let mut value_namespaces: Option<Vec<String>> = None;
92                let mut value_topology_key: Option<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() -> String {
166        "io.k8s.api.core.v1.PodAffinityTerm".to_owned()
167    }
168
169    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
170        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
171            metadata: Some(Box::new(crate::schemars::schema::Metadata {
172                description: Some("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".to_owned()),
173                ..Default::default()
174            })),
175            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
176            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
177                properties: [
178                    (
179                        "labelSelector".to_owned(),
180                        {
181                            let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>().into_object();
182                            schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
183                                description: Some("A label query over a set of resources, in this case pods. If it's null, this PodAffinityTerm matches with no Pods.".to_owned()),
184                                ..Default::default()
185                            }));
186                            crate::schemars::schema::Schema::Object(schema_obj)
187                        },
188                    ),
189                    (
190                        "matchLabelKeys".to_owned(),
191                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
192                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
193                                description: Some("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. This is an alpha field and requires enabling MatchLabelKeysInPodAffinity feature gate.".to_owned()),
194                                ..Default::default()
195                            })),
196                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
197                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
198                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
199                                    crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
200                                        instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
201                                        ..Default::default()
202                                    })
203                                ))),
204                                ..Default::default()
205                            })),
206                            ..Default::default()
207                        }),
208                    ),
209                    (
210                        "mismatchLabelKeys".to_owned(),
211                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
212                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
213                                description: Some("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. This is an alpha field and requires enabling MatchLabelKeysInPodAffinity feature gate.".to_owned()),
214                                ..Default::default()
215                            })),
216                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
217                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
218                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
219                                    crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
220                                        instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
221                                        ..Default::default()
222                                    })
223                                ))),
224                                ..Default::default()
225                            })),
226                            ..Default::default()
227                        }),
228                    ),
229                    (
230                        "namespaceSelector".to_owned(),
231                        {
232                            let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>().into_object();
233                            schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
234                                description: Some("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.".to_owned()),
235                                ..Default::default()
236                            }));
237                            crate::schemars::schema::Schema::Object(schema_obj)
238                        },
239                    ),
240                    (
241                        "namespaces".to_owned(),
242                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
243                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
244                                description: Some("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\".".to_owned()),
245                                ..Default::default()
246                            })),
247                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
248                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
249                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
250                                    crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
251                                        instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
252                                        ..Default::default()
253                                    })
254                                ))),
255                                ..Default::default()
256                            })),
257                            ..Default::default()
258                        }),
259                    ),
260                    (
261                        "topologyKey".to_owned(),
262                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
263                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
264                                description: Some("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.".to_owned()),
265                                ..Default::default()
266                            })),
267                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
268                            ..Default::default()
269                        }),
270                    ),
271                ].into(),
272                required: [
273                    "topologyKey".to_owned(),
274                ].into(),
275                ..Default::default()
276            })),
277            ..Default::default()
278        })
279    }
280}