k8s_openapi/v1_33/api/resource/v1beta2/
device_constraint.rs

1// Generated from definition io.k8s.api.resource.v1beta2.DeviceConstraint
2
3/// DeviceConstraint must have exactly one field set besides Requests.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct DeviceConstraint {
6    /// MatchAttribute requires that all devices in question have this attribute and that its type and value are the same across those devices.
7    ///
8    /// For example, if you specified "dra.example.com/numa" (a hypothetical example!), then only devices in the same NUMA node will be chosen. A device which does not have that attribute will not be chosen. All devices should use a value of the same type for this attribute because that is part of its specification, but if one device doesn't, then it also will not be chosen.
9    ///
10    /// Must include the domain qualifier.
11    pub match_attribute: Option<std::string::String>,
12
13    /// Requests is a list of the one or more requests in this claim which must co-satisfy this constraint. If a request is fulfilled by multiple devices, then all of the devices must satisfy the constraint. If this is not specified, this constraint applies to all requests in this claim.
14    ///
15    /// References to subrequests must include the name of the main request and may include the subrequest using the format \<main request\>\[/\<subrequest\>\]. If just the main request is given, the constraint applies to all subrequests.
16    pub requests: Option<std::vec::Vec<std::string::String>>,
17}
18
19impl crate::DeepMerge for DeviceConstraint {
20    fn merge_from(&mut self, other: Self) {
21        crate::DeepMerge::merge_from(&mut self.match_attribute, other.match_attribute);
22        crate::merge_strategies::list::atomic(&mut self.requests, other.requests);
23    }
24}
25
26impl<'de> crate::serde::Deserialize<'de> for DeviceConstraint {
27    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
28        #[allow(non_camel_case_types)]
29        enum Field {
30            Key_match_attribute,
31            Key_requests,
32            Other,
33        }
34
35        impl<'de> crate::serde::Deserialize<'de> for Field {
36            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
37                struct Visitor;
38
39                impl crate::serde::de::Visitor<'_> for Visitor {
40                    type Value = Field;
41
42                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
43                        f.write_str("field identifier")
44                    }
45
46                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
47                        Ok(match v {
48                            "matchAttribute" => Field::Key_match_attribute,
49                            "requests" => Field::Key_requests,
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 = DeviceConstraint;
63
64            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
65                f.write_str("DeviceConstraint")
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_match_attribute: Option<std::string::String> = None;
70                let mut value_requests: Option<std::vec::Vec<std::string::String>> = None;
71
72                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
73                    match key {
74                        Field::Key_match_attribute => value_match_attribute = crate::serde::de::MapAccess::next_value(&mut map)?,
75                        Field::Key_requests => value_requests = crate::serde::de::MapAccess::next_value(&mut map)?,
76                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
77                    }
78                }
79
80                Ok(DeviceConstraint {
81                    match_attribute: value_match_attribute,
82                    requests: value_requests,
83                })
84            }
85        }
86
87        deserializer.deserialize_struct(
88            "DeviceConstraint",
89            &[
90                "matchAttribute",
91                "requests",
92            ],
93            Visitor,
94        )
95    }
96}
97
98impl crate::serde::Serialize for DeviceConstraint {
99    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
100        let mut state = serializer.serialize_struct(
101            "DeviceConstraint",
102            self.match_attribute.as_ref().map_or(0, |_| 1) +
103            self.requests.as_ref().map_or(0, |_| 1),
104        )?;
105        if let Some(value) = &self.match_attribute {
106            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "matchAttribute", value)?;
107        }
108        if let Some(value) = &self.requests {
109            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "requests", value)?;
110        }
111        crate::serde::ser::SerializeStruct::end(state)
112    }
113}
114
115#[cfg(feature = "schemars")]
116impl crate::schemars::JsonSchema for DeviceConstraint {
117    fn schema_name() -> std::string::String {
118        "io.k8s.api.resource.v1beta2.DeviceConstraint".into()
119    }
120
121    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
122        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
123            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
124                description: Some("DeviceConstraint must have exactly one field set besides Requests.".into()),
125                ..Default::default()
126            })),
127            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
128            object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
129                properties: [
130                    (
131                        "matchAttribute".into(),
132                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
133                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
134                                description: Some("MatchAttribute requires that all devices in question have this attribute and that its type and value are the same across those devices.\n\nFor example, if you specified \"dra.example.com/numa\" (a hypothetical example!), then only devices in the same NUMA node will be chosen. A device which does not have that attribute will not be chosen. All devices should use a value of the same type for this attribute because that is part of its specification, but if one device doesn't, then it also will not be chosen.\n\nMust include the domain qualifier.".into()),
135                                ..Default::default()
136                            })),
137                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
138                            ..Default::default()
139                        }),
140                    ),
141                    (
142                        "requests".into(),
143                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
144                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
145                                description: Some("Requests is a list of the one or more requests in this claim which must co-satisfy this constraint. If a request is fulfilled by multiple devices, then all of the devices must satisfy the constraint. If this is not specified, this constraint applies to all requests in this claim.\n\nReferences to subrequests must include the name of the main request and may include the subrequest using the format <main request>[/<subrequest>]. If just the main request is given, the constraint applies to all subrequests.".into()),
146                                ..Default::default()
147                            })),
148                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
149                            array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
150                                items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(
151                                    crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
152                                        instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
153                                        ..Default::default()
154                                    })
155                                ))),
156                                ..Default::default()
157                            })),
158                            ..Default::default()
159                        }),
160                    ),
161                ].into(),
162                ..Default::default()
163            })),
164            ..Default::default()
165        })
166    }
167}