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

1// Generated from definition io.k8s.api.core.v1.EnvVar
2
3/// EnvVar represents an environment variable present in a Container.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct EnvVar {
6    /// Name of the environment variable. Must be a C_IDENTIFIER.
7    pub name: std::string::String,
8
9    /// Variable references $(VAR_NAME) are expanded using the previously defined environment variables in the container and any service environment variables. If a variable cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will produce the string literal "$(VAR_NAME)". Escaped references will never be expanded, regardless of whether the variable exists or not. Defaults to "".
10    pub value: Option<std::string::String>,
11
12    /// Source for the environment variable's value. Cannot be used if value is not empty.
13    pub value_from: Option<crate::api::core::v1::EnvVarSource>,
14}
15
16impl crate::DeepMerge for EnvVar {
17    fn merge_from(&mut self, other: Self) {
18        crate::DeepMerge::merge_from(&mut self.name, other.name);
19        crate::DeepMerge::merge_from(&mut self.value, other.value);
20        crate::DeepMerge::merge_from(&mut self.value_from, other.value_from);
21    }
22}
23
24impl<'de> crate::serde::Deserialize<'de> for EnvVar {
25    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
26        #[allow(non_camel_case_types)]
27        enum Field {
28            Key_name,
29            Key_value,
30            Key_value_from,
31            Other,
32        }
33
34        impl<'de> crate::serde::Deserialize<'de> for Field {
35            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
36                struct Visitor;
37
38                impl crate::serde::de::Visitor<'_> for Visitor {
39                    type Value = Field;
40
41                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
42                        f.write_str("field identifier")
43                    }
44
45                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
46                        Ok(match v {
47                            "name" => Field::Key_name,
48                            "value" => Field::Key_value,
49                            "valueFrom" => Field::Key_value_from,
50                            _ => Field::Other,
51                        })
52                    }
53                }
54
55                deserializer.deserialize_identifier(Visitor)
56            }
57        }
58
59        struct Visitor;
60
61        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
62            type Value = EnvVar;
63
64            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
65                f.write_str("EnvVar")
66            }
67
68            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
69                let mut value_name: Option<std::string::String> = None;
70                let mut value_value: Option<std::string::String> = None;
71                let mut value_value_from: Option<crate::api::core::v1::EnvVarSource> = None;
72
73                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
74                    match key {
75                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
76                        Field::Key_value => value_value = crate::serde::de::MapAccess::next_value(&mut map)?,
77                        Field::Key_value_from => value_value_from = crate::serde::de::MapAccess::next_value(&mut map)?,
78                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
79                    }
80                }
81
82                Ok(EnvVar {
83                    name: value_name.unwrap_or_default(),
84                    value: value_value,
85                    value_from: value_value_from,
86                })
87            }
88        }
89
90        deserializer.deserialize_struct(
91            "EnvVar",
92            &[
93                "name",
94                "value",
95                "valueFrom",
96            ],
97            Visitor,
98        )
99    }
100}
101
102impl crate::serde::Serialize for EnvVar {
103    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
104        let mut state = serializer.serialize_struct(
105            "EnvVar",
106            1 +
107            self.value.as_ref().map_or(0, |_| 1) +
108            self.value_from.as_ref().map_or(0, |_| 1),
109        )?;
110        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
111        if let Some(value) = &self.value {
112            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "value", value)?;
113        }
114        if let Some(value) = &self.value_from {
115            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "valueFrom", value)?;
116        }
117        crate::serde::ser::SerializeStruct::end(state)
118    }
119}
120
121#[cfg(feature = "schemars")]
122impl crate::schemars::JsonSchema for EnvVar {
123    fn schema_name() -> std::borrow::Cow<'static, str> {
124        "io.k8s.api.core.v1.EnvVar".into()
125    }
126
127    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
128        crate::schemars::json_schema!({
129            "description": "EnvVar represents an environment variable present in a Container.",
130            "type": "object",
131            "properties": {
132                "name": {
133                    "description": "Name of the environment variable. Must be a C_IDENTIFIER.",
134                    "type": "string",
135                },
136                "value": {
137                    "description": "Variable references $(VAR_NAME) are expanded using the previously defined environment variables in the container and any service environment variables. If a variable cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. \"$$(VAR_NAME)\" will produce the string literal \"$(VAR_NAME)\". Escaped references will never be expanded, regardless of whether the variable exists or not. Defaults to \"\".",
138                    "type": "string",
139                },
140                "valueFrom": ({
141                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::EnvVarSource>();
142                    schema_obj.ensure_object().insert("description".into(), "Source for the environment variable's value. Cannot be used if value is not empty.".into());
143                    schema_obj
144                }),
145            },
146            "required": [
147                "name",
148            ],
149        })
150    }
151}