Skip to main content

k8s_openapi/v1_36/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    /// DistinctAttribute requires that all devices in question have this attribute and that its type and value are unique across those devices.
7    ///
8    /// When the DRAListTypeAttributes feature gate is enabled, comparison uses set semantics (i.e., element order and duplicates are ignored): list-valued attributes must be pairwise disjoint across devices. Scalar values are treated as singleton sets for backward compatibility.
9    ///
10    /// This acts as the inverse of MatchAttribute.
11    ///
12    /// This constraint is used to avoid allocating multiple requests to the same device by ensuring attribute-level differentiation.
13    ///
14    /// This is useful for scenarios where resource requests must be fulfilled by separate physical devices. For example, a container requests two network interfaces that must be allocated from two different physical NICs.
15    pub distinct_attribute: Option<std::string::String>,
16
17    /// MatchAttribute requires that all devices in question have this attribute and that its type and value are the same across those devices.
18    ///
19    /// 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.
20    ///
21    /// When the DRAListTypeAttributes feature gate is enabled, comparison uses set semantics(i.e., element order and duplicates are ignored): list-valued attributes match when the intersection across all devices is non-empty. Scalar values are treated as singleton sets for backward compatibility.
22    ///
23    /// Must include the domain qualifier.
24    pub match_attribute: Option<std::string::String>,
25
26    /// 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.
27    ///
28    /// 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.
29    pub requests: Option<std::vec::Vec<std::string::String>>,
30}
31
32impl crate::DeepMerge for DeviceConstraint {
33    fn merge_from(&mut self, other: Self) {
34        crate::DeepMerge::merge_from(&mut self.distinct_attribute, other.distinct_attribute);
35        crate::DeepMerge::merge_from(&mut self.match_attribute, other.match_attribute);
36        crate::merge_strategies::list::atomic(&mut self.requests, other.requests);
37    }
38}
39
40impl<'de> crate::serde::Deserialize<'de> for DeviceConstraint {
41    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
42        #[allow(non_camel_case_types)]
43        enum Field {
44            Key_distinct_attribute,
45            Key_match_attribute,
46            Key_requests,
47            Other,
48        }
49
50        impl<'de> crate::serde::Deserialize<'de> for Field {
51            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
52                struct Visitor;
53
54                impl crate::serde::de::Visitor<'_> for Visitor {
55                    type Value = Field;
56
57                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
58                        f.write_str("field identifier")
59                    }
60
61                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
62                        Ok(match v {
63                            "distinctAttribute" => Field::Key_distinct_attribute,
64                            "matchAttribute" => Field::Key_match_attribute,
65                            "requests" => Field::Key_requests,
66                            _ => Field::Other,
67                        })
68                    }
69                }
70
71                deserializer.deserialize_identifier(Visitor)
72            }
73        }
74
75        struct Visitor;
76
77        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
78            type Value = DeviceConstraint;
79
80            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
81                f.write_str("DeviceConstraint")
82            }
83
84            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
85                let mut value_distinct_attribute: Option<std::string::String> = None;
86                let mut value_match_attribute: Option<std::string::String> = None;
87                let mut value_requests: Option<std::vec::Vec<std::string::String>> = None;
88
89                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
90                    match key {
91                        Field::Key_distinct_attribute => value_distinct_attribute = crate::serde::de::MapAccess::next_value(&mut map)?,
92                        Field::Key_match_attribute => value_match_attribute = crate::serde::de::MapAccess::next_value(&mut map)?,
93                        Field::Key_requests => value_requests = crate::serde::de::MapAccess::next_value(&mut map)?,
94                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
95                    }
96                }
97
98                Ok(DeviceConstraint {
99                    distinct_attribute: value_distinct_attribute,
100                    match_attribute: value_match_attribute,
101                    requests: value_requests,
102                })
103            }
104        }
105
106        deserializer.deserialize_struct(
107            "DeviceConstraint",
108            &[
109                "distinctAttribute",
110                "matchAttribute",
111                "requests",
112            ],
113            Visitor,
114        )
115    }
116}
117
118impl crate::serde::Serialize for DeviceConstraint {
119    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
120        let mut state = serializer.serialize_struct(
121            "DeviceConstraint",
122            self.distinct_attribute.as_ref().map_or(0, |_| 1) +
123            self.match_attribute.as_ref().map_or(0, |_| 1) +
124            self.requests.as_ref().map_or(0, |_| 1),
125        )?;
126        if let Some(value) = &self.distinct_attribute {
127            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "distinctAttribute", value)?;
128        }
129        if let Some(value) = &self.match_attribute {
130            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "matchAttribute", value)?;
131        }
132        if let Some(value) = &self.requests {
133            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "requests", value)?;
134        }
135        crate::serde::ser::SerializeStruct::end(state)
136    }
137}
138
139#[cfg(feature = "schemars")]
140impl crate::schemars::JsonSchema for DeviceConstraint {
141    fn schema_name() -> std::borrow::Cow<'static, str> {
142        "io.k8s.api.resource.v1beta2.DeviceConstraint".into()
143    }
144
145    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
146        crate::schemars::json_schema!({
147            "description": "DeviceConstraint must have exactly one field set besides Requests.",
148            "type": "object",
149            "properties": {
150                "distinctAttribute": {
151                    "description": "DistinctAttribute requires that all devices in question have this attribute and that its type and value are unique across those devices.\n\nWhen the DRAListTypeAttributes feature gate is enabled, comparison uses set semantics (i.e., element order and duplicates are ignored): list-valued attributes must be pairwise disjoint across devices. Scalar values are treated as singleton sets for backward compatibility.\n\nThis acts as the inverse of MatchAttribute.\n\nThis constraint is used to avoid allocating multiple requests to the same device by ensuring attribute-level differentiation.\n\nThis is useful for scenarios where resource requests must be fulfilled by separate physical devices. For example, a container requests two network interfaces that must be allocated from two different physical NICs.",
152                    "type": "string",
153                },
154                "matchAttribute": {
155                    "description": "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\nWhen the DRAListTypeAttributes feature gate is enabled, comparison uses set semantics(i.e., element order and duplicates are ignored): list-valued attributes match when the intersection across all devices is non-empty. Scalar values are treated as singleton sets for backward compatibility.\n\nMust include the domain qualifier.",
156                    "type": "string",
157                },
158                "requests": {
159                    "description": "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.",
160                    "type": "array",
161                    "items": {
162                        "type": "string",
163                    },
164                },
165            },
166        })
167    }
168}
169
170#[cfg(feature = "schemars08")]
171impl crate::schemars08::JsonSchema for DeviceConstraint {
172    fn schema_name() -> std::string::String {
173        "io.k8s.api.resource.v1beta2.DeviceConstraint".into()
174    }
175
176    fn json_schema(__gen: &mut crate::schemars08::gen::SchemaGenerator) -> crate::schemars08::schema::Schema {
177        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
178            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
179                description: Some("DeviceConstraint must have exactly one field set besides Requests.".into()),
180                ..Default::default()
181            })),
182            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Object))),
183            object: Some(std::boxed::Box::new(crate::schemars08::schema::ObjectValidation {
184                properties: [
185                    (
186                        "distinctAttribute".into(),
187                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
188                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
189                                description: Some("DistinctAttribute requires that all devices in question have this attribute and that its type and value are unique across those devices.\n\nWhen the DRAListTypeAttributes feature gate is enabled, comparison uses set semantics (i.e., element order and duplicates are ignored): list-valued attributes must be pairwise disjoint across devices. Scalar values are treated as singleton sets for backward compatibility.\n\nThis acts as the inverse of MatchAttribute.\n\nThis constraint is used to avoid allocating multiple requests to the same device by ensuring attribute-level differentiation.\n\nThis is useful for scenarios where resource requests must be fulfilled by separate physical devices. For example, a container requests two network interfaces that must be allocated from two different physical NICs.".into()),
190                                ..Default::default()
191                            })),
192                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
193                            ..Default::default()
194                        }),
195                    ),
196                    (
197                        "matchAttribute".into(),
198                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
199                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
200                                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\nWhen the DRAListTypeAttributes feature gate is enabled, comparison uses set semantics(i.e., element order and duplicates are ignored): list-valued attributes match when the intersection across all devices is non-empty. Scalar values are treated as singleton sets for backward compatibility.\n\nMust include the domain qualifier.".into()),
201                                ..Default::default()
202                            })),
203                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
204                            ..Default::default()
205                        }),
206                    ),
207                    (
208                        "requests".into(),
209                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
210                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
211                                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()),
212                                ..Default::default()
213                            })),
214                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Array))),
215                            array: Some(std::boxed::Box::new(crate::schemars08::schema::ArrayValidation {
216                                items: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(
217                                    crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
218                                        instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
219                                        ..Default::default()
220                                    })
221                                ))),
222                                ..Default::default()
223                            })),
224                            ..Default::default()
225                        }),
226                    ),
227                ].into(),
228                ..Default::default()
229            })),
230            ..Default::default()
231        })
232    }
233}