k8s_openapi/v1_37/api/resource/v1beta2/
device_counter_consumption.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct DeviceCounterConsumption {
6 pub compatibility_groups: Option<std::vec::Vec<std::string::String>>,
16
17 pub counter_set: std::string::String,
19
20 pub counters: std::collections::BTreeMap<std::string::String, crate::api::resource::v1beta2::Counter>,
24}
25
26impl crate::DeepMerge for DeviceCounterConsumption {
27 fn merge_from(&mut self, other: Self) {
28 crate::merge_strategies::list::atomic(&mut self.compatibility_groups, other.compatibility_groups);
29 crate::DeepMerge::merge_from(&mut self.counter_set, other.counter_set);
30 crate::merge_strategies::map::granular(&mut self.counters, other.counters, |current_item, other_item| {
31 crate::DeepMerge::merge_from(current_item, other_item);
32 });
33 }
34}
35
36impl<'de> crate::serde::Deserialize<'de> for DeviceCounterConsumption {
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_compatibility_groups,
41 Key_counter_set,
42 Key_counters,
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 "compatibilityGroups" => Field::Key_compatibility_groups,
60 "counterSet" => Field::Key_counter_set,
61 "counters" => Field::Key_counters,
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 = DeviceCounterConsumption;
75
76 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
77 f.write_str("DeviceCounterConsumption")
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_compatibility_groups: Option<std::vec::Vec<std::string::String>> = None;
82 let mut value_counter_set: Option<std::string::String> = None;
83 let mut value_counters: Option<std::collections::BTreeMap<std::string::String, crate::api::resource::v1beta2::Counter>> = None;
84
85 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
86 match key {
87 Field::Key_compatibility_groups => value_compatibility_groups = crate::serde::de::MapAccess::next_value(&mut map)?,
88 Field::Key_counter_set => value_counter_set = crate::serde::de::MapAccess::next_value(&mut map)?,
89 Field::Key_counters => value_counters = 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(DeviceCounterConsumption {
95 compatibility_groups: value_compatibility_groups,
96 counter_set: value_counter_set.unwrap_or_default(),
97 counters: value_counters.unwrap_or_default(),
98 })
99 }
100 }
101
102 deserializer.deserialize_struct(
103 "DeviceCounterConsumption",
104 &[
105 "compatibilityGroups",
106 "counterSet",
107 "counters",
108 ],
109 Visitor,
110 )
111 }
112}
113
114impl crate::serde::Serialize for DeviceCounterConsumption {
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 "DeviceCounterConsumption",
118 2 +
119 self.compatibility_groups.as_ref().map_or(0, |_| 1),
120 )?;
121 if let Some(value) = &self.compatibility_groups {
122 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "compatibilityGroups", value)?;
123 }
124 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "counterSet", &self.counter_set)?;
125 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "counters", &self.counters)?;
126 crate::serde::ser::SerializeStruct::end(state)
127 }
128}
129
130#[cfg(feature = "schemars")]
131impl crate::schemars::JsonSchema for DeviceCounterConsumption {
132 fn schema_name() -> std::borrow::Cow<'static, str> {
133 "io.k8s.api.resource.v1beta2.DeviceCounterConsumption".into()
134 }
135
136 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
137 crate::schemars::json_schema!({
138 "description": "DeviceCounterConsumption defines a set of counters that a device will consume from a CounterSet.",
139 "type": "object",
140 "properties": {
141 "compatibilityGroups": {
142 "description": "CompatibilityGroups is a list of opaque group names for this counter set consumption.\n\nDevices that consume counters from the same counter set may only be allocated at the same time (\"co-allocated\") if they all share at least one common group: the intersection of the CompatibilityGroups of all co-allocated devices on that counter set must be non-empty. Devices that consume from different counter sets are never compared via this field.\n\nAn unset field, an explicit nil, and an empty list are equivalent and mean \"no groups\": such a device is only co-allocatable with sibling devices on the same counter set that also have no groups, and is never co-allocatable with a device that declares one or more groups.\n\nGroup names are opaque and meaningful only within the publishing driver's pool.\n\nThe maximum number of groups is 2, and the names must be unique.",
143 "type": "array",
144 "items": {
145 "type": "string",
146 },
147 },
148 "counterSet": {
149 "description": "CounterSet is the name of the set from which the counters defined will be consumed.",
150 "type": "string",
151 },
152 "counters": {
153 "description": "Counters defines the counters that will be consumed by the device.\n\nThe maximum number of counters is 32.",
154 "type": "object",
155 "additionalProperties": (__gen.subschema_for::<crate::api::resource::v1beta2::Counter>()),
156 },
157 },
158 "required": [
159 "counterSet",
160 "counters",
161 ],
162 })
163 }
164}