#
k8s_openapi/v1_35/api/core/v1/
volume_mount.rs

    1// Generated from definition io.k8s.api.core.v1.VolumeMount
    2
    3/// VolumeMount describes a mounting of a Volume within a container.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct VolumeMount {
    6    /// Path within the container at which the volume should be mounted.  Must not contain ':'.
    7    pub mount_path: std::string::String,
    8
    9    /// mountPropagation determines how mounts are propagated from the host to container and the other way around. When not set, MountPropagationNone is used. This field is beta in 1.10. When RecursiveReadOnly is set to IfPossible or to Enabled, MountPropagation must be None or unspecified (which defaults to None).
    10    pub mount_propagation: Option<std::string::String>,
    11
    12    /// This must match the Name of a Volume.
    13    pub name: std::string::String,
    14
    15    /// Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false.
    16    pub read_only: Option<bool>,
    17
    18    /// RecursiveReadOnly specifies whether read-only mounts should be handled recursively.
    19    ///
    20    /// If ReadOnly is false, this field has no meaning and must be unspecified.
    21    ///
    22    /// If ReadOnly is true, and this field is set to Disabled, the mount is not made recursively read-only.  If this field is set to IfPossible, the mount is made recursively read-only, if it is supported by the container runtime.  If this field is set to Enabled, the mount is made recursively read-only if it is supported by the container runtime, otherwise the pod will not be started and an error will be generated to indicate the reason.
    23    ///
    24    /// If this field is set to IfPossible or Enabled, MountPropagation must be set to None (or be unspecified, which defaults to None).
    25    ///
    26    /// If this field is not specified, it is treated as an equivalent of Disabled.
    27    pub recursive_read_only: Option<std::string::String>,
    28
    29    /// Path within the volume from which the container's volume should be mounted. Defaults to "" (volume's root).
    30    pub sub_path: Option<std::string::String>,
    31
    32    /// Expanded path within the volume from which the container's volume should be mounted. Behaves similarly to SubPath but environment variable references $(VAR_NAME) are expanded using the container's environment. Defaults to "" (volume's root). SubPathExpr and SubPath are mutually exclusive.
    33    pub sub_path_expr: Option<std::string::String>,
    34}
    35
    36impl crate::DeepMerge for VolumeMount {
    37    fn merge_from(&mut self, other: Self) {
    38        crate::DeepMerge::merge_from(&mut self.mount_path, other.mount_path);
    39        crate::DeepMerge::merge_from(&mut self.mount_propagation, other.mount_propagation);
    40        crate::DeepMerge::merge_from(&mut self.name, other.name);
    41        crate::DeepMerge::merge_from(&mut self.read_only, other.read_only);
    42        crate::DeepMerge::merge_from(&mut self.recursive_read_only, other.recursive_read_only);
    43        crate::DeepMerge::merge_from(&mut self.sub_path, other.sub_path);
    44        crate::DeepMerge::merge_from(&mut self.sub_path_expr, other.sub_path_expr);
    45    }
    46}
    47
    48impl<'de> crate::serde::Deserialize<'de> for VolumeMount {
    49    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    50        #[allow(non_camel_case_types)]
    51        enum Field {
    52            Key_mount_path,
    53            Key_mount_propagation,
    54            Key_name,
    55            Key_read_only,
    56            Key_recursive_read_only,
    57            Key_sub_path,
    58            Key_sub_path_expr,
    59            Other,
    60        }
    61
    62        impl<'de> crate::serde::Deserialize<'de> for Field {
    63            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    64                struct Visitor;
    65
    66                impl crate::serde::de::Visitor<'_> for Visitor {
    67                    type Value = Field;
    68
    69                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    70                        f.write_str("field identifier")
    71                    }
    72
    73                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    74                        Ok(match v {
    75                            "mountPath" => Field::Key_mount_path,
    76                            "mountPropagation" => Field::Key_mount_propagation,
    77                            "name" => Field::Key_name,
    78                            "readOnly" => Field::Key_read_only,
    79                            "recursiveReadOnly" => Field::Key_recursive_read_only,
    80                            "subPath" => Field::Key_sub_path,
    81                            "subPathExpr" => Field::Key_sub_path_expr,
    82                            _ => Field::Other,
    83                        })
    84                    }
    85                }
    86
    87                deserializer.deserialize_identifier(Visitor)
    88            }
    89        }
    90
    91        struct Visitor;
    92
    93        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    94            type Value = VolumeMount;
    95
    96            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    97                f.write_str("VolumeMount")
    98            }
    99
    100            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    101                let mut value_mount_path: Option<std::string::String> = None;
    102                let mut value_mount_propagation: Option<std::string::String> = None;
    103                let mut value_name: Option<std::string::String> = None;
    104                let mut value_read_only: Option<bool> = None;
    105                let mut value_recursive_read_only: Option<std::string::String> = None;
    106                let mut value_sub_path: Option<std::string::String> = None;
    107                let mut value_sub_path_expr: Option<std::string::String> = None;
    108
    109                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    110                    match key {
    111                        Field::Key_mount_path => value_mount_path = crate::serde::de::MapAccess::next_value(&mut map)?,
    112                        Field::Key_mount_propagation => value_mount_propagation = crate::serde::de::MapAccess::next_value(&mut map)?,
    113                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
    114                        Field::Key_read_only => value_read_only = crate::serde::de::MapAccess::next_value(&mut map)?,
    115                        Field::Key_recursive_read_only => value_recursive_read_only = crate::serde::de::MapAccess::next_value(&mut map)?,
    116                        Field::Key_sub_path => value_sub_path = crate::serde::de::MapAccess::next_value(&mut map)?,
    117                        Field::Key_sub_path_expr => value_sub_path_expr = crate::serde::de::MapAccess::next_value(&mut map)?,
    118                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    119                    }
    120                }
    121
    122                Ok(VolumeMount {
    123                    mount_path: value_mount_path.unwrap_or_default(),
    124                    mount_propagation: value_mount_propagation,
    125                    name: value_name.unwrap_or_default(),
    126                    read_only: value_read_only,
    127                    recursive_read_only: value_recursive_read_only,
    128                    sub_path: value_sub_path,
    129                    sub_path_expr: value_sub_path_expr,
    130                })
    131            }
    132        }
    133
    134        deserializer.deserialize_struct(
    135            "VolumeMount",
    136            &[
    137                "mountPath",
    138                "mountPropagation",
    139                "name",
    140                "readOnly",
    141                "recursiveReadOnly",
    142                "subPath",
    143                "subPathExpr",
    144            ],
    145            Visitor,
    146        )
    147    }
    148}
    149
    150impl crate::serde::Serialize for VolumeMount {
    151    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    152        let mut state = serializer.serialize_struct(
    153            "VolumeMount",
    154            2 +
    155            self.mount_propagation.as_ref().map_or(0, |_| 1) +
    156            self.read_only.as_ref().map_or(0, |_| 1) +
    157            self.recursive_read_only.as_ref().map_or(0, |_| 1) +
    158            self.sub_path.as_ref().map_or(0, |_| 1) +
    159            self.sub_path_expr.as_ref().map_or(0, |_| 1),
    160        )?;
    161        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "mountPath", &self.mount_path)?;
    162        if let Some(value) = &self.mount_propagation {
    163            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "mountPropagation", value)?;
    164        }
    165        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
    166        if let Some(value) = &self.read_only {
    167            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "readOnly", value)?;
    168        }
    169        if let Some(value) = &self.recursive_read_only {
    170            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "recursiveReadOnly", value)?;
    171        }
    172        if let Some(value) = &self.sub_path {
    173            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "subPath", value)?;
    174        }
    175        if let Some(value) = &self.sub_path_expr {
    176            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "subPathExpr", value)?;
    177        }
    178        crate::serde::ser::SerializeStruct::end(state)
    179    }
    180}
    181
    182#[cfg(feature = "schemars")]
    183impl crate::schemars::JsonSchema for VolumeMount {
    184    fn schema_name() -> std::borrow::Cow<'static, str> {
    185        "io.k8s.api.core.v1.VolumeMount".into()
    186    }
    187
    188    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    189        crate::schemars::json_schema!({
    190            "description": "VolumeMount describes a mounting of a Volume within a container.",
    191            "type": "object",
    192            "properties": {
    193                "mountPath": {
    194                    "description": "Path within the container at which the volume should be mounted.  Must not contain ':'.",
    195                    "type": "string",
    196                },
    197                "mountPropagation": {
    198                    "description": "mountPropagation determines how mounts are propagated from the host to container and the other way around. When not set, MountPropagationNone is used. This field is beta in 1.10. When RecursiveReadOnly is set to IfPossible or to Enabled, MountPropagation must be None or unspecified (which defaults to None).",
    199                    "type": "string",
    200                },
    201                "name": {
    202                    "description": "This must match the Name of a Volume.",
    203                    "type": "string",
    204                },
    205                "readOnly": {
    206                    "description": "Mounted read-only if true, read-write otherwise (false or unspecified). Defaults to false.",
    207                    "type": "boolean",
    208                },
    209                "recursiveReadOnly": {
    210                    "description": "RecursiveReadOnly specifies whether read-only mounts should be handled recursively.\n\nIf ReadOnly is false, this field has no meaning and must be unspecified.\n\nIf ReadOnly is true, and this field is set to Disabled, the mount is not made recursively read-only.  If this field is set to IfPossible, the mount is made recursively read-only, if it is supported by the container runtime.  If this field is set to Enabled, the mount is made recursively read-only if it is supported by the container runtime, otherwise the pod will not be started and an error will be generated to indicate the reason.\n\nIf this field is set to IfPossible or Enabled, MountPropagation must be set to None (or be unspecified, which defaults to None).\n\nIf this field is not specified, it is treated as an equivalent of Disabled.",
    211                    "type": "string",
    212                },
    213                "subPath": {
    214                    "description": "Path within the volume from which the container's volume should be mounted. Defaults to \"\" (volume's root).",
    215                    "type": "string",
    216                },
    217                "subPathExpr": {
    218                    "description": "Expanded path within the volume from which the container's volume should be mounted. Behaves similarly to SubPath but environment variable references $(VAR_NAME) are expanded using the container's environment. Defaults to \"\" (volume's root). SubPathExpr and SubPath are mutually exclusive.",
    219                    "type": "string",
    220                },
    221            },
    222            "required": [
    223                "mountPath",
    224                "name",
    225            ],
    226        })
    227    }
    228}