1// Generated from definition io.k8s.api.resource.v1beta2.ResourcePool
23/// 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.
9pub generation: i64,
1011/// 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.
14pub name: std::string::String,
1516/// 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.
19pub resource_slice_count: i64,
20}
2122impl crate::DeepMerge for ResourcePool {
23fn merge_from(&mut self, other: Self) {
24crate::DeepMerge::merge_from(&mut self.generation, other.generation);
25crate::DeepMerge::merge_from(&mut self.name, other.name);
26crate::DeepMerge::merge_from(&mut self.resource_slice_count, other.resource_slice_count);
27 }
28}
2930impl<'de> crate::serde::Deserialize<'de> for ResourcePool {
31fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
32#[allow(non_camel_case_types)]
33enum Field {
34 Key_generation,
35 Key_name,
36 Key_resource_slice_count,
37 Other,
38 }
3940impl<'de> crate::serde::Deserialize<'de> for Field {
41fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
42struct Visitor;
4344impl crate::serde::de::Visitor<'_> for Visitor {
45type Value = Field;
4647fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
48 f.write_str("field identifier")
49 }
5051fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
52Ok(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 }
6061 deserializer.deserialize_identifier(Visitor)
62 }
63 }
6465struct Visitor;
6667impl<'de> crate::serde::de::Visitor<'de> for Visitor {
68type Value = ResourcePool;
6970fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
71 f.write_str("ResourcePool")
72 }
7374fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
75let mut value_generation: Option<i64> = None;
76let mut value_name: Option<std::string::String> = None;
77let mut value_resource_slice_count: Option<i64> = None;
7879while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
80match 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 }
8788Ok(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 }
9596 deserializer.deserialize_struct(
97"ResourcePool",
98&[
99"generation",
100"name",
101"resourceSliceCount",
102 ],
103 Visitor,
104 )
105 }
106}
107108impl crate::serde::Serialize for ResourcePool {
109fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
110let mut state = serializer.serialize_struct(
111"ResourcePool",
1123,
113 )?;
114crate::serde::ser::SerializeStruct::serialize_field(&mut state, "generation", &self.generation)?;
115crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
116crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resourceSliceCount", &self.resource_slice_count)?;
117crate::serde::ser::SerializeStruct::end(state)
118 }
119}
120121#[cfg(feature = "schemars")]
122impl crate::schemars::JsonSchema for ResourcePool {
123fn schema_name() -> std::string::String {
124"io.k8s.api.resource.v1beta2.ResourcePool".into()
125 }
126127fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
128crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
129 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
130 description: Some("ResourcePool describes the pool that ResourceSlices belong to.".into()),
131 ..Default::default()
132 })),
133 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
134 object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
135 properties: [
136 (
137"generation".into(),
138crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
139 metadata: Some(std::boxed::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.".into()),
141 ..Default::default()
142 })),
143 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Integer))),
144 format: Some("int64".into()),
145 ..Default::default()
146 }),
147 ),
148 (
149"name".into(),
150crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
151 metadata: Some(std::boxed::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.".into()),
153 ..Default::default()
154 })),
155 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
156 ..Default::default()
157 }),
158 ),
159 (
160"resourceSliceCount".into(),
161crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
162 metadata: Some(std::boxed::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.".into()),
164 ..Default::default()
165 })),
166 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Integer))),
167 format: Some("int64".into()),
168 ..Default::default()
169 }),
170 ),
171 ].into(),
172 required: [
173"generation".into(),
174"name".into(),
175"resourceSliceCount".into(),
176 ].into(),
177 ..Default::default()
178 })),
179 ..Default::default()
180 })
181 }
182}