k8s_openapi/v1_30/api/core/v1/
config_map.rs

1// Generated from definition io.k8s.api.core.v1.ConfigMap
2
3/// ConfigMap holds configuration data for pods to consume.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ConfigMap {
6    /// BinaryData contains the binary data. Each key must consist of alphanumeric characters, '-', '_' or '.'. BinaryData can contain byte sequences that are not in the UTF-8 range. The keys stored in BinaryData must not overlap with the ones in the Data field, this is enforced during validation process. Using this field will require 1.10+ apiserver and kubelet.
7    pub binary_data: Option<std::collections::BTreeMap<std::string::String, crate::ByteString>>,
8
9    /// Data contains the configuration data. Each key must consist of alphanumeric characters, '-', '_' or '.'. Values with non-UTF-8 byte sequences must use the BinaryData field. The keys stored in Data must not overlap with the keys in the BinaryData field, this is enforced during validation process.
10    pub data: Option<std::collections::BTreeMap<std::string::String, std::string::String>>,
11
12    /// Immutable, if set to true, ensures that data stored in the ConfigMap cannot be updated (only object metadata can be modified). If not set to true, the field can be modified at any time. Defaulted to nil.
13    pub immutable: Option<bool>,
14
15    /// Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
16    pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
17}
18
19impl crate::Resource for ConfigMap {
20    const API_VERSION: &'static str = "v1";
21    const GROUP: &'static str = "";
22    const KIND: &'static str = "ConfigMap";
23    const VERSION: &'static str = "v1";
24    const URL_PATH_SEGMENT: &'static str = "configmaps";
25    type Scope = crate::NamespaceResourceScope;
26}
27
28impl crate::ListableResource for ConfigMap {
29    const LIST_KIND: &'static str = "ConfigMapList";
30}
31
32impl crate::Metadata for ConfigMap {
33    type Ty = crate::apimachinery::pkg::apis::meta::v1::ObjectMeta;
34
35    fn metadata(&self) -> &<Self as crate::Metadata>::Ty {
36        &self.metadata
37    }
38
39    fn metadata_mut(&mut self) -> &mut<Self as crate::Metadata>::Ty {
40        &mut self.metadata
41    }
42}
43
44impl crate::DeepMerge for ConfigMap {
45    fn merge_from(&mut self, other: Self) {
46        crate::merge_strategies::map::granular(&mut self.binary_data, other.binary_data, |current_item, other_item| {
47            crate::DeepMerge::merge_from(current_item, other_item);
48        });
49        crate::merge_strategies::map::granular(&mut self.data, other.data, |current_item, other_item| {
50            crate::DeepMerge::merge_from(current_item, other_item);
51        });
52        crate::DeepMerge::merge_from(&mut self.immutable, other.immutable);
53        crate::DeepMerge::merge_from(&mut self.metadata, other.metadata);
54    }
55}
56
57impl<'de> crate::serde::Deserialize<'de> for ConfigMap {
58    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
59        #[allow(non_camel_case_types)]
60        enum Field {
61            Key_api_version,
62            Key_kind,
63            Key_binary_data,
64            Key_data,
65            Key_immutable,
66            Key_metadata,
67            Other,
68        }
69
70        impl<'de> crate::serde::Deserialize<'de> for Field {
71            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
72                struct Visitor;
73
74                impl crate::serde::de::Visitor<'_> for Visitor {
75                    type Value = Field;
76
77                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
78                        f.write_str("field identifier")
79                    }
80
81                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
82                        Ok(match v {
83                            "apiVersion" => Field::Key_api_version,
84                            "kind" => Field::Key_kind,
85                            "binaryData" => Field::Key_binary_data,
86                            "data" => Field::Key_data,
87                            "immutable" => Field::Key_immutable,
88                            "metadata" => Field::Key_metadata,
89                            _ => Field::Other,
90                        })
91                    }
92                }
93
94                deserializer.deserialize_identifier(Visitor)
95            }
96        }
97
98        struct Visitor;
99
100        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
101            type Value = ConfigMap;
102
103            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
104                f.write_str(<Self::Value as crate::Resource>::KIND)
105            }
106
107            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
108                let mut value_binary_data: Option<std::collections::BTreeMap<std::string::String, crate::ByteString>> = None;
109                let mut value_data: Option<std::collections::BTreeMap<std::string::String, std::string::String>> = None;
110                let mut value_immutable: Option<bool> = None;
111                let mut value_metadata: Option<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
112
113                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
114                    match key {
115                        Field::Key_api_version => {
116                            let value_api_version: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
117                            if value_api_version != <Self::Value as crate::Resource>::API_VERSION {
118                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_api_version), &<Self::Value as crate::Resource>::API_VERSION));
119                            }
120                        },
121                        Field::Key_kind => {
122                            let value_kind: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
123                            if value_kind != <Self::Value as crate::Resource>::KIND {
124                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_kind), &<Self::Value as crate::Resource>::KIND));
125                            }
126                        },
127                        Field::Key_binary_data => value_binary_data = crate::serde::de::MapAccess::next_value(&mut map)?,
128                        Field::Key_data => value_data = crate::serde::de::MapAccess::next_value(&mut map)?,
129                        Field::Key_immutable => value_immutable = crate::serde::de::MapAccess::next_value(&mut map)?,
130                        Field::Key_metadata => value_metadata = crate::serde::de::MapAccess::next_value(&mut map)?,
131                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
132                    }
133                }
134
135                Ok(ConfigMap {
136                    binary_data: value_binary_data,
137                    data: value_data,
138                    immutable: value_immutable,
139                    metadata: value_metadata.unwrap_or_default(),
140                })
141            }
142        }
143
144        deserializer.deserialize_struct(
145            <Self as crate::Resource>::KIND,
146            &[
147                "apiVersion",
148                "kind",
149                "binaryData",
150                "data",
151                "immutable",
152                "metadata",
153            ],
154            Visitor,
155        )
156    }
157}
158
159impl crate::serde::Serialize for ConfigMap {
160    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
161        let mut state = serializer.serialize_struct(
162            <Self as crate::Resource>::KIND,
163            3 +
164            self.binary_data.as_ref().map_or(0, |_| 1) +
165            self.data.as_ref().map_or(0, |_| 1) +
166            self.immutable.as_ref().map_or(0, |_| 1),
167        )?;
168        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as crate::Resource>::API_VERSION)?;
169        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as crate::Resource>::KIND)?;
170        if let Some(value) = &self.binary_data {
171            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "binaryData", value)?;
172        }
173        if let Some(value) = &self.data {
174            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "data", value)?;
175        }
176        if let Some(value) = &self.immutable {
177            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "immutable", value)?;
178        }
179        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
180        crate::serde::ser::SerializeStruct::end(state)
181    }
182}
183
184#[cfg(feature = "schemars")]
185impl crate::schemars::JsonSchema for ConfigMap {
186    fn schema_name() -> std::borrow::Cow<'static, str> {
187        "io.k8s.api.core.v1.ConfigMap".into()
188    }
189
190    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
191        crate::schemars::json_schema!({
192            "description": "ConfigMap holds configuration data for pods to consume.",
193            "type": "object",
194            "properties": {
195                "apiVersion": {
196                    "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",
197                    "type": "string",
198                },
199                "binaryData": {
200                    "description": "BinaryData contains the binary data. Each key must consist of alphanumeric characters, '-', '_' or '.'. BinaryData can contain byte sequences that are not in the UTF-8 range. The keys stored in BinaryData must not overlap with the ones in the Data field, this is enforced during validation process. Using this field will require 1.10+ apiserver and kubelet.",
201                    "type": "object",
202                    "additionalProperties": {
203                        "type": "string",
204                        "format": "byte",
205                    },
206                },
207                "data": {
208                    "description": "Data contains the configuration data. Each key must consist of alphanumeric characters, '-', '_' or '.'. Values with non-UTF-8 byte sequences must use the BinaryData field. The keys stored in Data must not overlap with the keys in the BinaryData field, this is enforced during validation process.",
209                    "type": "object",
210                    "additionalProperties": {
211                        "type": "string",
212                    },
213                },
214                "immutable": {
215                    "description": "Immutable, if set to true, ensures that data stored in the ConfigMap cannot be updated (only object metadata can be modified). If not set to true, the field can be modified at any time. Defaulted to nil.",
216                    "type": "boolean",
217                },
218                "kind": {
219                    "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",
220                    "type": "string",
221                },
222                "metadata": ({
223                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>();
224                    schema_obj.ensure_object().insert("description".into(), "Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata".into());
225                    schema_obj
226                }),
227            },
228            "required": [
229                "metadata",
230            ],
231        })
232    }
233}