k8s_openapi/v1_33/api/resource/v1alpha3/
counter_set.rs

1// Generated from definition io.k8s.api.resource.v1alpha3.CounterSet
2
3/// 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.
13    pub counters: std::collections::BTreeMap<std::string::String, crate::api::resource::v1alpha3::Counter>,
14
15    /// CounterSet is the name of the set from which the counters defined will be consumed.
16    pub name: std::string::String,
17}
18
19impl crate::DeepMerge for CounterSet {
20    fn merge_from(&mut self, other: Self) {
21        crate::merge_strategies::map::granular(&mut self.counters, other.counters, |current_item, other_item| {
22            crate::DeepMerge::merge_from(current_item, other_item);
23        });
24        crate::DeepMerge::merge_from(&mut self.name, other.name);
25    }
26}
27
28impl<'de> crate::serde::Deserialize<'de> for CounterSet {
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_counters,
33            Key_name,
34            Other,
35        }
36
37        impl<'de> crate::serde::Deserialize<'de> for Field {
38            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
39                struct Visitor;
40
41                impl crate::serde::de::Visitor<'_> for Visitor {
42                    type Value = Field;
43
44                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
45                        f.write_str("field identifier")
46                    }
47
48                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
49                        Ok(match v {
50                            "counters" => Field::Key_counters,
51                            "name" => Field::Key_name,
52                            _ => Field::Other,
53                        })
54                    }
55                }
56
57                deserializer.deserialize_identifier(Visitor)
58            }
59        }
60
61        struct Visitor;
62
63        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
64            type Value = CounterSet;
65
66            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
67                f.write_str("CounterSet")
68            }
69
70            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
71                let mut value_counters: Option<std::collections::BTreeMap<std::string::String, crate::api::resource::v1alpha3::Counter>> = None;
72                let mut value_name: Option<std::string::String> = None;
73
74                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
75                    match 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                }
81
82                Ok(CounterSet {
83                    counters: value_counters.unwrap_or_default(),
84                    name: value_name.unwrap_or_default(),
85                })
86            }
87        }
88
89        deserializer.deserialize_struct(
90            "CounterSet",
91            &[
92                "counters",
93                "name",
94            ],
95            Visitor,
96        )
97    }
98}
99
100impl crate::serde::Serialize for CounterSet {
101    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
102        let mut state = serializer.serialize_struct(
103            "CounterSet",
104            2,
105        )?;
106        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "counters", &self.counters)?;
107        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
108        crate::serde::ser::SerializeStruct::end(state)
109    }
110}
111
112#[cfg(feature = "schemars")]
113impl crate::schemars::JsonSchema for CounterSet {
114    fn schema_name() -> std::string::String {
115        "io.k8s.api.resource.v1alpha3.CounterSet".into()
116    }
117
118    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
119        crate::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(),
129                        crate::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(),
144                        crate::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}