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

    1// Generated from definition io.k8s.api.storage.v1.VolumeAttachment
    2
    3/// VolumeAttachment captures the intent to attach or detach the specified volume to/from the specified node.
    4///
    5/// VolumeAttachment objects are non-namespaced.
    6#[derive(Clone, Debug, Default, PartialEq)]
    7pub struct VolumeAttachment {
    8    /// Standard object metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
    9    pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
    10
    11    /// spec represents specification of the desired attach/detach volume behavior. Populated by the Kubernetes system.
    12    pub spec: crate::api::storage::v1::VolumeAttachmentSpec,
    13
    14    /// status represents status of the VolumeAttachment request. Populated by the entity completing the attach or detach operation, i.e. the external-attacher.
    15    pub status: Option<crate::api::storage::v1::VolumeAttachmentStatus>,
    16}
    17
    18impl crate::Resource for VolumeAttachment {
    19    const API_VERSION: &'static str = "storage.k8s.io/v1";
    20    const GROUP: &'static str = "storage.k8s.io";
    21    const KIND: &'static str = "VolumeAttachment";
    22    const VERSION: &'static str = "v1";
    23    const URL_PATH_SEGMENT: &'static str = "volumeattachments";
    24    type Scope = crate::ClusterResourceScope;
    25}
    26
    27impl crate::ListableResource for VolumeAttachment {
    28    const LIST_KIND: &'static str = "VolumeAttachmentList";
    29}
    30
    31impl crate::Metadata for VolumeAttachment {
    32    type Ty = crate::apimachinery::pkg::apis::meta::v1::ObjectMeta;
    33
    34    fn metadata(&self) -> &<Self as crate::Metadata>::Ty {
    35        &self.metadata
    36    }
    37
    38    fn metadata_mut(&mut self) -> &mut<Self as crate::Metadata>::Ty {
    39        &mut self.metadata
    40    }
    41}
    42
    43impl crate::DeepMerge for VolumeAttachment {
    44    fn merge_from(&mut self, other: Self) {
    45        crate::DeepMerge::merge_from(&mut self.metadata, other.metadata);
    46        crate::DeepMerge::merge_from(&mut self.spec, other.spec);
    47        crate::DeepMerge::merge_from(&mut self.status, other.status);
    48    }
    49}
    50
    51impl<'de> crate::serde::Deserialize<'de> for VolumeAttachment {
    52    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    53        #[allow(non_camel_case_types)]
    54        enum Field {
    55            Key_api_version,
    56            Key_kind,
    57            Key_metadata,
    58            Key_spec,
    59            Key_status,
    60            Other,
    61        }
    62
    63        impl<'de> crate::serde::Deserialize<'de> for Field {
    64            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    65                struct Visitor;
    66
    67                impl crate::serde::de::Visitor<'_> for Visitor {
    68                    type Value = Field;
    69
    70                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    71                        f.write_str("field identifier")
    72                    }
    73
    74                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    75                        Ok(match v {
    76                            "apiVersion" => Field::Key_api_version,
    77                            "kind" => Field::Key_kind,
    78                            "metadata" => Field::Key_metadata,
    79                            "spec" => Field::Key_spec,
    80                            "status" => Field::Key_status,
    81                            _ => Field::Other,
    82                        })
    83                    }
    84                }
    85
    86                deserializer.deserialize_identifier(Visitor)
    87            }
    88        }
    89
    90        struct Visitor;
    91
    92        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    93            type Value = VolumeAttachment;
    94
    95            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    96                f.write_str(<Self::Value as crate::Resource>::KIND)
    97            }
    98
    99            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    100                let mut value_metadata: Option<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
    101                let mut value_spec: Option<crate::api::storage::v1::VolumeAttachmentSpec> = None;
    102                let mut value_status: Option<crate::api::storage::v1::VolumeAttachmentStatus> = None;
    103
    104                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    105                    match key {
    106                        Field::Key_api_version => {
    107                            let value_api_version: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    108                            if value_api_version != <Self::Value as crate::Resource>::API_VERSION {
    109                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_api_version), &<Self::Value as crate::Resource>::API_VERSION));
    110                            }
    111                        },
    112                        Field::Key_kind => {
    113                            let value_kind: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    114                            if value_kind != <Self::Value as crate::Resource>::KIND {
    115                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_kind), &<Self::Value as crate::Resource>::KIND));
    116                            }
    117                        },
    118                        Field::Key_metadata => value_metadata = crate::serde::de::MapAccess::next_value(&mut map)?,
    119                        Field::Key_spec => value_spec = crate::serde::de::MapAccess::next_value(&mut map)?,
    120                        Field::Key_status => value_status = 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(VolumeAttachment {
    126                    metadata: value_metadata.unwrap_or_default(),
    127                    spec: value_spec.unwrap_or_default(),
    128                    status: value_status,
    129                })
    130            }
    131        }
    132
    133        deserializer.deserialize_struct(
    134            <Self as crate::Resource>::KIND,
    135            &[
    136                "apiVersion",
    137                "kind",
    138                "metadata",
    139                "spec",
    140                "status",
    141            ],
    142            Visitor,
    143        )
    144    }
    145}
    146
    147impl crate::serde::Serialize for VolumeAttachment {
    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            self.status.as_ref().map_or(0, |_| 1),
    153        )?;
    154        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as crate::Resource>::API_VERSION)?;
    155        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as crate::Resource>::KIND)?;
    156        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
    157        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "spec", &self.spec)?;
    158        if let Some(value) = &self.status {
    159            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "status", value)?;
    160        }
    161        crate::serde::ser::SerializeStruct::end(state)
    162    }
    163}
    164
    165#[cfg(feature = "schemars")]
    166impl crate::schemars::JsonSchema for VolumeAttachment {
    167    fn schema_name() -> std::borrow::Cow<'static, str> {
    168        "io.k8s.api.storage.v1.VolumeAttachment".into()
    169    }
    170
    171    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    172        crate::schemars::json_schema!({
    173            "description": "VolumeAttachment captures the intent to attach or detach the specified volume to/from the specified node.\n\nVolumeAttachment objects are non-namespaced.",
    174            "type": "object",
    175            "properties": {
    176                "apiVersion": {
    177                    "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",
    178                    "type": "string",
    179                },
    180                "kind": {
    181                    "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",
    182                    "type": "string",
    183                },
    184                "metadata": ({
    185                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>();
    186                    schema_obj.ensure_object().insert("description".into(), "Standard object metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata".into());
    187                    schema_obj
    188                }),
    189                "spec": ({
    190                    let mut schema_obj = __gen.subschema_for::<crate::api::storage::v1::VolumeAttachmentSpec>();
    191                    schema_obj.ensure_object().insert("description".into(), "spec represents specification of the desired attach/detach volume behavior. Populated by the Kubernetes system.".into());
    192                    schema_obj
    193                }),
    194                "status": ({
    195                    let mut schema_obj = __gen.subschema_for::<crate::api::storage::v1::VolumeAttachmentStatus>();
    196                    schema_obj.ensure_object().insert("description".into(), "status represents status of the VolumeAttachment request. Populated by the entity completing the attach or detach operation, i.e. the external-attacher.".into());
    197                    schema_obj
    198                }),
    199            },
    200            "required": [
    201                "metadata",
    202                "spec",
    203            ],
    204        })
    205    }
    206}