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

    1// Generated from definition io.k8s.api.core.v1.SecretVolumeSource
    2
    3/// Adapts a Secret into a volume.
    4///
    5/// The contents of the target Secret's Data field will be presented in a volume as files using the keys in the Data field as the file names. Secret volumes support ownership management and SELinux relabeling.
    6#[derive(Clone, Debug, Default, PartialEq)]
    7pub struct SecretVolumeSource {
    8    /// defaultMode is Optional: mode bits used to set permissions on created files by default. Must be an octal value between 0000 and 0777 or a decimal value between 0 and 511. YAML accepts both octal and decimal values, JSON requires decimal values for mode bits. Defaults to 0644. Directories within the path are not affected by this setting. This might be in conflict with other options that affect the file mode, like fsGroup, and the result can be other mode bits set.
    9    pub default_mode: Option<i32>,
    10
    11    /// items If unspecified, each key-value pair in the Data field of the referenced Secret will be projected into the volume as a file whose name is the key and content is the value. If specified, the listed keys will be projected into the specified paths, and unlisted keys will not be present. If a key is specified which is not present in the Secret, the volume setup will error unless it is marked optional. Paths must be relative and may not contain the '..' path or start with '..'.
    12    pub items: Option<std::vec::Vec<crate::api::core::v1::KeyToPath>>,
    13
    14    /// optional field specify whether the Secret or its keys must be defined
    15    pub optional: Option<bool>,
    16
    17    /// secretName is the name of the secret in the pod's namespace to use. More info: https://kubernetes.io/docs/concepts/storage/volumes#secret
    18    pub secret_name: Option<std::string::String>,
    19}
    20
    21impl crate::DeepMerge for SecretVolumeSource {
    22    fn merge_from(&mut self, other: Self) {
    23        crate::DeepMerge::merge_from(&mut self.default_mode, other.default_mode);
    24        crate::merge_strategies::list::atomic(&mut self.items, other.items);
    25        crate::DeepMerge::merge_from(&mut self.optional, other.optional);
    26        crate::DeepMerge::merge_from(&mut self.secret_name, other.secret_name);
    27    }
    28}
    29
    30impl<'de> crate::serde::Deserialize<'de> for SecretVolumeSource {
    31    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    32        #[allow(non_camel_case_types)]
    33        enum Field {
    34            Key_default_mode,
    35            Key_items,
    36            Key_optional,
    37            Key_secret_name,
    38            Other,
    39        }
    40
    41        impl<'de> crate::serde::Deserialize<'de> for Field {
    42            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    43                struct Visitor;
    44
    45                impl crate::serde::de::Visitor<'_> for Visitor {
    46                    type Value = Field;
    47
    48                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    49                        f.write_str("field identifier")
    50                    }
    51
    52                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    53                        Ok(match v {
    54                            "defaultMode" => Field::Key_default_mode,
    55                            "items" => Field::Key_items,
    56                            "optional" => Field::Key_optional,
    57                            "secretName" => Field::Key_secret_name,
    58                            _ => Field::Other,
    59                        })
    60                    }
    61                }
    62
    63                deserializer.deserialize_identifier(Visitor)
    64            }
    65        }
    66
    67        struct Visitor;
    68
    69        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    70            type Value = SecretVolumeSource;
    71
    72            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    73                f.write_str("SecretVolumeSource")
    74            }
    75
    76            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    77                let mut value_default_mode: Option<i32> = None;
    78                let mut value_items: Option<std::vec::Vec<crate::api::core::v1::KeyToPath>> = None;
    79                let mut value_optional: Option<bool> = None;
    80                let mut value_secret_name: Option<std::string::String> = None;
    81
    82                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    83                    match key {
    84                        Field::Key_default_mode => value_default_mode = crate::serde::de::MapAccess::next_value(&mut map)?,
    85                        Field::Key_items => value_items = crate::serde::de::MapAccess::next_value(&mut map)?,
    86                        Field::Key_optional => value_optional = crate::serde::de::MapAccess::next_value(&mut map)?,
    87                        Field::Key_secret_name => value_secret_name = crate::serde::de::MapAccess::next_value(&mut map)?,
    88                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    89                    }
    90                }
    91
    92                Ok(SecretVolumeSource {
    93                    default_mode: value_default_mode,
    94                    items: value_items,
    95                    optional: value_optional,
    96                    secret_name: value_secret_name,
    97                })
    98            }
    99        }
    100
    101        deserializer.deserialize_struct(
    102            "SecretVolumeSource",
    103            &[
    104                "defaultMode",
    105                "items",
    106                "optional",
    107                "secretName",
    108            ],
    109            Visitor,
    110        )
    111    }
    112}
    113
    114impl crate::serde::Serialize for SecretVolumeSource {
    115    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    116        let mut state = serializer.serialize_struct(
    117            "SecretVolumeSource",
    118            self.default_mode.as_ref().map_or(0, |_| 1) +
    119            self.items.as_ref().map_or(0, |_| 1) +
    120            self.optional.as_ref().map_or(0, |_| 1) +
    121            self.secret_name.as_ref().map_or(0, |_| 1),
    122        )?;
    123        if let Some(value) = &self.default_mode {
    124            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "defaultMode", value)?;
    125        }
    126        if let Some(value) = &self.items {
    127            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "items", value)?;
    128        }
    129        if let Some(value) = &self.optional {
    130            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "optional", value)?;
    131        }
    132        if let Some(value) = &self.secret_name {
    133            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "secretName", value)?;
    134        }
    135        crate::serde::ser::SerializeStruct::end(state)
    136    }
    137}
    138
    139#[cfg(feature = "schemars")]
    140impl crate::schemars::JsonSchema for SecretVolumeSource {
    141    fn schema_name() -> std::borrow::Cow<'static, str> {
    142        "io.k8s.api.core.v1.SecretVolumeSource".into()
    143    }
    144
    145    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    146        crate::schemars::json_schema!({
    147            "description": "Adapts a Secret into a volume.\n\nThe contents of the target Secret's Data field will be presented in a volume as files using the keys in the Data field as the file names. Secret volumes support ownership management and SELinux relabeling.",
    148            "type": "object",
    149            "properties": {
    150                "defaultMode": {
    151                    "description": "defaultMode is Optional: mode bits used to set permissions on created files by default. Must be an octal value between 0000 and 0777 or a decimal value between 0 and 511. YAML accepts both octal and decimal values, JSON requires decimal values for mode bits. Defaults to 0644. Directories within the path are not affected by this setting. This might be in conflict with other options that affect the file mode, like fsGroup, and the result can be other mode bits set.",
    152                    "type": "integer",
    153                    "format": "int32",
    154                },
    155                "items": {
    156                    "description": "items If unspecified, each key-value pair in the Data field of the referenced Secret will be projected into the volume as a file whose name is the key and content is the value. If specified, the listed keys will be projected into the specified paths, and unlisted keys will not be present. If a key is specified which is not present in the Secret, the volume setup will error unless it is marked optional. Paths must be relative and may not contain the '..' path or start with '..'.",
    157                    "type": "array",
    158                    "items": (__gen.subschema_for::<crate::api::core::v1::KeyToPath>()),
    159                },
    160                "optional": {
    161                    "description": "optional field specify whether the Secret or its keys must be defined",
    162                    "type": "boolean",
    163                },
    164                "secretName": {
    165                    "description": "secretName is the name of the secret in the pod's namespace to use. More info: https://kubernetes.io/docs/concepts/storage/volumes#secret",
    166                    "type": "string",
    167                },
    168            },
    169        })
    170    }
    171}