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: 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<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 std::fmt::Formatter<'_>) -> std::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 std::fmt::Formatter<'_>) -> std::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<String> = None;
70                let mut value_value: Option<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() -> String {
124        "io.k8s.api.core.v1.EnvVar".to_owned()
125    }
126
127    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
128        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
129            metadata: Some(Box::new(crate::schemars::schema::Metadata {
130                description: Some("EnvVar represents an environment variable present in a Container.".to_owned()),
131                ..Default::default()
132            })),
133            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
134            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
135                properties: [
136                    (
137                        "name".to_owned(),
138                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
139                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
140                                description: Some("Name of the environment variable. Must be a C_IDENTIFIER.".to_owned()),
141                                ..Default::default()
142                            })),
143                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
144                            ..Default::default()
145                        }),
146                    ),
147                    (
148                        "value".to_owned(),
149                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
150                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
151                                description: Some("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 \"\".".to_owned()),
152                                ..Default::default()
153                            })),
154                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
155                            ..Default::default()
156                        }),
157                    ),
158                    (
159                        "valueFrom".to_owned(),
160                        {
161                            let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::EnvVarSource>().into_object();
162                            schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
163                                description: Some("Source for the environment variable's value. Cannot be used if value is not empty.".to_owned()),
164                                ..Default::default()
165                            }));
166                            crate::schemars::schema::Schema::Object(schema_obj)
167                        },
168                    ),
169                ].into(),
170                required: [
171                    "name".to_owned(),
172                ].into(),
173                ..Default::default()
174            })),
175            ..Default::default()
176        })
177    }
178}