k8s_openapi/v1_35/api/core/v1/
config_map_volume_source.rs

1// Generated from definition io.k8s.api.core.v1.ConfigMapVolumeSource
2
3/// Adapts a ConfigMap into a volume.
4///
5/// The contents of the target ConfigMap's Data field will be presented in a volume as files using the keys in the Data field as the file names, unless the items element is populated with specific mappings of keys to paths. ConfigMap volumes support ownership management and SELinux relabeling.
6#[derive(Clone, Debug, Default, PartialEq)]
7pub struct ConfigMapVolumeSource {
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 ConfigMap 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 ConfigMap, 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    /// Name of the referent. This field is effectively required, but due to backwards compatibility is allowed to be empty. Instances of this type with an empty value here are almost certainly wrong. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
15    pub name: std::string::String,
16
17    /// optional specify whether the ConfigMap or its keys must be defined
18    pub optional: Option<bool>,
19}
20
21impl crate::DeepMerge for ConfigMapVolumeSource {
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.name, other.name);
26        crate::DeepMerge::merge_from(&mut self.optional, other.optional);
27    }
28}
29
30impl<'de> crate::serde::Deserialize<'de> for ConfigMapVolumeSource {
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_name,
37            Key_optional,
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                            "name" => Field::Key_name,
57                            "optional" => Field::Key_optional,
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 = ConfigMapVolumeSource;
71
72            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
73                f.write_str("ConfigMapVolumeSource")
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_name: Option<std::string::String> = None;
80                let mut value_optional: Option<bool> = 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_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
87                        Field::Key_optional => value_optional = 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(ConfigMapVolumeSource {
93                    default_mode: value_default_mode,
94                    items: value_items,
95                    name: value_name.unwrap_or_default(),
96                    optional: value_optional,
97                })
98            }
99        }
100
101        deserializer.deserialize_struct(
102            "ConfigMapVolumeSource",
103            &[
104                "defaultMode",
105                "items",
106                "name",
107                "optional",
108            ],
109            Visitor,
110        )
111    }
112}
113
114impl crate::serde::Serialize for ConfigMapVolumeSource {
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            "ConfigMapVolumeSource",
118            1 +
119            self.default_mode.as_ref().map_or(0, |_| 1) +
120            self.items.as_ref().map_or(0, |_| 1) +
121            self.optional.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        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
130        if let Some(value) = &self.optional {
131            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "optional", value)?;
132        }
133        crate::serde::ser::SerializeStruct::end(state)
134    }
135}
136
137#[cfg(feature = "schemars")]
138impl crate::schemars::JsonSchema for ConfigMapVolumeSource {
139    fn schema_name() -> std::borrow::Cow<'static, str> {
140        "io.k8s.api.core.v1.ConfigMapVolumeSource".into()
141    }
142
143    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
144        crate::schemars::json_schema!({
145            "description": "Adapts a ConfigMap into a volume.\n\nThe contents of the target ConfigMap's Data field will be presented in a volume as files using the keys in the Data field as the file names, unless the items element is populated with specific mappings of keys to paths. ConfigMap volumes support ownership management and SELinux relabeling.",
146            "type": "object",
147            "properties": {
148                "defaultMode": {
149                    "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.",
150                    "type": "integer",
151                    "format": "int32",
152                },
153                "items": {
154                    "description": "items if unspecified, each key-value pair in the Data field of the referenced ConfigMap 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 ConfigMap, the volume setup will error unless it is marked optional. Paths must be relative and may not contain the '..' path or start with '..'.",
155                    "type": "array",
156                    "items": (__gen.subschema_for::<crate::api::core::v1::KeyToPath>()),
157                },
158                "name": {
159                    "description": "Name of the referent. This field is effectively required, but due to backwards compatibility is allowed to be empty. Instances of this type with an empty value here are almost certainly wrong. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names",
160                    "type": "string",
161                },
162                "optional": {
163                    "description": "optional specify whether the ConfigMap or its keys must be defined",
164                    "type": "boolean",
165                },
166            },
167            "required": [
168                "name",
169            ],
170        })
171    }
172}