#
k8s_openapi/v1_35/api/networking/v1beta1/
ip_address.rs

    1// Generated from definition io.k8s.api.networking.v1beta1.IPAddress
    2
    3/// IPAddress represents a single IP of a single IP Family. The object is designed to be used by APIs that operate on IP addresses. The object is used by the Service core API for allocation of IP addresses. An IP address can be represented in different formats, to guarantee the uniqueness of the IP, the name of the object is the IP address in canonical format, four decimal digits separated by dots suppressing leading zeros for IPv4 and the representation defined by RFC 5952 for IPv6. Valid: 192.168.1.5 or 2001:db8::1 or 2001:db8:aaaa:bbbb:cccc:dddd:eeee:1 Invalid: 10.01.2.3 or 2001:db8:0:0:0::1
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct IPAddress {
    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 is the desired state of the IPAddress. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
    10    pub spec: Option<crate::api::networking::v1beta1::IPAddressSpec>,
    11}
    12
    13impl crate::Resource for IPAddress {
    14    const API_VERSION: &'static str = "networking.k8s.io/v1beta1";
    15    const GROUP: &'static str = "networking.k8s.io";
    16    const KIND: &'static str = "IPAddress";
    17    const VERSION: &'static str = "v1beta1";
    18    const URL_PATH_SEGMENT: &'static str = "ipaddresses";
    19    type Scope = crate::ClusterResourceScope;
    20}
    21
    22impl crate::ListableResource for IPAddress {
    23    const LIST_KIND: &'static str = "IPAddressList";
    24}
    25
    26impl crate::Metadata for IPAddress {
    27    type Ty = crate::apimachinery::pkg::apis::meta::v1::ObjectMeta;
    28
    29    fn metadata(&self) -> &<Self as crate::Metadata>::Ty {
    30        &self.metadata
    31    }
    32
    33    fn metadata_mut(&mut self) -> &mut<Self as crate::Metadata>::Ty {
    34        &mut self.metadata
    35    }
    36}
    37
    38impl crate::DeepMerge for IPAddress {
    39    fn merge_from(&mut self, other: Self) {
    40        crate::DeepMerge::merge_from(&mut self.metadata, other.metadata);
    41        crate::DeepMerge::merge_from(&mut self.spec, other.spec);
    42    }
    43}
    44
    45impl<'de> crate::serde::Deserialize<'de> for IPAddress {
    46    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    47        #[allow(non_camel_case_types)]
    48        enum Field {
    49            Key_api_version,
    50            Key_kind,
    51            Key_metadata,
    52            Key_spec,
    53            Other,
    54        }
    55
    56        impl<'de> crate::serde::Deserialize<'de> for Field {
    57            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    58                struct Visitor;
    59
    60                impl crate::serde::de::Visitor<'_> for Visitor {
    61                    type Value = Field;
    62
    63                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    64                        f.write_str("field identifier")
    65                    }
    66
    67                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    68                        Ok(match v {
    69                            "apiVersion" => Field::Key_api_version,
    70                            "kind" => Field::Key_kind,
    71                            "metadata" => Field::Key_metadata,
    72                            "spec" => Field::Key_spec,
    73                            _ => Field::Other,
    74                        })
    75                    }
    76                }
    77
    78                deserializer.deserialize_identifier(Visitor)
    79            }
    80        }
    81
    82        struct Visitor;
    83
    84        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    85            type Value = IPAddress;
    86
    87            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    88                f.write_str(<Self::Value as crate::Resource>::KIND)
    89            }
    90
    91            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    92                let mut value_metadata: Option<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
    93                let mut value_spec: Option<crate::api::networking::v1beta1::IPAddressSpec> = None;
    94
    95                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    96                    match key {
    97                        Field::Key_api_version => {
    98                            let value_api_version: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    99                            if value_api_version != <Self::Value as crate::Resource>::API_VERSION {
    100                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_api_version), &<Self::Value as crate::Resource>::API_VERSION));
    101                            }
    102                        },
    103                        Field::Key_kind => {
    104                            let value_kind: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    105                            if value_kind != <Self::Value as crate::Resource>::KIND {
    106                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_kind), &<Self::Value as crate::Resource>::KIND));
    107                            }
    108                        },
    109                        Field::Key_metadata => value_metadata = crate::serde::de::MapAccess::next_value(&mut map)?,
    110                        Field::Key_spec => value_spec = crate::serde::de::MapAccess::next_value(&mut map)?,
    111                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    112                    }
    113                }
    114
    115                Ok(IPAddress {
    116                    metadata: value_metadata.unwrap_or_default(),
    117                    spec: value_spec,
    118                })
    119            }
    120        }
    121
    122        deserializer.deserialize_struct(
    123            <Self as crate::Resource>::KIND,
    124            &[
    125                "apiVersion",
    126                "kind",
    127                "metadata",
    128                "spec",
    129            ],
    130            Visitor,
    131        )
    132    }
    133}
    134
    135impl crate::serde::Serialize for IPAddress {
    136    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    137        let mut state = serializer.serialize_struct(
    138            <Self as crate::Resource>::KIND,
    139            3 +
    140            self.spec.as_ref().map_or(0, |_| 1),
    141        )?;
    142        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as crate::Resource>::API_VERSION)?;
    143        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as crate::Resource>::KIND)?;
    144        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
    145        if let Some(value) = &self.spec {
    146            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "spec", value)?;
    147        }
    148        crate::serde::ser::SerializeStruct::end(state)
    149    }
    150}
    151
    152#[cfg(feature = "schemars")]
    153impl crate::schemars::JsonSchema for IPAddress {
    154    fn schema_name() -> std::borrow::Cow<'static, str> {
    155        "io.k8s.api.networking.v1beta1.IPAddress".into()
    156    }
    157
    158    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    159        crate::schemars::json_schema!({
    160            "description": "IPAddress represents a single IP of a single IP Family. The object is designed to be used by APIs that operate on IP addresses. The object is used by the Service core API for allocation of IP addresses. An IP address can be represented in different formats, to guarantee the uniqueness of the IP, the name of the object is the IP address in canonical format, four decimal digits separated by dots suppressing leading zeros for IPv4 and the representation defined by RFC 5952 for IPv6. Valid: 192.168.1.5 or 2001:db8::1 or 2001:db8:aaaa:bbbb:cccc:dddd:eeee:1 Invalid: 10.01.2.3 or 2001:db8:0:0:0::1",
    161            "type": "object",
    162            "properties": {
    163                "apiVersion": {
    164                    "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",
    165                    "type": "string",
    166                },
    167                "kind": {
    168                    "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",
    169                    "type": "string",
    170                },
    171                "metadata": ({
    172                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>();
    173                    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());
    174                    schema_obj
    175                }),
    176                "spec": ({
    177                    let mut schema_obj = __gen.subschema_for::<crate::api::networking::v1beta1::IPAddressSpec>();
    178                    schema_obj.ensure_object().insert("description".into(), "spec is the desired state of the IPAddress. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status".into());
    179                    schema_obj
    180                }),
    181            },
    182            "required": [
    183                "metadata",
    184            ],
    185        })
    186    }
    187}