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

1// Generated from definition io.k8s.api.core.v1.FileKeySelector
2
3/// FileKeySelector selects a key of the env file.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct FileKeySelector {
6    /// The key within the env file. An invalid key will prevent the pod from starting. The keys defined within a source may consist of any printable ASCII characters except '='. During Alpha stage of the EnvFiles feature gate, the key size is limited to 128 characters.
7    pub key: std::string::String,
8
9    /// Specify whether the file or its key must be defined. If the file or key does not exist, then the env var is not published. If optional is set to true and the specified key does not exist, the environment variable will not be set in the Pod's containers.
10    ///
11    /// If optional is set to false and the specified key does not exist, an error will be returned during Pod creation.
12    pub optional: Option<bool>,
13
14    /// The path within the volume from which to select the file. Must be relative and may not contain the '..' path or start with '..'.
15    pub path: std::string::String,
16
17    /// The name of the volume mount containing the env file.
18    pub volume_name: std::string::String,
19}
20
21impl crate::DeepMerge for FileKeySelector {
22    fn merge_from(&mut self, other: Self) {
23        crate::DeepMerge::merge_from(&mut self.key, other.key);
24        crate::DeepMerge::merge_from(&mut self.optional, other.optional);
25        crate::DeepMerge::merge_from(&mut self.path, other.path);
26        crate::DeepMerge::merge_from(&mut self.volume_name, other.volume_name);
27    }
28}
29
30impl<'de> crate::serde::Deserialize<'de> for FileKeySelector {
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_key,
35            Key_optional,
36            Key_path,
37            Key_volume_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                            "key" => Field::Key_key,
55                            "optional" => Field::Key_optional,
56                            "path" => Field::Key_path,
57                            "volumeName" => Field::Key_volume_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 = FileKeySelector;
71
72            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
73                f.write_str("FileKeySelector")
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_key: Option<std::string::String> = None;
78                let mut value_optional: Option<bool> = None;
79                let mut value_path: Option<std::string::String> = None;
80                let mut value_volume_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_key => value_key = crate::serde::de::MapAccess::next_value(&mut map)?,
85                        Field::Key_optional => value_optional = crate::serde::de::MapAccess::next_value(&mut map)?,
86                        Field::Key_path => value_path = crate::serde::de::MapAccess::next_value(&mut map)?,
87                        Field::Key_volume_name => value_volume_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(FileKeySelector {
93                    key: value_key.unwrap_or_default(),
94                    optional: value_optional,
95                    path: value_path.unwrap_or_default(),
96                    volume_name: value_volume_name.unwrap_or_default(),
97                })
98            }
99        }
100
101        deserializer.deserialize_struct(
102            "FileKeySelector",
103            &[
104                "key",
105                "optional",
106                "path",
107                "volumeName",
108            ],
109            Visitor,
110        )
111    }
112}
113
114impl crate::serde::Serialize for FileKeySelector {
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            "FileKeySelector",
118            3 +
119            self.optional.as_ref().map_or(0, |_| 1),
120        )?;
121        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "key", &self.key)?;
122        if let Some(value) = &self.optional {
123            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "optional", value)?;
124        }
125        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "path", &self.path)?;
126        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "volumeName", &self.volume_name)?;
127        crate::serde::ser::SerializeStruct::end(state)
128    }
129}
130
131#[cfg(feature = "schemars")]
132impl crate::schemars::JsonSchema for FileKeySelector {
133    fn schema_name() -> std::borrow::Cow<'static, str> {
134        "io.k8s.api.core.v1.FileKeySelector".into()
135    }
136
137    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
138        crate::schemars::json_schema!({
139            "description": "FileKeySelector selects a key of the env file.",
140            "type": "object",
141            "properties": {
142                "key": {
143                    "description": "The key within the env file. An invalid key will prevent the pod from starting. The keys defined within a source may consist of any printable ASCII characters except '='. During Alpha stage of the EnvFiles feature gate, the key size is limited to 128 characters.",
144                    "type": "string",
145                },
146                "optional": {
147                    "description": "Specify whether the file or its key must be defined. If the file or key does not exist, then the env var is not published. If optional is set to true and the specified key does not exist, the environment variable will not be set in the Pod's containers.\n\nIf optional is set to false and the specified key does not exist, an error will be returned during Pod creation.",
148                    "type": "boolean",
149                },
150                "path": {
151                    "description": "The path within the volume from which to select the file. Must be relative and may not contain the '..' path or start with '..'.",
152                    "type": "string",
153                },
154                "volumeName": {
155                    "description": "The name of the volume mount containing the env file.",
156                    "type": "string",
157                },
158            },
159            "required": [
160                "key",
161                "path",
162                "volumeName",
163            ],
164        })
165    }
166}