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

    1// Generated from definition io.k8s.api.core.v1.ObjectReference
    2
    3/// ObjectReference contains enough information to let you inspect or modify the referred object.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct ObjectReference {
    6    /// API version of the referent.
    7    pub api_version: Option<std::string::String>,
    8
    9    /// If referring to a piece of an object instead of an entire object, this string should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers\[2\]. For example, if the object reference is to a container within a pod, this would take on a value like: "spec.containers{name}" (where "name" refers to the name of the container that triggered the event) or if no container name is specified "spec.containers\[2\]" (container with index 2 in this pod). This syntax is chosen only to have some well-defined way of referencing a part of an object.
    10    pub field_path: Option<std::string::String>,
    11
    12    /// Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
    13    pub kind: Option<std::string::String>,
    14
    15    /// Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
    16    pub name: Option<std::string::String>,
    17
    18    /// Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
    19    pub namespace: Option<std::string::String>,
    20
    21    /// Specific resourceVersion to which this reference is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency
    22    pub resource_version: Option<std::string::String>,
    23
    24    /// UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids
    25    pub uid: Option<std::string::String>,
    26}
    27
    28impl crate::DeepMerge for ObjectReference {
    29    fn merge_from(&mut self, other: Self) {
    30        crate::DeepMerge::merge_from(&mut self.api_version, other.api_version);
    31        crate::DeepMerge::merge_from(&mut self.field_path, other.field_path);
    32        crate::DeepMerge::merge_from(&mut self.kind, other.kind);
    33        crate::DeepMerge::merge_from(&mut self.name, other.name);
    34        crate::DeepMerge::merge_from(&mut self.namespace, other.namespace);
    35        crate::DeepMerge::merge_from(&mut self.resource_version, other.resource_version);
    36        crate::DeepMerge::merge_from(&mut self.uid, other.uid);
    37    }
    38}
    39
    40impl<'de> crate::serde::Deserialize<'de> for ObjectReference {
    41    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    42        #[allow(non_camel_case_types)]
    43        enum Field {
    44            Key_api_version,
    45            Key_field_path,
    46            Key_kind,
    47            Key_name,
    48            Key_namespace,
    49            Key_resource_version,
    50            Key_uid,
    51            Other,
    52        }
    53
    54        impl<'de> crate::serde::Deserialize<'de> for Field {
    55            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    56                struct Visitor;
    57
    58                impl crate::serde::de::Visitor<'_> for Visitor {
    59                    type Value = Field;
    60
    61                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    62                        f.write_str("field identifier")
    63                    }
    64
    65                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    66                        Ok(match v {
    67                            "apiVersion" => Field::Key_api_version,
    68                            "fieldPath" => Field::Key_field_path,
    69                            "kind" => Field::Key_kind,
    70                            "name" => Field::Key_name,
    71                            "namespace" => Field::Key_namespace,
    72                            "resourceVersion" => Field::Key_resource_version,
    73                            "uid" => Field::Key_uid,
    74                            _ => Field::Other,
    75                        })
    76                    }
    77                }
    78
    79                deserializer.deserialize_identifier(Visitor)
    80            }
    81        }
    82
    83        struct Visitor;
    84
    85        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    86            type Value = ObjectReference;
    87
    88            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    89                f.write_str("ObjectReference")
    90            }
    91
    92            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    93                let mut value_api_version: Option<std::string::String> = None;
    94                let mut value_field_path: Option<std::string::String> = None;
    95                let mut value_kind: Option<std::string::String> = None;
    96                let mut value_name: Option<std::string::String> = None;
    97                let mut value_namespace: Option<std::string::String> = None;
    98                let mut value_resource_version: Option<std::string::String> = None;
    99                let mut value_uid: Option<std::string::String> = None;
    100
    101                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    102                    match key {
    103                        Field::Key_api_version => value_api_version = crate::serde::de::MapAccess::next_value(&mut map)?,
    104                        Field::Key_field_path => value_field_path = crate::serde::de::MapAccess::next_value(&mut map)?,
    105                        Field::Key_kind => value_kind = crate::serde::de::MapAccess::next_value(&mut map)?,
    106                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
    107                        Field::Key_namespace => value_namespace = crate::serde::de::MapAccess::next_value(&mut map)?,
    108                        Field::Key_resource_version => value_resource_version = crate::serde::de::MapAccess::next_value(&mut map)?,
    109                        Field::Key_uid => value_uid = crate::serde::de::MapAccess::next_value(&mut map)?,
    110                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    111                    }
    112                }
    113
    114                Ok(ObjectReference {
    115                    api_version: value_api_version,
    116                    field_path: value_field_path,
    117                    kind: value_kind,
    118                    name: value_name,
    119                    namespace: value_namespace,
    120                    resource_version: value_resource_version,
    121                    uid: value_uid,
    122                })
    123            }
    124        }
    125
    126        deserializer.deserialize_struct(
    127            "ObjectReference",
    128            &[
    129                "apiVersion",
    130                "fieldPath",
    131                "kind",
    132                "name",
    133                "namespace",
    134                "resourceVersion",
    135                "uid",
    136            ],
    137            Visitor,
    138        )
    139    }
    140}
    141
    142impl crate::serde::Serialize for ObjectReference {
    143    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    144        let mut state = serializer.serialize_struct(
    145            "ObjectReference",
    146            self.api_version.as_ref().map_or(0, |_| 1) +
    147            self.field_path.as_ref().map_or(0, |_| 1) +
    148            self.kind.as_ref().map_or(0, |_| 1) +
    149            self.name.as_ref().map_or(0, |_| 1) +
    150            self.namespace.as_ref().map_or(0, |_| 1) +
    151            self.resource_version.as_ref().map_or(0, |_| 1) +
    152            self.uid.as_ref().map_or(0, |_| 1),
    153        )?;
    154        if let Some(value) = &self.api_version {
    155            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", value)?;
    156        }
    157        if let Some(value) = &self.field_path {
    158            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "fieldPath", value)?;
    159        }
    160        if let Some(value) = &self.kind {
    161            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", value)?;
    162        }
    163        if let Some(value) = &self.name {
    164            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", value)?;
    165        }
    166        if let Some(value) = &self.namespace {
    167            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "namespace", value)?;
    168        }
    169        if let Some(value) = &self.resource_version {
    170            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resourceVersion", value)?;
    171        }
    172        if let Some(value) = &self.uid {
    173            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "uid", value)?;
    174        }
    175        crate::serde::ser::SerializeStruct::end(state)
    176    }
    177}
    178
    179#[cfg(feature = "schemars")]
    180impl crate::schemars::JsonSchema for ObjectReference {
    181    fn schema_name() -> std::borrow::Cow<'static, str> {
    182        "io.k8s.api.core.v1.ObjectReference".into()
    183    }
    184
    185    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    186        crate::schemars::json_schema!({
    187            "description": "ObjectReference contains enough information to let you inspect or modify the referred object.",
    188            "type": "object",
    189            "properties": {
    190                "apiVersion": {
    191                    "description": "API version of the referent.",
    192                    "type": "string",
    193                },
    194                "fieldPath": {
    195                    "description": "If referring to a piece of an object instead of an entire object, this string should contain a valid JSON/Go field access statement, such as desiredState.manifest.containers[2]. For example, if the object reference is to a container within a pod, this would take on a value like: \"spec.containers{name}\" (where \"name\" refers to the name of the container that triggered the event) or if no container name is specified \"spec.containers[2]\" (container with index 2 in this pod). This syntax is chosen only to have some well-defined way of referencing a part of an object.",
    196                    "type": "string",
    197                },
    198                "kind": {
    199                    "description": "Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
    200                    "type": "string",
    201                },
    202                "name": {
    203                    "description": "Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names",
    204                    "type": "string",
    205                },
    206                "namespace": {
    207                    "description": "Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/",
    208                    "type": "string",
    209                },
    210                "resourceVersion": {
    211                    "description": "Specific resourceVersion to which this reference is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency",
    212                    "type": "string",
    213                },
    214                "uid": {
    215                    "description": "UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids",
    216                    "type": "string",
    217                },
    218            },
    219        })
    220    }
    221}