k8s_openapi/v1_30/api/storage/v1/
csi_storage_capacity.rs1#[derive(Clone, Debug, Default, PartialEq)]
13pub struct CSIStorageCapacity {
14 pub capacity: Option<crate::apimachinery::pkg::api::resource::Quantity>,
18
19 pub maximum_volume_size: Option<crate::apimachinery::pkg::api::resource::Quantity>,
23
24 pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
30
31 pub node_topology: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>,
33
34 pub storage_class_name: String,
36}
37
38impl crate::Resource for CSIStorageCapacity {
39 const API_VERSION: &'static str = "storage.k8s.io/v1";
40 const GROUP: &'static str = "storage.k8s.io";
41 const KIND: &'static str = "CSIStorageCapacity";
42 const VERSION: &'static str = "v1";
43 const URL_PATH_SEGMENT: &'static str = "csistoragecapacities";
44 type Scope = crate::NamespaceResourceScope;
45}
46
47impl crate::ListableResource for CSIStorageCapacity {
48 const LIST_KIND: &'static str = "CSIStorageCapacityList";
49}
50
51impl crate::Metadata for CSIStorageCapacity {
52 type Ty = crate::apimachinery::pkg::apis::meta::v1::ObjectMeta;
53
54 fn metadata(&self) -> &<Self as crate::Metadata>::Ty {
55 &self.metadata
56 }
57
58 fn metadata_mut(&mut self) -> &mut<Self as crate::Metadata>::Ty {
59 &mut self.metadata
60 }
61}
62
63impl crate::DeepMerge for CSIStorageCapacity {
64 fn merge_from(&mut self, other: Self) {
65 crate::DeepMerge::merge_from(&mut self.capacity, other.capacity);
66 crate::DeepMerge::merge_from(&mut self.maximum_volume_size, other.maximum_volume_size);
67 crate::DeepMerge::merge_from(&mut self.metadata, other.metadata);
68 crate::DeepMerge::merge_from(&mut self.node_topology, other.node_topology);
69 crate::DeepMerge::merge_from(&mut self.storage_class_name, other.storage_class_name);
70 }
71}
72
73impl<'de> crate::serde::Deserialize<'de> for CSIStorageCapacity {
74 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
75 #[allow(non_camel_case_types)]
76 enum Field {
77 Key_api_version,
78 Key_kind,
79 Key_capacity,
80 Key_maximum_volume_size,
81 Key_metadata,
82 Key_node_topology,
83 Key_storage_class_name,
84 Other,
85 }
86
87 impl<'de> crate::serde::Deserialize<'de> for Field {
88 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
89 struct Visitor;
90
91 impl crate::serde::de::Visitor<'_> for Visitor {
92 type Value = Field;
93
94 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
95 f.write_str("field identifier")
96 }
97
98 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
99 Ok(match v {
100 "apiVersion" => Field::Key_api_version,
101 "kind" => Field::Key_kind,
102 "capacity" => Field::Key_capacity,
103 "maximumVolumeSize" => Field::Key_maximum_volume_size,
104 "metadata" => Field::Key_metadata,
105 "nodeTopology" => Field::Key_node_topology,
106 "storageClassName" => Field::Key_storage_class_name,
107 _ => Field::Other,
108 })
109 }
110 }
111
112 deserializer.deserialize_identifier(Visitor)
113 }
114 }
115
116 struct Visitor;
117
118 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
119 type Value = CSIStorageCapacity;
120
121 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
122 f.write_str(<Self::Value as crate::Resource>::KIND)
123 }
124
125 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
126 let mut value_capacity: Option<crate::apimachinery::pkg::api::resource::Quantity> = None;
127 let mut value_maximum_volume_size: Option<crate::apimachinery::pkg::api::resource::Quantity> = None;
128 let mut value_metadata: Option<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
129 let mut value_node_topology: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector> = None;
130 let mut value_storage_class_name: Option<String> = None;
131
132 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
133 match key {
134 Field::Key_api_version => {
135 let value_api_version: String = crate::serde::de::MapAccess::next_value(&mut map)?;
136 if value_api_version != <Self::Value as crate::Resource>::API_VERSION {
137 return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_api_version), &<Self::Value as crate::Resource>::API_VERSION));
138 }
139 },
140 Field::Key_kind => {
141 let value_kind: String = crate::serde::de::MapAccess::next_value(&mut map)?;
142 if value_kind != <Self::Value as crate::Resource>::KIND {
143 return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_kind), &<Self::Value as crate::Resource>::KIND));
144 }
145 },
146 Field::Key_capacity => value_capacity = crate::serde::de::MapAccess::next_value(&mut map)?,
147 Field::Key_maximum_volume_size => value_maximum_volume_size = crate::serde::de::MapAccess::next_value(&mut map)?,
148 Field::Key_metadata => value_metadata = crate::serde::de::MapAccess::next_value(&mut map)?,
149 Field::Key_node_topology => value_node_topology = crate::serde::de::MapAccess::next_value(&mut map)?,
150 Field::Key_storage_class_name => value_storage_class_name = crate::serde::de::MapAccess::next_value(&mut map)?,
151 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
152 }
153 }
154
155 Ok(CSIStorageCapacity {
156 capacity: value_capacity,
157 maximum_volume_size: value_maximum_volume_size,
158 metadata: value_metadata.unwrap_or_default(),
159 node_topology: value_node_topology,
160 storage_class_name: value_storage_class_name.unwrap_or_default(),
161 })
162 }
163 }
164
165 deserializer.deserialize_struct(
166 <Self as crate::Resource>::KIND,
167 &[
168 "apiVersion",
169 "kind",
170 "capacity",
171 "maximumVolumeSize",
172 "metadata",
173 "nodeTopology",
174 "storageClassName",
175 ],
176 Visitor,
177 )
178 }
179}
180
181impl crate::serde::Serialize for CSIStorageCapacity {
182 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
183 let mut state = serializer.serialize_struct(
184 <Self as crate::Resource>::KIND,
185 4 +
186 self.capacity.as_ref().map_or(0, |_| 1) +
187 self.maximum_volume_size.as_ref().map_or(0, |_| 1) +
188 self.node_topology.as_ref().map_or(0, |_| 1),
189 )?;
190 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as crate::Resource>::API_VERSION)?;
191 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as crate::Resource>::KIND)?;
192 if let Some(value) = &self.capacity {
193 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "capacity", value)?;
194 }
195 if let Some(value) = &self.maximum_volume_size {
196 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "maximumVolumeSize", value)?;
197 }
198 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
199 if let Some(value) = &self.node_topology {
200 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nodeTopology", value)?;
201 }
202 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "storageClassName", &self.storage_class_name)?;
203 crate::serde::ser::SerializeStruct::end(state)
204 }
205}
206
207#[cfg(feature = "schemars")]
208impl crate::schemars::JsonSchema for CSIStorageCapacity {
209 fn schema_name() -> String {
210 "io.k8s.api.storage.v1.CSIStorageCapacity".to_owned()
211 }
212
213 fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
214 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
215 metadata: Some(Box::new(crate::schemars::schema::Metadata {
216 description: Some("CSIStorageCapacity stores the result of one CSI GetCapacity call. For a given StorageClass, this describes the available capacity in a particular topology segment. This can be used when considering where to instantiate new PersistentVolumes.\n\nFor example this can express things like: - StorageClass \"standard\" has \"1234 GiB\" available in \"topology.kubernetes.io/zone=us-east1\" - StorageClass \"localssd\" has \"10 GiB\" available in \"kubernetes.io/hostname=knode-abc123\"\n\nThe following three cases all imply that no capacity is available for a certain combination: - no object exists with suitable topology and storage class name - such an object exists, but the capacity is unset - such an object exists, but the capacity is zero\n\nThe producer of these objects can decide which approach is more suitable.\n\nThey are consumed by the kube-scheduler when a CSI driver opts into capacity-aware scheduling with CSIDriverSpec.StorageCapacity. The scheduler compares the MaximumVolumeSize against the requested size of pending volumes to filter out unsuitable nodes. If MaximumVolumeSize is unset, it falls back to a comparison against the less precise Capacity. If that is also unset, the scheduler assumes that capacity is insufficient and tries some other node.".to_owned()),
217 ..Default::default()
218 })),
219 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
220 object: Some(Box::new(crate::schemars::schema::ObjectValidation {
221 properties: [
222 (
223 "apiVersion".to_owned(),
224 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
225 metadata: Some(Box::new(crate::schemars::schema::Metadata {
226 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()),
227 ..Default::default()
228 })),
229 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
230 ..Default::default()
231 }),
232 ),
233 (
234 "capacity".to_owned(),
235 {
236 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>().into_object();
237 schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
238 description: Some("capacity is the value reported by the CSI driver in its GetCapacityResponse for a GetCapacityRequest with topology and parameters that match the previous fields.\n\nThe semantic is currently (CSI spec 1.2) defined as: The available capacity, in bytes, of the storage that can be used to provision volumes. If not set, that information is currently unavailable.".to_owned()),
239 ..Default::default()
240 }));
241 crate::schemars::schema::Schema::Object(schema_obj)
242 },
243 ),
244 (
245 "kind".to_owned(),
246 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
247 metadata: Some(Box::new(crate::schemars::schema::Metadata {
248 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()),
249 ..Default::default()
250 })),
251 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
252 ..Default::default()
253 }),
254 ),
255 (
256 "maximumVolumeSize".to_owned(),
257 {
258 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>().into_object();
259 schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
260 description: Some("maximumVolumeSize is the value reported by the CSI driver in its GetCapacityResponse for a GetCapacityRequest with topology and parameters that match the previous fields.\n\nThis is defined since CSI spec 1.4.0 as the largest size that may be used in a CreateVolumeRequest.capacity_range.required_bytes field to create a volume with the same parameters as those in GetCapacityRequest. The corresponding value in the Kubernetes API is ResourceRequirements.Requests in a volume claim.".to_owned()),
261 ..Default::default()
262 }));
263 crate::schemars::schema::Schema::Object(schema_obj)
264 },
265 ),
266 (
267 "metadata".to_owned(),
268 {
269 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>().into_object();
270 schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
271 description: Some("Standard object's metadata. The name has no particular meaning. It must be a DNS subdomain (dots allowed, 253 characters). To ensure that there are no conflicts with other CSI drivers on the cluster, the recommendation is to use csisc-<uuid>, a generated name, or a reverse-domain name which ends with the unique CSI driver name.\n\nObjects are namespaced.\n\nMore info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata".to_owned()),
272 ..Default::default()
273 }));
274 crate::schemars::schema::Schema::Object(schema_obj)
275 },
276 ),
277 (
278 "nodeTopology".to_owned(),
279 {
280 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>().into_object();
281 schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
282 description: Some("nodeTopology defines which nodes have access to the storage for which capacity was reported. If not set, the storage is not accessible from any node in the cluster. If empty, the storage is accessible from all nodes. This field is immutable.".to_owned()),
283 ..Default::default()
284 }));
285 crate::schemars::schema::Schema::Object(schema_obj)
286 },
287 ),
288 (
289 "storageClassName".to_owned(),
290 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
291 metadata: Some(Box::new(crate::schemars::schema::Metadata {
292 description: Some("storageClassName represents the name of the StorageClass that the reported capacity applies to. It must meet the same requirements as the name of a StorageClass object (non-empty, DNS subdomain). If that object no longer exists, the CSIStorageCapacity object is obsolete and should be removed by its creator. This field is immutable.".to_owned()),
293 ..Default::default()
294 })),
295 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
296 ..Default::default()
297 }),
298 ),
299 ].into(),
300 required: [
301 "metadata".to_owned(),
302 "storageClassName".to_owned(),
303 ].into(),
304 ..Default::default()
305 })),
306 ..Default::default()
307 })
308 }
309}