#
k8s_openapi/v1_35/apiextensions_apiserver/pkg/apis/apiextensions/v1/
custom_resource_conversion.rs

    1// Generated from definition io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceConversion
    2
    3/// CustomResourceConversion describes how to convert different versions of a CR.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct CustomResourceConversion {
    6    /// strategy specifies how custom resources are converted between versions. Allowed values are: - `"None"`: The converter only change the apiVersion and would not touch any other field in the custom resource. - `"Webhook"`: API Server will call to an external webhook to do the conversion. Additional information
    7    ///   is needed for this option. This requires spec.preserveUnknownFields to be false, and spec.conversion.webhook to be set.
    8    pub strategy: std::string::String,
    9
    10    /// webhook describes how to call the conversion webhook. Required when `strategy` is set to `"Webhook"`.
    11    pub webhook: Option<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::WebhookConversion>,
    12}
    13
    14impl crate::DeepMerge for CustomResourceConversion {
    15    fn merge_from(&mut self, other: Self) {
    16        crate::DeepMerge::merge_from(&mut self.strategy, other.strategy);
    17        crate::DeepMerge::merge_from(&mut self.webhook, other.webhook);
    18    }
    19}
    20
    21impl<'de> crate::serde::Deserialize<'de> for CustomResourceConversion {
    22    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    23        #[allow(non_camel_case_types)]
    24        enum Field {
    25            Key_strategy,
    26            Key_webhook,
    27            Other,
    28        }
    29
    30        impl<'de> crate::serde::Deserialize<'de> for Field {
    31            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    32                struct Visitor;
    33
    34                impl crate::serde::de::Visitor<'_> for Visitor {
    35                    type Value = Field;
    36
    37                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    38                        f.write_str("field identifier")
    39                    }
    40
    41                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    42                        Ok(match v {
    43                            "strategy" => Field::Key_strategy,
    44                            "webhook" => Field::Key_webhook,
    45                            _ => Field::Other,
    46                        })
    47                    }
    48                }
    49
    50                deserializer.deserialize_identifier(Visitor)
    51            }
    52        }
    53
    54        struct Visitor;
    55
    56        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    57            type Value = CustomResourceConversion;
    58
    59            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    60                f.write_str("CustomResourceConversion")
    61            }
    62
    63            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    64                let mut value_strategy: Option<std::string::String> = None;
    65                let mut value_webhook: Option<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::WebhookConversion> = None;
    66
    67                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    68                    match key {
    69                        Field::Key_strategy => value_strategy = crate::serde::de::MapAccess::next_value(&mut map)?,
    70                        Field::Key_webhook => value_webhook = crate::serde::de::MapAccess::next_value(&mut map)?,
    71                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    72                    }
    73                }
    74
    75                Ok(CustomResourceConversion {
    76                    strategy: value_strategy.unwrap_or_default(),
    77                    webhook: value_webhook,
    78                })
    79            }
    80        }
    81
    82        deserializer.deserialize_struct(
    83            "CustomResourceConversion",
    84            &[
    85                "strategy",
    86                "webhook",
    87            ],
    88            Visitor,
    89        )
    90    }
    91}
    92
    93impl crate::serde::Serialize for CustomResourceConversion {
    94    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    95        let mut state = serializer.serialize_struct(
    96            "CustomResourceConversion",
    97            1 +
    98            self.webhook.as_ref().map_or(0, |_| 1),
    99        )?;
    100        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "strategy", &self.strategy)?;
    101        if let Some(value) = &self.webhook {
    102            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "webhook", value)?;
    103        }
    104        crate::serde::ser::SerializeStruct::end(state)
    105    }
    106}
    107
    108#[cfg(feature = "schemars")]
    109impl crate::schemars::JsonSchema for CustomResourceConversion {
    110    fn schema_name() -> std::borrow::Cow<'static, str> {
    111        "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceConversion".into()
    112    }
    113
    114    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    115        crate::schemars::json_schema!({
    116            "description": "CustomResourceConversion describes how to convert different versions of a CR.",
    117            "type": "object",
    118            "properties": {
    119                "strategy": {
    120                    "description": "strategy specifies how custom resources are converted between versions. Allowed values are: - `\"None\"`: The converter only change the apiVersion and would not touch any other field in the custom resource. - `\"Webhook\"`: API Server will call to an external webhook to do the conversion. Additional information\n  is needed for this option. This requires spec.preserveUnknownFields to be false, and spec.conversion.webhook to be set.",
    121                    "type": "string",
    122                },
    123                "webhook": ({
    124                    let mut schema_obj = __gen.subschema_for::<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::WebhookConversion>();
    125                    schema_obj.ensure_object().insert("description".into(), "webhook describes how to call the conversion webhook. Required when `strategy` is set to `\"Webhook\"`.".into());
    126                    schema_obj
    127                }),
    128            },
    129            "required": [
    130                "strategy",
    131            ],
    132        })
    133    }
    134}