#
k8s_openapi/v1_35/api/storage/v1/
csi_storage_capacity.rs

    1// Generated from definition io.k8s.api.storage.v1.CSIStorageCapacity
    2
    3/// 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.
    4///
    5/// For 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"
    6///
    7/// The 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
    8///
    9/// The producer of these objects can decide which approach is more suitable.
    10///
    11/// They 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.
    12#[derive(Clone, Debug, Default, PartialEq)]
    13pub struct CSIStorageCapacity {
    14    /// capacity is the value reported by the CSI driver in its GetCapacityResponse for a GetCapacityRequest with topology and parameters that match the previous fields.
    15    ///
    16    /// The 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.
    17    pub capacity: Option<crate::apimachinery::pkg::api::resource::Quantity>,
    18
    19    /// maximumVolumeSize is the value reported by the CSI driver in its GetCapacityResponse for a GetCapacityRequest with topology and parameters that match the previous fields.
    20    ///
    21    /// This 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.
    22    pub maximum_volume_size: Option<crate::apimachinery::pkg::api::resource::Quantity>,
    23
    24    /// 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.
    25    ///
    26    /// Objects are namespaced.
    27    ///
    28    /// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
    29    pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
    30
    31    /// 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.
    32    pub node_topology: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>,
    33
    34    /// 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.
    35    pub storage_class_name: std::string::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 core::fmt::Formatter<'_>) -> core::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 core::fmt::Formatter<'_>) -> core::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<std::string::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: std::string::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: std::string::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() -> std::borrow::Cow<'static, str> {
    210        "io.k8s.api.storage.v1.CSIStorageCapacity".into()
    211    }
    212
    213    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    214        crate::schemars::json_schema!({
    215            "description": "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.",
    216            "type": "object",
    217            "properties": {
    218                "apiVersion": {
    219                    "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",
    220                    "type": "string",
    221                },
    222                "capacity": ({
    223                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>();
    224                    schema_obj.ensure_object().insert("description".into(), "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.".into());
    225                    schema_obj
    226                }),
    227                "kind": {
    228                    "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",
    229                    "type": "string",
    230                },
    231                "maximumVolumeSize": ({
    232                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>();
    233                    schema_obj.ensure_object().insert("description".into(), "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.".into());
    234                    schema_obj
    235                }),
    236                "metadata": ({
    237                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>();
    238                    schema_obj.ensure_object().insert("description".into(), "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".into());
    239                    schema_obj
    240                }),
    241                "nodeTopology": ({
    242                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>();
    243                    schema_obj.ensure_object().insert("description".into(), "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.".into());
    244                    schema_obj
    245                }),
    246                "storageClassName": {
    247                    "description": "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.",
    248                    "type": "string",
    249                },
    250            },
    251            "required": [
    252                "metadata",
    253                "storageClassName",
    254            ],
    255        })
    256    }
    257}