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

1// Generated from definition io.k8s.api.resource.v1alpha3.ResourcePool
2
3/// ResourcePool describes the pool that ResourceSlices belong to.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ResourcePool {
6    /// Generation tracks the change in a pool over time. Whenever a driver changes something about one or more of the resources in a pool, it must change the generation in all ResourceSlices which are part of that pool. Consumers of ResourceSlices should only consider resources from the pool with the highest generation number. The generation may be reset by drivers, which should be fine for consumers, assuming that all ResourceSlices in a pool are updated to match or deleted.
7    ///
8    /// Combined with ResourceSliceCount, this mechanism enables consumers to detect pools which are comprised of multiple ResourceSlices and are in an incomplete state.
9    pub generation: i64,
10
11    /// Name is used to identify the pool. For node-local devices, this is often the node name, but this is not required.
12    ///
13    /// It must not be longer than 253 characters and must consist of one or more DNS sub-domains separated by slashes. This field is immutable.
14    pub name: String,
15
16    /// ResourceSliceCount is the total number of ResourceSlices in the pool at this generation number. Must be greater than zero.
17    ///
18    /// Consumers can use this to check whether they have seen all ResourceSlices belonging to the same pool.
19    pub resource_slice_count: i64,
20}
21
22impl crate::DeepMerge for ResourcePool {
23    fn merge_from(&mut self, other: Self) {
24        crate::DeepMerge::merge_from(&mut self.generation, other.generation);
25        crate::DeepMerge::merge_from(&mut self.name, other.name);
26        crate::DeepMerge::merge_from(&mut self.resource_slice_count, other.resource_slice_count);
27    }
28}
29
30impl<'de> crate::serde::Deserialize<'de> for ResourcePool {
31    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
32        #[allow(non_camel_case_types)]
33        enum Field {
34            Key_generation,
35            Key_name,
36            Key_resource_slice_count,
37            Other,
38        }
39
40        impl<'de> crate::serde::Deserialize<'de> for Field {
41            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
42                struct Visitor;
43
44                impl crate::serde::de::Visitor<'_> for Visitor {
45                    type Value = Field;
46
47                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
48                        f.write_str("field identifier")
49                    }
50
51                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
52                        Ok(match v {
53                            "generation" => Field::Key_generation,
54                            "name" => Field::Key_name,
55                            "resourceSliceCount" => Field::Key_resource_slice_count,
56                            _ => Field::Other,
57                        })
58                    }
59                }
60
61                deserializer.deserialize_identifier(Visitor)
62            }
63        }
64
65        struct Visitor;
66
67        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
68            type Value = ResourcePool;
69
70            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
71                f.write_str("ResourcePool")
72            }
73
74            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
75                let mut value_generation: Option<i64> = None;
76                let mut value_name: Option<String> = None;
77                let mut value_resource_slice_count: Option<i64> = None;
78
79                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
80                    match key {
81                        Field::Key_generation => value_generation = crate::serde::de::MapAccess::next_value(&mut map)?,
82                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
83                        Field::Key_resource_slice_count => value_resource_slice_count = crate::serde::de::MapAccess::next_value(&mut map)?,
84                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
85                    }
86                }
87
88                Ok(ResourcePool {
89                    generation: value_generation.unwrap_or_default(),
90                    name: value_name.unwrap_or_default(),
91                    resource_slice_count: value_resource_slice_count.unwrap_or_default(),
92                })
93            }
94        }
95
96        deserializer.deserialize_struct(
97            "ResourcePool",
98            &[
99                "generation",
100                "name",
101                "resourceSliceCount",
102            ],
103            Visitor,
104        )
105    }
106}
107
108impl crate::serde::Serialize for ResourcePool {
109    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
110        let mut state = serializer.serialize_struct(
111            "ResourcePool",
112            3,
113        )?;
114        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "generation", &self.generation)?;
115        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
116        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resourceSliceCount", &self.resource_slice_count)?;
117        crate::serde::ser::SerializeStruct::end(state)
118    }
119}
120
121#[cfg(feature = "schemars")]
122impl crate::schemars::JsonSchema for ResourcePool {
123    fn schema_name() -> String {
124        "io.k8s.api.resource.v1alpha3.ResourcePool".to_owned()
125    }
126
127    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
128        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
129            metadata: Some(Box::new(crate::schemars::schema::Metadata {
130                description: Some("ResourcePool describes the pool that ResourceSlices belong to.".to_owned()),
131                ..Default::default()
132            })),
133            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
134            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
135                properties: [
136                    (
137                        "generation".to_owned(),
138                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
139                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
140                                description: Some("Generation tracks the change in a pool over time. Whenever a driver changes something about one or more of the resources in a pool, it must change the generation in all ResourceSlices which are part of that pool. Consumers of ResourceSlices should only consider resources from the pool with the highest generation number. The generation may be reset by drivers, which should be fine for consumers, assuming that all ResourceSlices in a pool are updated to match or deleted.\n\nCombined with ResourceSliceCount, this mechanism enables consumers to detect pools which are comprised of multiple ResourceSlices and are in an incomplete state.".to_owned()),
141                                ..Default::default()
142                            })),
143                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Integer))),
144                            format: Some("int64".to_owned()),
145                            ..Default::default()
146                        }),
147                    ),
148                    (
149                        "name".to_owned(),
150                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
151                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
152                                description: Some("Name is used to identify the pool. For node-local devices, this is often the node name, but this is not required.\n\nIt must not be longer than 253 characters and must consist of one or more DNS sub-domains separated by slashes. This field is immutable.".to_owned()),
153                                ..Default::default()
154                            })),
155                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
156                            ..Default::default()
157                        }),
158                    ),
159                    (
160                        "resourceSliceCount".to_owned(),
161                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
162                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
163                                description: Some("ResourceSliceCount is the total number of ResourceSlices in the pool at this generation number. Must be greater than zero.\n\nConsumers can use this to check whether they have seen all ResourceSlices belonging to the same pool.".to_owned()),
164                                ..Default::default()
165                            })),
166                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Integer))),
167                            format: Some("int64".to_owned()),
168                            ..Default::default()
169                        }),
170                    ),
171                ].into(),
172                required: [
173                    "generation".to_owned(),
174                    "name".to_owned(),
175                    "resourceSliceCount".to_owned(),
176                ].into(),
177                ..Default::default()
178            })),
179            ..Default::default()
180        })
181    }
182}