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

1// Generated from definition io.k8s.api.core.v1.ConfigMapProjection
2
3/// Adapts a ConfigMap into a projected volume.
4///
5/// The contents of the target ConfigMap's Data field will be presented in a projected 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. Note that this is identical to a configmap volume source without the default mode.
6#[derive(Clone, Debug, Default, PartialEq)]
7pub struct ConfigMapProjection {
8    /// 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 '..'.
9    pub items: Option<std::vec::Vec<crate::api::core::v1::KeyToPath>>,
10
11    /// 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
12    pub name: std::string::String,
13
14    /// optional specify whether the ConfigMap or its keys must be defined
15    pub optional: Option<bool>,
16}
17
18impl crate::DeepMerge for ConfigMapProjection {
19    fn merge_from(&mut self, other: Self) {
20        crate::merge_strategies::list::atomic(&mut self.items, other.items);
21        crate::DeepMerge::merge_from(&mut self.name, other.name);
22        crate::DeepMerge::merge_from(&mut self.optional, other.optional);
23    }
24}
25
26impl<'de> crate::serde::Deserialize<'de> for ConfigMapProjection {
27    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
28        #[allow(non_camel_case_types)]
29        enum Field {
30            Key_items,
31            Key_name,
32            Key_optional,
33            Other,
34        }
35
36        impl<'de> crate::serde::Deserialize<'de> for Field {
37            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
38                struct Visitor;
39
40                impl crate::serde::de::Visitor<'_> for Visitor {
41                    type Value = Field;
42
43                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
44                        f.write_str("field identifier")
45                    }
46
47                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
48                        Ok(match v {
49                            "items" => Field::Key_items,
50                            "name" => Field::Key_name,
51                            "optional" => Field::Key_optional,
52                            _ => Field::Other,
53                        })
54                    }
55                }
56
57                deserializer.deserialize_identifier(Visitor)
58            }
59        }
60
61        struct Visitor;
62
63        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
64            type Value = ConfigMapProjection;
65
66            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
67                f.write_str("ConfigMapProjection")
68            }
69
70            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
71                let mut value_items: Option<std::vec::Vec<crate::api::core::v1::KeyToPath>> = None;
72                let mut value_name: Option<std::string::String> = None;
73                let mut value_optional: Option<bool> = None;
74
75                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
76                    match key {
77                        Field::Key_items => value_items = crate::serde::de::MapAccess::next_value(&mut map)?,
78                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
79                        Field::Key_optional => value_optional = crate::serde::de::MapAccess::next_value(&mut map)?,
80                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
81                    }
82                }
83
84                Ok(ConfigMapProjection {
85                    items: value_items,
86                    name: value_name.unwrap_or_default(),
87                    optional: value_optional,
88                })
89            }
90        }
91
92        deserializer.deserialize_struct(
93            "ConfigMapProjection",
94            &[
95                "items",
96                "name",
97                "optional",
98            ],
99            Visitor,
100        )
101    }
102}
103
104impl crate::serde::Serialize for ConfigMapProjection {
105    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
106        let mut state = serializer.serialize_struct(
107            "ConfigMapProjection",
108            1 +
109            self.items.as_ref().map_or(0, |_| 1) +
110            self.optional.as_ref().map_or(0, |_| 1),
111        )?;
112        if let Some(value) = &self.items {
113            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "items", value)?;
114        }
115        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
116        if let Some(value) = &self.optional {
117            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "optional", value)?;
118        }
119        crate::serde::ser::SerializeStruct::end(state)
120    }
121}
122
123#[cfg(feature = "schemars")]
124impl crate::schemars::JsonSchema for ConfigMapProjection {
125    fn schema_name() -> std::borrow::Cow<'static, str> {
126        "io.k8s.api.core.v1.ConfigMapProjection".into()
127    }
128
129    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
130        crate::schemars::json_schema!({
131            "description": "Adapts a ConfigMap into a projected volume.\n\nThe contents of the target ConfigMap's Data field will be presented in a projected 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. Note that this is identical to a configmap volume source without the default mode.",
132            "type": "object",
133            "properties": {
134                "items": {
135                    "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 '..'.",
136                    "type": "array",
137                    "items": (__gen.subschema_for::<crate::api::core::v1::KeyToPath>()),
138                },
139                "name": {
140                    "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",
141                    "type": "string",
142                },
143                "optional": {
144                    "description": "optional specify whether the ConfigMap or its keys must be defined",
145                    "type": "boolean",
146                },
147            },
148            "required": [
149                "name",
150            ],
151        })
152    }
153}