k8s_openapi/v1_32/api/resource/v1alpha3/
device_constraint.rs

1// Generated from definition io.k8s.api.resource.v1alpha3.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<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    pub requests: Option<Vec<String>>,
15}
16
17impl crate::DeepMerge for DeviceConstraint {
18    fn merge_from(&mut self, other: Self) {
19        crate::DeepMerge::merge_from(&mut self.match_attribute, other.match_attribute);
20        crate::merge_strategies::list::atomic(&mut self.requests, other.requests);
21    }
22}
23
24impl<'de> crate::serde::Deserialize<'de> for DeviceConstraint {
25    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
26        #[allow(non_camel_case_types)]
27        enum Field {
28            Key_match_attribute,
29            Key_requests,
30            Other,
31        }
32
33        impl<'de> crate::serde::Deserialize<'de> for Field {
34            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
35                struct Visitor;
36
37                impl crate::serde::de::Visitor<'_> for Visitor {
38                    type Value = Field;
39
40                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41                        f.write_str("field identifier")
42                    }
43
44                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
45                        Ok(match v {
46                            "matchAttribute" => Field::Key_match_attribute,
47                            "requests" => Field::Key_requests,
48                            _ => Field::Other,
49                        })
50                    }
51                }
52
53                deserializer.deserialize_identifier(Visitor)
54            }
55        }
56
57        struct Visitor;
58
59        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
60            type Value = DeviceConstraint;
61
62            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
63                f.write_str("DeviceConstraint")
64            }
65
66            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
67                let mut value_match_attribute: Option<String> = None;
68                let mut value_requests: Option<Vec<String>> = None;
69
70                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
71                    match key {
72                        Field::Key_match_attribute => value_match_attribute = crate::serde::de::MapAccess::next_value(&mut map)?,
73                        Field::Key_requests => value_requests = crate::serde::de::MapAccess::next_value(&mut map)?,
74                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
75                    }
76                }
77
78                Ok(DeviceConstraint {
79                    match_attribute: value_match_attribute,
80                    requests: value_requests,
81                })
82            }
83        }
84
85        deserializer.deserialize_struct(
86            "DeviceConstraint",
87            &[
88                "matchAttribute",
89                "requests",
90            ],
91            Visitor,
92        )
93    }
94}
95
96impl crate::serde::Serialize for DeviceConstraint {
97    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
98        let mut state = serializer.serialize_struct(
99            "DeviceConstraint",
100            self.match_attribute.as_ref().map_or(0, |_| 1) +
101            self.requests.as_ref().map_or(0, |_| 1),
102        )?;
103        if let Some(value) = &self.match_attribute {
104            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "matchAttribute", value)?;
105        }
106        if let Some(value) = &self.requests {
107            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "requests", value)?;
108        }
109        crate::serde::ser::SerializeStruct::end(state)
110    }
111}
112
113#[cfg(feature = "schemars")]
114impl crate::schemars::JsonSchema for DeviceConstraint {
115    fn schema_name() -> String {
116        "io.k8s.api.resource.v1alpha3.DeviceConstraint".to_owned()
117    }
118
119    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
120        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
121            metadata: Some(Box::new(crate::schemars::schema::Metadata {
122                description: Some("DeviceConstraint must have exactly one field set besides Requests.".to_owned()),
123                ..Default::default()
124            })),
125            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
126            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
127                properties: [
128                    (
129                        "matchAttribute".to_owned(),
130                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
131                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
132                                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.".to_owned()),
133                                ..Default::default()
134                            })),
135                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
136                            ..Default::default()
137                        }),
138                    ),
139                    (
140                        "requests".to_owned(),
141                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
142                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
143                                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.".to_owned()),
144                                ..Default::default()
145                            })),
146                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
147                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
148                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
149                                    crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
150                                        instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
151                                        ..Default::default()
152                                    })
153                                ))),
154                                ..Default::default()
155                            })),
156                            ..Default::default()
157                        }),
158                    ),
159                ].into(),
160                ..Default::default()
161            })),
162            ..Default::default()
163        })
164    }
165}