k8s_openapi/v1_32/api/resource/v1beta1/
resource_slice.rs1#[derive(Clone, Debug, Default, PartialEq)]
15pub struct ResourceSlice {
16 pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
18
19 pub spec: crate::api::resource::v1beta1::ResourceSliceSpec,
23}
24
25impl crate::Resource for ResourceSlice {
26 const API_VERSION: &'static str = "resource.k8s.io/v1beta1";
27 const GROUP: &'static str = "resource.k8s.io";
28 const KIND: &'static str = "ResourceSlice";
29 const VERSION: &'static str = "v1beta1";
30 const URL_PATH_SEGMENT: &'static str = "resourceslices";
31 type Scope = crate::ClusterResourceScope;
32}
33
34impl crate::ListableResource for ResourceSlice {
35 const LIST_KIND: &'static str = "ResourceSliceList";
36}
37
38impl crate::Metadata for ResourceSlice {
39 type Ty = crate::apimachinery::pkg::apis::meta::v1::ObjectMeta;
40
41 fn metadata(&self) -> &<Self as crate::Metadata>::Ty {
42 &self.metadata
43 }
44
45 fn metadata_mut(&mut self) -> &mut<Self as crate::Metadata>::Ty {
46 &mut self.metadata
47 }
48}
49
50impl crate::DeepMerge for ResourceSlice {
51 fn merge_from(&mut self, other: Self) {
52 crate::DeepMerge::merge_from(&mut self.metadata, other.metadata);
53 crate::DeepMerge::merge_from(&mut self.spec, other.spec);
54 }
55}
56
57impl<'de> crate::serde::Deserialize<'de> for ResourceSlice {
58 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
59 #[allow(non_camel_case_types)]
60 enum Field {
61 Key_api_version,
62 Key_kind,
63 Key_metadata,
64 Key_spec,
65 Other,
66 }
67
68 impl<'de> crate::serde::Deserialize<'de> for Field {
69 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
70 struct Visitor;
71
72 impl crate::serde::de::Visitor<'_> for Visitor {
73 type Value = Field;
74
75 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
76 f.write_str("field identifier")
77 }
78
79 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
80 Ok(match v {
81 "apiVersion" => Field::Key_api_version,
82 "kind" => Field::Key_kind,
83 "metadata" => Field::Key_metadata,
84 "spec" => Field::Key_spec,
85 _ => Field::Other,
86 })
87 }
88 }
89
90 deserializer.deserialize_identifier(Visitor)
91 }
92 }
93
94 struct Visitor;
95
96 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
97 type Value = ResourceSlice;
98
99 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
100 f.write_str(<Self::Value as crate::Resource>::KIND)
101 }
102
103 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
104 let mut value_metadata: Option<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
105 let mut value_spec: Option<crate::api::resource::v1beta1::ResourceSliceSpec> = None;
106
107 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
108 match key {
109 Field::Key_api_version => {
110 let value_api_version: String = crate::serde::de::MapAccess::next_value(&mut map)?;
111 if value_api_version != <Self::Value as crate::Resource>::API_VERSION {
112 return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_api_version), &<Self::Value as crate::Resource>::API_VERSION));
113 }
114 },
115 Field::Key_kind => {
116 let value_kind: String = crate::serde::de::MapAccess::next_value(&mut map)?;
117 if value_kind != <Self::Value as crate::Resource>::KIND {
118 return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_kind), &<Self::Value as crate::Resource>::KIND));
119 }
120 },
121 Field::Key_metadata => value_metadata = crate::serde::de::MapAccess::next_value(&mut map)?,
122 Field::Key_spec => value_spec = crate::serde::de::MapAccess::next_value(&mut map)?,
123 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
124 }
125 }
126
127 Ok(ResourceSlice {
128 metadata: value_metadata.unwrap_or_default(),
129 spec: value_spec.unwrap_or_default(),
130 })
131 }
132 }
133
134 deserializer.deserialize_struct(
135 <Self as crate::Resource>::KIND,
136 &[
137 "apiVersion",
138 "kind",
139 "metadata",
140 "spec",
141 ],
142 Visitor,
143 )
144 }
145}
146
147impl crate::serde::Serialize for ResourceSlice {
148 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
149 let mut state = serializer.serialize_struct(
150 <Self as crate::Resource>::KIND,
151 4,
152 )?;
153 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as crate::Resource>::API_VERSION)?;
154 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as crate::Resource>::KIND)?;
155 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
156 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "spec", &self.spec)?;
157 crate::serde::ser::SerializeStruct::end(state)
158 }
159}
160
161#[cfg(feature = "schemars")]
162impl crate::schemars::JsonSchema for ResourceSlice {
163 fn schema_name() -> String {
164 "io.k8s.api.resource.v1beta1.ResourceSlice".to_owned()
165 }
166
167 fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
168 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
169 metadata: Some(Box::new(crate::schemars::schema::Metadata {
170 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.\n\nThis is an alpha type and requires enabling the DynamicResourceAllocation feature gate.".to_owned()),
171 ..Default::default()
172 })),
173 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
174 object: Some(Box::new(crate::schemars::schema::ObjectValidation {
175 properties: [
176 (
177 "apiVersion".to_owned(),
178 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
179 metadata: Some(Box::new(crate::schemars::schema::Metadata {
180 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".to_owned()),
181 ..Default::default()
182 })),
183 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
184 ..Default::default()
185 }),
186 ),
187 (
188 "kind".to_owned(),
189 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
190 metadata: Some(Box::new(crate::schemars::schema::Metadata {
191 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".to_owned()),
192 ..Default::default()
193 })),
194 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
195 ..Default::default()
196 }),
197 ),
198 (
199 "metadata".to_owned(),
200 {
201 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>().into_object();
202 schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
203 description: Some("Standard object metadata".to_owned()),
204 ..Default::default()
205 }));
206 crate::schemars::schema::Schema::Object(schema_obj)
207 },
208 ),
209 (
210 "spec".to_owned(),
211 {
212 let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta1::ResourceSliceSpec>().into_object();
213 schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
214 description: Some("Contains the information published by the driver.\n\nChanging the spec automatically increments the metadata.generation number.".to_owned()),
215 ..Default::default()
216 }));
217 crate::schemars::schema::Schema::Object(schema_obj)
218 },
219 ),
220 ].into(),
221 required: [
222 "metadata".to_owned(),
223 "spec".to_owned(),
224 ].into(),
225 ..Default::default()
226 })),
227 ..Default::default()
228 })
229 }
230}