Skip to main content

k8s_openapi/v1_36/api/scheduling/v1alpha2/
pod_group_scheduling_constraints.rs

1// Generated from definition io.k8s.api.scheduling.v1alpha2.PodGroupSchedulingConstraints
2
3/// PodGroupSchedulingConstraints defines scheduling constraints (e.g. topology) for a PodGroup.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct PodGroupSchedulingConstraints {
6    /// Topology defines the topology constraints for the pod group. Currently only a single topology constraint can be specified. This may change in the future.
7    pub topology: Option<std::vec::Vec<crate::api::scheduling::v1alpha2::TopologyConstraint>>,
8}
9
10impl crate::DeepMerge for PodGroupSchedulingConstraints {
11    fn merge_from(&mut self, other: Self) {
12        crate::merge_strategies::list::atomic(&mut self.topology, other.topology);
13    }
14}
15
16impl<'de> crate::serde::Deserialize<'de> for PodGroupSchedulingConstraints {
17    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
18        #[allow(non_camel_case_types)]
19        enum Field {
20            Key_topology,
21            Other,
22        }
23
24        impl<'de> crate::serde::Deserialize<'de> for Field {
25            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
26                struct Visitor;
27
28                impl crate::serde::de::Visitor<'_> for Visitor {
29                    type Value = Field;
30
31                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
32                        f.write_str("field identifier")
33                    }
34
35                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
36                        Ok(match v {
37                            "topology" => Field::Key_topology,
38                            _ => Field::Other,
39                        })
40                    }
41                }
42
43                deserializer.deserialize_identifier(Visitor)
44            }
45        }
46
47        struct Visitor;
48
49        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
50            type Value = PodGroupSchedulingConstraints;
51
52            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
53                f.write_str("PodGroupSchedulingConstraints")
54            }
55
56            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
57                let mut value_topology: Option<std::vec::Vec<crate::api::scheduling::v1alpha2::TopologyConstraint>> = None;
58
59                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
60                    match key {
61                        Field::Key_topology => value_topology = crate::serde::de::MapAccess::next_value(&mut map)?,
62                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
63                    }
64                }
65
66                Ok(PodGroupSchedulingConstraints {
67                    topology: value_topology,
68                })
69            }
70        }
71
72        deserializer.deserialize_struct(
73            "PodGroupSchedulingConstraints",
74            &[
75                "topology",
76            ],
77            Visitor,
78        )
79    }
80}
81
82impl crate::serde::Serialize for PodGroupSchedulingConstraints {
83    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
84        let mut state = serializer.serialize_struct(
85            "PodGroupSchedulingConstraints",
86            self.topology.as_ref().map_or(0, |_| 1),
87        )?;
88        if let Some(value) = &self.topology {
89            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "topology", value)?;
90        }
91        crate::serde::ser::SerializeStruct::end(state)
92    }
93}
94
95#[cfg(feature = "schemars")]
96impl crate::schemars::JsonSchema for PodGroupSchedulingConstraints {
97    fn schema_name() -> std::borrow::Cow<'static, str> {
98        "io.k8s.api.scheduling.v1alpha2.PodGroupSchedulingConstraints".into()
99    }
100
101    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
102        crate::schemars::json_schema!({
103            "description": "PodGroupSchedulingConstraints defines scheduling constraints (e.g. topology) for a PodGroup.",
104            "type": "object",
105            "properties": {
106                "topology": {
107                    "description": "Topology defines the topology constraints for the pod group. Currently only a single topology constraint can be specified. This may change in the future.",
108                    "type": "array",
109                    "items": (__gen.subschema_for::<crate::api::scheduling::v1alpha2::TopologyConstraint>()),
110                },
111            },
112        })
113    }
114}
115
116#[cfg(feature = "schemars08")]
117impl crate::schemars08::JsonSchema for PodGroupSchedulingConstraints {
118    fn schema_name() -> std::string::String {
119        "io.k8s.api.scheduling.v1alpha2.PodGroupSchedulingConstraints".into()
120    }
121
122    fn json_schema(__gen: &mut crate::schemars08::gen::SchemaGenerator) -> crate::schemars08::schema::Schema {
123        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
124            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
125                description: Some("PodGroupSchedulingConstraints defines scheduling constraints (e.g. topology) for a PodGroup.".into()),
126                ..Default::default()
127            })),
128            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Object))),
129            object: Some(std::boxed::Box::new(crate::schemars08::schema::ObjectValidation {
130                properties: [
131                    (
132                        "topology".into(),
133                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
134                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
135                                description: Some("Topology defines the topology constraints for the pod group. Currently only a single topology constraint can be specified. This may change in the future.".into()),
136                                ..Default::default()
137                            })),
138                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Array))),
139                            array: Some(std::boxed::Box::new(crate::schemars08::schema::ArrayValidation {
140                                items: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::scheduling::v1alpha2::TopologyConstraint>()))),
141                                ..Default::default()
142                            })),
143                            ..Default::default()
144                        }),
145                    ),
146                ].into(),
147                ..Default::default()
148            })),
149            ..Default::default()
150        })
151    }
152}