k8s_openapi/v1_34/api/resource/v1/
device_constraint.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct DeviceConstraint {
6 pub distinct_attribute: Option<std::string::String>,
14
15 pub match_attribute: Option<std::string::String>,
21
22 pub requests: Option<std::vec::Vec<std::string::String>>,
26}
27
28impl crate::DeepMerge for DeviceConstraint {
29 fn merge_from(&mut self, other: Self) {
30 crate::DeepMerge::merge_from(&mut self.distinct_attribute, other.distinct_attribute);
31 crate::DeepMerge::merge_from(&mut self.match_attribute, other.match_attribute);
32 crate::merge_strategies::list::atomic(&mut self.requests, other.requests);
33 }
34}
35
36impl<'de> crate::serde::Deserialize<'de> for DeviceConstraint {
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_distinct_attribute,
41 Key_match_attribute,
42 Key_requests,
43 Other,
44 }
45
46 impl<'de> crate::serde::Deserialize<'de> for Field {
47 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
48 struct Visitor;
49
50 impl crate::serde::de::Visitor<'_> for Visitor {
51 type Value = Field;
52
53 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
54 f.write_str("field identifier")
55 }
56
57 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
58 Ok(match v {
59 "distinctAttribute" => Field::Key_distinct_attribute,
60 "matchAttribute" => Field::Key_match_attribute,
61 "requests" => Field::Key_requests,
62 _ => Field::Other,
63 })
64 }
65 }
66
67 deserializer.deserialize_identifier(Visitor)
68 }
69 }
70
71 struct Visitor;
72
73 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
74 type Value = DeviceConstraint;
75
76 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
77 f.write_str("DeviceConstraint")
78 }
79
80 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
81 let mut value_distinct_attribute: Option<std::string::String> = None;
82 let mut value_match_attribute: Option<std::string::String> = None;
83 let mut value_requests: Option<std::vec::Vec<std::string::String>> = None;
84
85 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
86 match key {
87 Field::Key_distinct_attribute => value_distinct_attribute = crate::serde::de::MapAccess::next_value(&mut map)?,
88 Field::Key_match_attribute => value_match_attribute = crate::serde::de::MapAccess::next_value(&mut map)?,
89 Field::Key_requests => value_requests = crate::serde::de::MapAccess::next_value(&mut map)?,
90 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
91 }
92 }
93
94 Ok(DeviceConstraint {
95 distinct_attribute: value_distinct_attribute,
96 match_attribute: value_match_attribute,
97 requests: value_requests,
98 })
99 }
100 }
101
102 deserializer.deserialize_struct(
103 "DeviceConstraint",
104 &[
105 "distinctAttribute",
106 "matchAttribute",
107 "requests",
108 ],
109 Visitor,
110 )
111 }
112}
113
114impl crate::serde::Serialize for DeviceConstraint {
115 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
116 let mut state = serializer.serialize_struct(
117 "DeviceConstraint",
118 self.distinct_attribute.as_ref().map_or(0, |_| 1) +
119 self.match_attribute.as_ref().map_or(0, |_| 1) +
120 self.requests.as_ref().map_or(0, |_| 1),
121 )?;
122 if let Some(value) = &self.distinct_attribute {
123 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "distinctAttribute", value)?;
124 }
125 if let Some(value) = &self.match_attribute {
126 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "matchAttribute", value)?;
127 }
128 if let Some(value) = &self.requests {
129 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "requests", value)?;
130 }
131 crate::serde::ser::SerializeStruct::end(state)
132 }
133}
134
135#[cfg(feature = "schemars")]
136impl crate::schemars::JsonSchema for DeviceConstraint {
137 fn schema_name() -> std::borrow::Cow<'static, str> {
138 "io.k8s.api.resource.v1.DeviceConstraint".into()
139 }
140
141 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
142 crate::schemars::json_schema!({
143 "description": "DeviceConstraint must have exactly one field set besides Requests.",
144 "type": "object",
145 "properties": {
146 "distinctAttribute": {
147 "description": "DistinctAttribute requires that all devices in question have this attribute and that its type and value are unique across those devices.\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.",
148 "type": "string",
149 },
150 "matchAttribute": {
151 "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\nMust include the domain qualifier.",
152 "type": "string",
153 },
154 "requests": {
155 "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.",
156 "type": "array",
157 "items": {
158 "type": "string",
159 },
160 },
161 },
162 })
163 }
164}