k8s_openapi/v1_34/api/resource/v1beta1/
device_class_spec.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct DeviceClassSpec {
6 pub config: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceClassConfiguration>>,
10
11 pub extended_resource_name: Option<std::string::String>,
15
16 pub selectors: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceSelector>>,
18}
19
20impl crate::DeepMerge for DeviceClassSpec {
21 fn merge_from(&mut self, other: Self) {
22 crate::merge_strategies::list::atomic(&mut self.config, other.config);
23 crate::DeepMerge::merge_from(&mut self.extended_resource_name, other.extended_resource_name);
24 crate::merge_strategies::list::atomic(&mut self.selectors, other.selectors);
25 }
26}
27
28impl<'de> crate::serde::Deserialize<'de> for DeviceClassSpec {
29 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
30 #[allow(non_camel_case_types)]
31 enum Field {
32 Key_config,
33 Key_extended_resource_name,
34 Key_selectors,
35 Other,
36 }
37
38 impl<'de> crate::serde::Deserialize<'de> for Field {
39 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
40 struct Visitor;
41
42 impl crate::serde::de::Visitor<'_> for Visitor {
43 type Value = Field;
44
45 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
46 f.write_str("field identifier")
47 }
48
49 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
50 Ok(match v {
51 "config" => Field::Key_config,
52 "extendedResourceName" => Field::Key_extended_resource_name,
53 "selectors" => Field::Key_selectors,
54 _ => Field::Other,
55 })
56 }
57 }
58
59 deserializer.deserialize_identifier(Visitor)
60 }
61 }
62
63 struct Visitor;
64
65 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
66 type Value = DeviceClassSpec;
67
68 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
69 f.write_str("DeviceClassSpec")
70 }
71
72 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
73 let mut value_config: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceClassConfiguration>> = None;
74 let mut value_extended_resource_name: Option<std::string::String> = None;
75 let mut value_selectors: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceSelector>> = None;
76
77 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
78 match key {
79 Field::Key_config => value_config = crate::serde::de::MapAccess::next_value(&mut map)?,
80 Field::Key_extended_resource_name => value_extended_resource_name = crate::serde::de::MapAccess::next_value(&mut map)?,
81 Field::Key_selectors => value_selectors = crate::serde::de::MapAccess::next_value(&mut map)?,
82 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
83 }
84 }
85
86 Ok(DeviceClassSpec {
87 config: value_config,
88 extended_resource_name: value_extended_resource_name,
89 selectors: value_selectors,
90 })
91 }
92 }
93
94 deserializer.deserialize_struct(
95 "DeviceClassSpec",
96 &[
97 "config",
98 "extendedResourceName",
99 "selectors",
100 ],
101 Visitor,
102 )
103 }
104}
105
106impl crate::serde::Serialize for DeviceClassSpec {
107 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
108 let mut state = serializer.serialize_struct(
109 "DeviceClassSpec",
110 self.config.as_ref().map_or(0, |_| 1) +
111 self.extended_resource_name.as_ref().map_or(0, |_| 1) +
112 self.selectors.as_ref().map_or(0, |_| 1),
113 )?;
114 if let Some(value) = &self.config {
115 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "config", value)?;
116 }
117 if let Some(value) = &self.extended_resource_name {
118 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "extendedResourceName", value)?;
119 }
120 if let Some(value) = &self.selectors {
121 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "selectors", value)?;
122 }
123 crate::serde::ser::SerializeStruct::end(state)
124 }
125}
126
127#[cfg(feature = "schemars")]
128impl crate::schemars::JsonSchema for DeviceClassSpec {
129 fn schema_name() -> std::borrow::Cow<'static, str> {
130 "io.k8s.api.resource.v1beta1.DeviceClassSpec".into()
131 }
132
133 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
134 crate::schemars::json_schema!({
135 "description": "DeviceClassSpec is used in a [DeviceClass] to define what can be allocated and how to configure it.",
136 "type": "object",
137 "properties": {
138 "config": {
139 "description": "Config defines configuration parameters that apply to each device that is claimed via this class. Some classses may potentially be satisfied by multiple drivers, so each instance of a vendor configuration applies to exactly one driver.\n\nThey are passed to the driver, but are not considered while allocating the claim.",
140 "type": "array",
141 "items": (__gen.subschema_for::<crate::api::resource::v1beta1::DeviceClassConfiguration>()),
142 },
143 "extendedResourceName": {
144 "description": "ExtendedResourceName is the extended resource name for the devices of this class. The devices of this class can be used to satisfy a pod's extended resource requests. It has the same format as the name of a pod's extended resource. It should be unique among all the device classes in a cluster. If two device classes have the same name, then the class created later is picked to satisfy a pod's extended resource requests. If two classes are created at the same time, then the name of the class lexicographically sorted first is picked.\n\nThis is an alpha field.",
145 "type": "string",
146 },
147 "selectors": {
148 "description": "Each selector must be satisfied by a device which is claimed via this class.",
149 "type": "array",
150 "items": (__gen.subschema_for::<crate::api::resource::v1beta1::DeviceSelector>()),
151 },
152 },
153 })
154 }
155}