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

    1// Generated from definition io.k8s.api.core.v1.Service
    2
    3/// Service is a named abstraction of software service (for example, mysql) consisting of local port (for example 3306) that the proxy listens on, and the selector that determines which pods will answer requests sent through the proxy.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct Service {
    6    /// Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
    7    pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
    8
    9    /// Spec defines the behavior of a service. https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
    10    pub spec: Option<crate::api::core::v1::ServiceSpec>,
    11
    12    /// Most recently observed status of the service. Populated by the system. Read-only. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
    13    pub status: Option<crate::api::core::v1::ServiceStatus>,
    14}
    15
    16impl crate::Resource for Service {
    17    const API_VERSION: &'static str = "v1";
    18    const GROUP: &'static str = "";
    19    const KIND: &'static str = "Service";
    20    const VERSION: &'static str = "v1";
    21    const URL_PATH_SEGMENT: &'static str = "services";
    22    type Scope = crate::NamespaceResourceScope;
    23}
    24
    25impl crate::ListableResource for Service {
    26    const LIST_KIND: &'static str = "ServiceList";
    27}
    28
    29impl crate::Metadata for Service {
    30    type Ty = crate::apimachinery::pkg::apis::meta::v1::ObjectMeta;
    31
    32    fn metadata(&self) -> &<Self as crate::Metadata>::Ty {
    33        &self.metadata
    34    }
    35
    36    fn metadata_mut(&mut self) -> &mut<Self as crate::Metadata>::Ty {
    37        &mut self.metadata
    38    }
    39}
    40
    41impl crate::DeepMerge for Service {
    42    fn merge_from(&mut self, other: Self) {
    43        crate::DeepMerge::merge_from(&mut self.metadata, other.metadata);
    44        crate::DeepMerge::merge_from(&mut self.spec, other.spec);
    45        crate::DeepMerge::merge_from(&mut self.status, other.status);
    46    }
    47}
    48
    49impl<'de> crate::serde::Deserialize<'de> for Service {
    50    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    51        #[allow(non_camel_case_types)]
    52        enum Field {
    53            Key_api_version,
    54            Key_kind,
    55            Key_metadata,
    56            Key_spec,
    57            Key_status,
    58            Other,
    59        }
    60
    61        impl<'de> crate::serde::Deserialize<'de> for Field {
    62            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    63                struct Visitor;
    64
    65                impl crate::serde::de::Visitor<'_> for Visitor {
    66                    type Value = Field;
    67
    68                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    69                        f.write_str("field identifier")
    70                    }
    71
    72                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    73                        Ok(match v {
    74                            "apiVersion" => Field::Key_api_version,
    75                            "kind" => Field::Key_kind,
    76                            "metadata" => Field::Key_metadata,
    77                            "spec" => Field::Key_spec,
    78                            "status" => Field::Key_status,
    79                            _ => Field::Other,
    80                        })
    81                    }
    82                }
    83
    84                deserializer.deserialize_identifier(Visitor)
    85            }
    86        }
    87
    88        struct Visitor;
    89
    90        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    91            type Value = Service;
    92
    93            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    94                f.write_str(<Self::Value as crate::Resource>::KIND)
    95            }
    96
    97            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    98                let mut value_metadata: Option<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
    99                let mut value_spec: Option<crate::api::core::v1::ServiceSpec> = None;
    100                let mut value_status: Option<crate::api::core::v1::ServiceStatus> = None;
    101
    102                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    103                    match key {
    104                        Field::Key_api_version => {
    105                            let value_api_version: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    106                            if value_api_version != <Self::Value as crate::Resource>::API_VERSION {
    107                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_api_version), &<Self::Value as crate::Resource>::API_VERSION));
    108                            }
    109                        },
    110                        Field::Key_kind => {
    111                            let value_kind: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    112                            if value_kind != <Self::Value as crate::Resource>::KIND {
    113                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_kind), &<Self::Value as crate::Resource>::KIND));
    114                            }
    115                        },
    116                        Field::Key_metadata => value_metadata = crate::serde::de::MapAccess::next_value(&mut map)?,
    117                        Field::Key_spec => value_spec = crate::serde::de::MapAccess::next_value(&mut map)?,
    118                        Field::Key_status => value_status = crate::serde::de::MapAccess::next_value(&mut map)?,
    119                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    120                    }
    121                }
    122
    123                Ok(Service {
    124                    metadata: value_metadata.unwrap_or_default(),
    125                    spec: value_spec,
    126                    status: value_status,
    127                })
    128            }
    129        }
    130
    131        deserializer.deserialize_struct(
    132            <Self as crate::Resource>::KIND,
    133            &[
    134                "apiVersion",
    135                "kind",
    136                "metadata",
    137                "spec",
    138                "status",
    139            ],
    140            Visitor,
    141        )
    142    }
    143}
    144
    145impl crate::serde::Serialize for Service {
    146    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    147        let mut state = serializer.serialize_struct(
    148            <Self as crate::Resource>::KIND,
    149            3 +
    150            self.spec.as_ref().map_or(0, |_| 1) +
    151            self.status.as_ref().map_or(0, |_| 1),
    152        )?;
    153        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as crate::Resource>::API_VERSION)?;
    154        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as crate::Resource>::KIND)?;
    155        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
    156        if let Some(value) = &self.spec {
    157            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "spec", value)?;
    158        }
    159        if let Some(value) = &self.status {
    160            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "status", value)?;
    161        }
    162        crate::serde::ser::SerializeStruct::end(state)
    163    }
    164}
    165
    166#[cfg(feature = "schemars")]
    167impl crate::schemars::JsonSchema for Service {
    168    fn schema_name() -> std::borrow::Cow<'static, str> {
    169        "io.k8s.api.core.v1.Service".into()
    170    }
    171
    172    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    173        crate::schemars::json_schema!({
    174            "description": "Service is a named abstraction of software service (for example, mysql) consisting of local port (for example 3306) that the proxy listens on, and the selector that determines which pods will answer requests sent through the proxy.",
    175            "type": "object",
    176            "properties": {
    177                "apiVersion": {
    178                    "description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
    179                    "type": "string",
    180                },
    181                "kind": {
    182                    "description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
    183                    "type": "string",
    184                },
    185                "metadata": ({
    186                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>();
    187                    schema_obj.ensure_object().insert("description".into(), "Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata".into());
    188                    schema_obj
    189                }),
    190                "spec": ({
    191                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::ServiceSpec>();
    192                    schema_obj.ensure_object().insert("description".into(), "Spec defines the behavior of a service. https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status".into());
    193                    schema_obj
    194                }),
    195                "status": ({
    196                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::ServiceStatus>();
    197                    schema_obj.ensure_object().insert("description".into(), "Most recently observed status of the service. Populated by the system. Read-only. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status".into());
    198                    schema_obj
    199                }),
    200            },
    201            "required": [
    202                "metadata",
    203            ],
    204        })
    205    }
    206}