k8s_openapi/v1_36/api/resource/v1/
resource_slice.rs1#[derive(Clone, Debug, Default, PartialEq)]
13pub struct ResourceSlice {
14 pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
16
17 pub spec: crate::api::resource::v1::ResourceSliceSpec,
21}
22
23impl crate::Resource for ResourceSlice {
24 const API_VERSION: &'static str = "resource.k8s.io/v1";
25 const GROUP: &'static str = "resource.k8s.io";
26 const KIND: &'static str = "ResourceSlice";
27 const VERSION: &'static str = "v1";
28 const URL_PATH_SEGMENT: &'static str = "resourceslices";
29 type Scope = crate::ClusterResourceScope;
30}
31
32impl crate::ListableResource for ResourceSlice {
33 const LIST_KIND: &'static str = "ResourceSliceList";
34}
35
36impl crate::Metadata for ResourceSlice {
37 type Ty = crate::apimachinery::pkg::apis::meta::v1::ObjectMeta;
38
39 fn metadata(&self) -> &<Self as crate::Metadata>::Ty {
40 &self.metadata
41 }
42
43 fn metadata_mut(&mut self) -> &mut<Self as crate::Metadata>::Ty {
44 &mut self.metadata
45 }
46}
47
48impl crate::DeepMerge for ResourceSlice {
49 fn merge_from(&mut self, other: Self) {
50 crate::DeepMerge::merge_from(&mut self.metadata, other.metadata);
51 crate::DeepMerge::merge_from(&mut self.spec, other.spec);
52 }
53}
54
55impl<'de> crate::serde::Deserialize<'de> for ResourceSlice {
56 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
57 #[allow(non_camel_case_types)]
58 enum Field {
59 Key_api_version,
60 Key_kind,
61 Key_metadata,
62 Key_spec,
63 Other,
64 }
65
66 impl<'de> crate::serde::Deserialize<'de> for Field {
67 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
68 struct Visitor;
69
70 impl crate::serde::de::Visitor<'_> for Visitor {
71 type Value = Field;
72
73 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
74 f.write_str("field identifier")
75 }
76
77 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
78 Ok(match v {
79 "apiVersion" => Field::Key_api_version,
80 "kind" => Field::Key_kind,
81 "metadata" => Field::Key_metadata,
82 "spec" => Field::Key_spec,
83 _ => Field::Other,
84 })
85 }
86 }
87
88 deserializer.deserialize_identifier(Visitor)
89 }
90 }
91
92 struct Visitor;
93
94 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
95 type Value = ResourceSlice;
96
97 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
98 f.write_str(<Self::Value as crate::Resource>::KIND)
99 }
100
101 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
102 let mut value_metadata: Option<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
103 let mut value_spec: Option<crate::api::resource::v1::ResourceSliceSpec> = None;
104
105 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
106 match key {
107 Field::Key_api_version => {
108 let value_api_version: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
109 if value_api_version != <Self::Value as crate::Resource>::API_VERSION {
110 return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_api_version), &<Self::Value as crate::Resource>::API_VERSION));
111 }
112 },
113 Field::Key_kind => {
114 let value_kind: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
115 if value_kind != <Self::Value as crate::Resource>::KIND {
116 return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_kind), &<Self::Value as crate::Resource>::KIND));
117 }
118 },
119 Field::Key_metadata => value_metadata = crate::serde::de::MapAccess::next_value(&mut map)?,
120 Field::Key_spec => value_spec = crate::serde::de::MapAccess::next_value(&mut map)?,
121 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
122 }
123 }
124
125 Ok(ResourceSlice {
126 metadata: value_metadata.unwrap_or_default(),
127 spec: value_spec.unwrap_or_default(),
128 })
129 }
130 }
131
132 deserializer.deserialize_struct(
133 <Self as crate::Resource>::KIND,
134 &[
135 "apiVersion",
136 "kind",
137 "metadata",
138 "spec",
139 ],
140 Visitor,
141 )
142 }
143}
144
145impl crate::serde::Serialize for ResourceSlice {
146 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
147 let mut state = serializer.serialize_struct(
148 <Self as crate::Resource>::KIND,
149 4,
150 )?;
151 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as crate::Resource>::API_VERSION)?;
152 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as crate::Resource>::KIND)?;
153 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
154 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "spec", &self.spec)?;
155 crate::serde::ser::SerializeStruct::end(state)
156 }
157}
158
159#[cfg(feature = "schemars")]
160impl crate::schemars::JsonSchema for ResourceSlice {
161 fn schema_name() -> std::borrow::Cow<'static, str> {
162 "io.k8s.api.resource.v1.ResourceSlice".into()
163 }
164
165 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
166 crate::schemars::json_schema!({
167 "description": "ResourceSlice represents one or more resources in a pool of similar resources, managed by a common driver. A pool may span more than one ResourceSlice, and exactly how many ResourceSlices comprise a pool is determined by the driver.\n\nAt the moment, the only supported resources are devices with attributes and capacities. Each device in a given pool, regardless of how many ResourceSlices, must have a unique name. The ResourceSlice in which a device gets published may change over time. The unique identifier for a device is the tuple <driver name>, <pool name>, <device name>.\n\nWhenever a driver needs to update a pool, it increments the pool.Spec.Pool.Generation number and updates all ResourceSlices with that new number and new resource definitions. A consumer must only use ResourceSlices with the highest generation number and ignore all others.\n\nWhen allocating all resources in a pool matching certain criteria or when looking for the best solution among several different alternatives, a consumer should check the number of ResourceSlices in a pool (included in each ResourceSlice) to determine whether its view of a pool is complete and if not, should wait until the driver has completed updating the pool.\n\nFor resources that are not local to a node, the node name is not set. Instead, the driver may use a node selector to specify where the devices are available.",
168 "type": "object",
169 "properties": {
170 "apiVersion": {
171 "description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
172 "type": "string",
173 },
174 "kind": {
175 "description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
176 "type": "string",
177 },
178 "metadata": ({
179 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>();
180 schema_obj.ensure_object().insert("description".into(), "Standard object metadata".into());
181 schema_obj
182 }),
183 "spec": ({
184 let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1::ResourceSliceSpec>();
185 schema_obj.ensure_object().insert("description".into(), "Contains the information published by the driver.\n\nChanging the spec automatically increments the metadata.generation number.".into());
186 schema_obj
187 }),
188 },
189 "required": [
190 "metadata",
191 "spec",
192 ],
193 })
194 }
195}
196
197#[cfg(feature = "schemars08")]
198impl crate::schemars08::JsonSchema for ResourceSlice {
199 fn schema_name() -> std::string::String {
200 "io.k8s.api.resource.v1.ResourceSlice".into()
201 }
202
203 fn json_schema(__gen: &mut crate::schemars08::gen::SchemaGenerator) -> crate::schemars08::schema::Schema {
204 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
205 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
206 description: Some("ResourceSlice represents one or more resources in a pool of similar resources, managed by a common driver. A pool may span more than one ResourceSlice, and exactly how many ResourceSlices comprise a pool is determined by the driver.\n\nAt the moment, the only supported resources are devices with attributes and capacities. Each device in a given pool, regardless of how many ResourceSlices, must have a unique name. The ResourceSlice in which a device gets published may change over time. The unique identifier for a device is the tuple <driver name>, <pool name>, <device name>.\n\nWhenever a driver needs to update a pool, it increments the pool.Spec.Pool.Generation number and updates all ResourceSlices with that new number and new resource definitions. A consumer must only use ResourceSlices with the highest generation number and ignore all others.\n\nWhen allocating all resources in a pool matching certain criteria or when looking for the best solution among several different alternatives, a consumer should check the number of ResourceSlices in a pool (included in each ResourceSlice) to determine whether its view of a pool is complete and if not, should wait until the driver has completed updating the pool.\n\nFor resources that are not local to a node, the node name is not set. Instead, the driver may use a node selector to specify where the devices are available.".into()),
207 ..Default::default()
208 })),
209 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Object))),
210 object: Some(std::boxed::Box::new(crate::schemars08::schema::ObjectValidation {
211 properties: [
212 (
213 "apiVersion".into(),
214 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
215 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
216 description: Some("APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources".into()),
217 ..Default::default()
218 })),
219 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
220 ..Default::default()
221 }),
222 ),
223 (
224 "kind".into(),
225 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
226 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
227 description: Some("Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds".into()),
228 ..Default::default()
229 })),
230 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
231 ..Default::default()
232 }),
233 ),
234 (
235 "metadata".into(),
236 {
237 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>().into_object();
238 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
239 description: Some("Standard object metadata".into()),
240 ..Default::default()
241 }));
242 crate::schemars08::schema::Schema::Object(schema_obj)
243 },
244 ),
245 (
246 "spec".into(),
247 {
248 let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1::ResourceSliceSpec>().into_object();
249 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
250 description: Some("Contains the information published by the driver.\n\nChanging the spec automatically increments the metadata.generation number.".into()),
251 ..Default::default()
252 }));
253 crate::schemars08::schema::Schema::Object(schema_obj)
254 },
255 ),
256 ].into(),
257 required: [
258 "metadata".into(),
259 "spec".into(),
260 ].into(),
261 ..Default::default()
262 })),
263 ..Default::default()
264 })
265 }
266}