1// Generated from definition io.k8s.api.resource.v1alpha3.CounterSet
23/// CounterSet defines a named set of counters that are available to be used by devices defined in the ResourceSlice.
4///
5/// The counters are not allocatable by themselves, but can be referenced by devices. When a device is allocated, the portion of counters it uses will no longer be available for use by other devices.
6#[derive(Clone, Debug, Default, PartialEq)]
7pub struct CounterSet {
8/// Counters defines the counters that will be consumed by the device. The name of each counter must be unique in that set and must be a DNS label.
9 ///
10 /// To ensure this uniqueness, capacities defined by the vendor must be listed without the driver name as domain prefix in their name. All others must be listed with their domain prefix.
11 ///
12 /// The maximum number of counters is 32.
13pub counters: std::collections::BTreeMap<std::string::String, crate::api::resource::v1alpha3::Counter>,
1415/// CounterSet is the name of the set from which the counters defined will be consumed.
16pub name: std::string::String,
17}
1819impl crate::DeepMerge for CounterSet {
20fn merge_from(&mut self, other: Self) {
21crate::merge_strategies::map::granular(&mut self.counters, other.counters, |current_item, other_item| {
22crate::DeepMerge::merge_from(current_item, other_item);
23 });
24crate::DeepMerge::merge_from(&mut self.name, other.name);
25 }
26}
2728impl<'de> crate::serde::Deserialize<'de> for CounterSet {
29fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
30#[allow(non_camel_case_types)]
31enum Field {
32 Key_counters,
33 Key_name,
34 Other,
35 }
3637impl<'de> crate::serde::Deserialize<'de> for Field {
38fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
39struct Visitor;
4041impl crate::serde::de::Visitor<'_> for Visitor {
42type Value = Field;
4344fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
45 f.write_str("field identifier")
46 }
4748fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
49Ok(match v {
50"counters" => Field::Key_counters,
51"name" => Field::Key_name,
52_ => Field::Other,
53 })
54 }
55 }
5657 deserializer.deserialize_identifier(Visitor)
58 }
59 }
6061struct Visitor;
6263impl<'de> crate::serde::de::Visitor<'de> for Visitor {
64type Value = CounterSet;
6566fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
67 f.write_str("CounterSet")
68 }
6970fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
71let mut value_counters: Option<std::collections::BTreeMap<std::string::String, crate::api::resource::v1alpha3::Counter>> = None;
72let mut value_name: Option<std::string::String> = None;
7374while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
75match key {
76 Field::Key_counters => value_counters = crate::serde::de::MapAccess::next_value(&mut map)?,
77 Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
78 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
79 }
80 }
8182Ok(CounterSet {
83 counters: value_counters.unwrap_or_default(),
84 name: value_name.unwrap_or_default(),
85 })
86 }
87 }
8889 deserializer.deserialize_struct(
90"CounterSet",
91&[
92"counters",
93"name",
94 ],
95 Visitor,
96 )
97 }
98}
99100impl crate::serde::Serialize for CounterSet {
101fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
102let mut state = serializer.serialize_struct(
103"CounterSet",
1042,
105 )?;
106crate::serde::ser::SerializeStruct::serialize_field(&mut state, "counters", &self.counters)?;
107crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
108crate::serde::ser::SerializeStruct::end(state)
109 }
110}
111112#[cfg(feature = "schemars")]
113impl crate::schemars::JsonSchema for CounterSet {
114fn schema_name() -> std::string::String {
115"io.k8s.api.resource.v1alpha3.CounterSet".into()
116 }
117118fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
119crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
120 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
121 description: Some("CounterSet defines a named set of counters that are available to be used by devices defined in the ResourceSlice.\n\nThe counters are not allocatable by themselves, but can be referenced by devices. When a device is allocated, the portion of counters it uses will no longer be available for use by other devices.".into()),
122 ..Default::default()
123 })),
124 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
125 object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
126 properties: [
127 (
128"counters".into(),
129crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
130 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
131 description: Some("Counters defines the counters that will be consumed by the device. The name of each counter must be unique in that set and must be a DNS label.\n\nTo ensure this uniqueness, capacities defined by the vendor must be listed without the driver name as domain prefix in their name. All others must be listed with their domain prefix.\n\nThe maximum number of counters is 32.".into()),
132 ..Default::default()
133 })),
134 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
135 object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
136 additional_properties: Some(std::boxed::Box::new(__gen.subschema_for::<crate::api::resource::v1alpha3::Counter>())),
137 ..Default::default()
138 })),
139 ..Default::default()
140 }),
141 ),
142 (
143"name".into(),
144crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
145 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
146 description: Some("CounterSet is the name of the set from which the counters defined will be consumed.".into()),
147 ..Default::default()
148 })),
149 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
150 ..Default::default()
151 }),
152 ),
153 ].into(),
154 required: [
155"counters".into(),
156"name".into(),
157 ].into(),
158 ..Default::default()
159 })),
160 ..Default::default()
161 })
162 }
163}