#
k8s_openapi/v1_35/api/core/v1/
env_var_source.rs

    1// Generated from definition io.k8s.api.core.v1.EnvVarSource
    2
    3/// EnvVarSource represents a source for the value of an EnvVar.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct EnvVarSource {
    6    /// Selects a key of a ConfigMap.
    7    pub config_map_key_ref: Option<crate::api::core::v1::ConfigMapKeySelector>,
    8
    9    /// Selects a field of the pod: supports metadata.name, metadata.namespace, `metadata.labels\['\<KEY\>'\]`, `metadata.annotations\['\<KEY\>'\]`, spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP, status.podIPs.
    10    pub field_ref: Option<crate::api::core::v1::ObjectFieldSelector>,
    11
    12    /// FileKeyRef selects a key of the env file. Requires the EnvFiles feature gate to be enabled.
    13    pub file_key_ref: Option<crate::api::core::v1::FileKeySelector>,
    14
    15    /// Selects a resource of the container: only resources limits and requests (limits.cpu, limits.memory, limits.ephemeral-storage, requests.cpu, requests.memory and requests.ephemeral-storage) are currently supported.
    16    pub resource_field_ref: Option<crate::api::core::v1::ResourceFieldSelector>,
    17
    18    /// Selects a key of a secret in the pod's namespace
    19    pub secret_key_ref: Option<crate::api::core::v1::SecretKeySelector>,
    20}
    21
    22impl crate::DeepMerge for EnvVarSource {
    23    fn merge_from(&mut self, other: Self) {
    24        crate::DeepMerge::merge_from(&mut self.config_map_key_ref, other.config_map_key_ref);
    25        crate::DeepMerge::merge_from(&mut self.field_ref, other.field_ref);
    26        crate::DeepMerge::merge_from(&mut self.file_key_ref, other.file_key_ref);
    27        crate::DeepMerge::merge_from(&mut self.resource_field_ref, other.resource_field_ref);
    28        crate::DeepMerge::merge_from(&mut self.secret_key_ref, other.secret_key_ref);
    29    }
    30}
    31
    32impl<'de> crate::serde::Deserialize<'de> for EnvVarSource {
    33    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    34        #[allow(non_camel_case_types)]
    35        enum Field {
    36            Key_config_map_key_ref,
    37            Key_field_ref,
    38            Key_file_key_ref,
    39            Key_resource_field_ref,
    40            Key_secret_key_ref,
    41            Other,
    42        }
    43
    44        impl<'de> crate::serde::Deserialize<'de> for Field {
    45            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    46                struct Visitor;
    47
    48                impl crate::serde::de::Visitor<'_> for Visitor {
    49                    type Value = Field;
    50
    51                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    52                        f.write_str("field identifier")
    53                    }
    54
    55                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    56                        Ok(match v {
    57                            "configMapKeyRef" => Field::Key_config_map_key_ref,
    58                            "fieldRef" => Field::Key_field_ref,
    59                            "fileKeyRef" => Field::Key_file_key_ref,
    60                            "resourceFieldRef" => Field::Key_resource_field_ref,
    61                            "secretKeyRef" => Field::Key_secret_key_ref,
    62                            _ => Field::Other,
    63                        })
    64                    }
    65                }
    66
    67                deserializer.deserialize_identifier(Visitor)
    68            }
    69        }
    70
    71        struct Visitor;
    72
    73        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    74            type Value = EnvVarSource;
    75
    76            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    77                f.write_str("EnvVarSource")
    78            }
    79
    80            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    81                let mut value_config_map_key_ref: Option<crate::api::core::v1::ConfigMapKeySelector> = None;
    82                let mut value_field_ref: Option<crate::api::core::v1::ObjectFieldSelector> = None;
    83                let mut value_file_key_ref: Option<crate::api::core::v1::FileKeySelector> = None;
    84                let mut value_resource_field_ref: Option<crate::api::core::v1::ResourceFieldSelector> = None;
    85                let mut value_secret_key_ref: Option<crate::api::core::v1::SecretKeySelector> = None;
    86
    87                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    88                    match key {
    89                        Field::Key_config_map_key_ref => value_config_map_key_ref = crate::serde::de::MapAccess::next_value(&mut map)?,
    90                        Field::Key_field_ref => value_field_ref = crate::serde::de::MapAccess::next_value(&mut map)?,
    91                        Field::Key_file_key_ref => value_file_key_ref = crate::serde::de::MapAccess::next_value(&mut map)?,
    92                        Field::Key_resource_field_ref => value_resource_field_ref = crate::serde::de::MapAccess::next_value(&mut map)?,
    93                        Field::Key_secret_key_ref => value_secret_key_ref = crate::serde::de::MapAccess::next_value(&mut map)?,
    94                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    95                    }
    96                }
    97
    98                Ok(EnvVarSource {
    99                    config_map_key_ref: value_config_map_key_ref,
    100                    field_ref: value_field_ref,
    101                    file_key_ref: value_file_key_ref,
    102                    resource_field_ref: value_resource_field_ref,
    103                    secret_key_ref: value_secret_key_ref,
    104                })
    105            }
    106        }
    107
    108        deserializer.deserialize_struct(
    109            "EnvVarSource",
    110            &[
    111                "configMapKeyRef",
    112                "fieldRef",
    113                "fileKeyRef",
    114                "resourceFieldRef",
    115                "secretKeyRef",
    116            ],
    117            Visitor,
    118        )
    119    }
    120}
    121
    122impl crate::serde::Serialize for EnvVarSource {
    123    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    124        let mut state = serializer.serialize_struct(
    125            "EnvVarSource",
    126            self.config_map_key_ref.as_ref().map_or(0, |_| 1) +
    127            self.field_ref.as_ref().map_or(0, |_| 1) +
    128            self.file_key_ref.as_ref().map_or(0, |_| 1) +
    129            self.resource_field_ref.as_ref().map_or(0, |_| 1) +
    130            self.secret_key_ref.as_ref().map_or(0, |_| 1),
    131        )?;
    132        if let Some(value) = &self.config_map_key_ref {
    133            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "configMapKeyRef", value)?;
    134        }
    135        if let Some(value) = &self.field_ref {
    136            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "fieldRef", value)?;
    137        }
    138        if let Some(value) = &self.file_key_ref {
    139            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "fileKeyRef", value)?;
    140        }
    141        if let Some(value) = &self.resource_field_ref {
    142            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resourceFieldRef", value)?;
    143        }
    144        if let Some(value) = &self.secret_key_ref {
    145            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "secretKeyRef", value)?;
    146        }
    147        crate::serde::ser::SerializeStruct::end(state)
    148    }
    149}
    150
    151#[cfg(feature = "schemars")]
    152impl crate::schemars::JsonSchema for EnvVarSource {
    153    fn schema_name() -> std::borrow::Cow<'static, str> {
    154        "io.k8s.api.core.v1.EnvVarSource".into()
    155    }
    156
    157    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    158        crate::schemars::json_schema!({
    159            "description": "EnvVarSource represents a source for the value of an EnvVar.",
    160            "type": "object",
    161            "properties": {
    162                "configMapKeyRef": ({
    163                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::ConfigMapKeySelector>();
    164                    schema_obj.ensure_object().insert("description".into(), "Selects a key of a ConfigMap.".into());
    165                    schema_obj
    166                }),
    167                "fieldRef": ({
    168                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::ObjectFieldSelector>();
    169                    schema_obj.ensure_object().insert("description".into(), "Selects a field of the pod: supports metadata.name, metadata.namespace, `metadata.labels['<KEY>']`, `metadata.annotations['<KEY>']`, spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP, status.podIPs.".into());
    170                    schema_obj
    171                }),
    172                "fileKeyRef": ({
    173                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::FileKeySelector>();
    174                    schema_obj.ensure_object().insert("description".into(), "FileKeyRef selects a key of the env file. Requires the EnvFiles feature gate to be enabled.".into());
    175                    schema_obj
    176                }),
    177                "resourceFieldRef": ({
    178                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::ResourceFieldSelector>();
    179                    schema_obj.ensure_object().insert("description".into(), "Selects a resource of the container: only resources limits and requests (limits.cpu, limits.memory, limits.ephemeral-storage, requests.cpu, requests.memory and requests.ephemeral-storage) are currently supported.".into());
    180                    schema_obj
    181                }),
    182                "secretKeyRef": ({
    183                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::SecretKeySelector>();
    184                    schema_obj.ensure_object().insert("description".into(), "Selects a key of a secret in the pod's namespace".into());
    185                    schema_obj
    186                }),
    187            },
    188        })
    189    }
    190}