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

    1// Generated from definition io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceDefinitionVersion
    2
    3/// CustomResourceDefinitionVersion describes a version for CRD.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct CustomResourceDefinitionVersion {
    6    /// additionalPrinterColumns specifies additional columns returned in Table output. See https://kubernetes.io/docs/reference/using-api/api-concepts/#receiving-resources-as-tables for details. If no columns are specified, a single column displaying the age of the custom resource is used.
    7    pub additional_printer_columns: Option<std::vec::Vec<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceColumnDefinition>>,
    8
    9    /// deprecated indicates this version of the custom resource API is deprecated. When set to true, API requests to this version receive a warning header in the server response. Defaults to false.
    10    pub deprecated: Option<bool>,
    11
    12    /// deprecationWarning overrides the default warning returned to API clients. May only be set when `deprecated` is true. The default warning indicates this version is deprecated and recommends use of the newest served version of equal or greater stability, if one exists.
    13    pub deprecation_warning: Option<std::string::String>,
    14
    15    /// name is the version name, e.g. “v1”, “v2beta1”, etc. The custom resources are served under this version at `/apis/\<group\>/\<version\>/...` if `served` is true.
    16    pub name: std::string::String,
    17
    18    /// schema describes the schema used for validation, pruning, and defaulting of this version of the custom resource.
    19    pub schema: Option<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceValidation>,
    20
    21    /// selectableFields specifies paths to fields that may be used as field selectors. A maximum of 8 selectable fields are allowed. See https://kubernetes.io/docs/concepts/overview/working-with-objects/field-selectors
    22    pub selectable_fields: Option<std::vec::Vec<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::SelectableField>>,
    23
    24    /// served is a flag enabling/disabling this version from being served via REST APIs
    25    pub served: bool,
    26
    27    /// storage indicates this version should be used when persisting custom resources to storage. There must be exactly one version with storage=true.
    28    pub storage: bool,
    29
    30    /// subresources specify what subresources this version of the defined custom resource have.
    31    pub subresources: Option<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceSubresources>,
    32}
    33
    34impl crate::DeepMerge for CustomResourceDefinitionVersion {
    35    fn merge_from(&mut self, other: Self) {
    36        crate::merge_strategies::list::atomic(&mut self.additional_printer_columns, other.additional_printer_columns);
    37        crate::DeepMerge::merge_from(&mut self.deprecated, other.deprecated);
    38        crate::DeepMerge::merge_from(&mut self.deprecation_warning, other.deprecation_warning);
    39        crate::DeepMerge::merge_from(&mut self.name, other.name);
    40        crate::DeepMerge::merge_from(&mut self.schema, other.schema);
    41        crate::merge_strategies::list::atomic(&mut self.selectable_fields, other.selectable_fields);
    42        crate::DeepMerge::merge_from(&mut self.served, other.served);
    43        crate::DeepMerge::merge_from(&mut self.storage, other.storage);
    44        crate::DeepMerge::merge_from(&mut self.subresources, other.subresources);
    45    }
    46}
    47
    48impl<'de> crate::serde::Deserialize<'de> for CustomResourceDefinitionVersion {
    49    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    50        #[allow(non_camel_case_types)]
    51        enum Field {
    52            Key_additional_printer_columns,
    53            Key_deprecated,
    54            Key_deprecation_warning,
    55            Key_name,
    56            Key_schema,
    57            Key_selectable_fields,
    58            Key_served,
    59            Key_storage,
    60            Key_subresources,
    61            Other,
    62        }
    63
    64        impl<'de> crate::serde::Deserialize<'de> for Field {
    65            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    66                struct Visitor;
    67
    68                impl crate::serde::de::Visitor<'_> for Visitor {
    69                    type Value = Field;
    70
    71                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    72                        f.write_str("field identifier")
    73                    }
    74
    75                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    76                        Ok(match v {
    77                            "additionalPrinterColumns" => Field::Key_additional_printer_columns,
    78                            "deprecated" => Field::Key_deprecated,
    79                            "deprecationWarning" => Field::Key_deprecation_warning,
    80                            "name" => Field::Key_name,
    81                            "schema" => Field::Key_schema,
    82                            "selectableFields" => Field::Key_selectable_fields,
    83                            "served" => Field::Key_served,
    84                            "storage" => Field::Key_storage,
    85                            "subresources" => Field::Key_subresources,
    86                            _ => Field::Other,
    87                        })
    88                    }
    89                }
    90
    91                deserializer.deserialize_identifier(Visitor)
    92            }
    93        }
    94
    95        struct Visitor;
    96
    97        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    98            type Value = CustomResourceDefinitionVersion;
    99
    100            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    101                f.write_str("CustomResourceDefinitionVersion")
    102            }
    103
    104            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    105                let mut value_additional_printer_columns: Option<std::vec::Vec<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceColumnDefinition>> = None;
    106                let mut value_deprecated: Option<bool> = None;
    107                let mut value_deprecation_warning: Option<std::string::String> = None;
    108                let mut value_name: Option<std::string::String> = None;
    109                let mut value_schema: Option<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceValidation> = None;
    110                let mut value_selectable_fields: Option<std::vec::Vec<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::SelectableField>> = None;
    111                let mut value_served: Option<bool> = None;
    112                let mut value_storage: Option<bool> = None;
    113                let mut value_subresources: Option<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceSubresources> = None;
    114
    115                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    116                    match key {
    117                        Field::Key_additional_printer_columns => value_additional_printer_columns = crate::serde::de::MapAccess::next_value(&mut map)?,
    118                        Field::Key_deprecated => value_deprecated = crate::serde::de::MapAccess::next_value(&mut map)?,
    119                        Field::Key_deprecation_warning => value_deprecation_warning = crate::serde::de::MapAccess::next_value(&mut map)?,
    120                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
    121                        Field::Key_schema => value_schema = crate::serde::de::MapAccess::next_value(&mut map)?,
    122                        Field::Key_selectable_fields => value_selectable_fields = crate::serde::de::MapAccess::next_value(&mut map)?,
    123                        Field::Key_served => value_served = crate::serde::de::MapAccess::next_value(&mut map)?,
    124                        Field::Key_storage => value_storage = crate::serde::de::MapAccess::next_value(&mut map)?,
    125                        Field::Key_subresources => value_subresources = crate::serde::de::MapAccess::next_value(&mut map)?,
    126                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    127                    }
    128                }
    129
    130                Ok(CustomResourceDefinitionVersion {
    131                    additional_printer_columns: value_additional_printer_columns,
    132                    deprecated: value_deprecated,
    133                    deprecation_warning: value_deprecation_warning,
    134                    name: value_name.unwrap_or_default(),
    135                    schema: value_schema,
    136                    selectable_fields: value_selectable_fields,
    137                    served: value_served.unwrap_or_default(),
    138                    storage: value_storage.unwrap_or_default(),
    139                    subresources: value_subresources,
    140                })
    141            }
    142        }
    143
    144        deserializer.deserialize_struct(
    145            "CustomResourceDefinitionVersion",
    146            &[
    147                "additionalPrinterColumns",
    148                "deprecated",
    149                "deprecationWarning",
    150                "name",
    151                "schema",
    152                "selectableFields",
    153                "served",
    154                "storage",
    155                "subresources",
    156            ],
    157            Visitor,
    158        )
    159    }
    160}
    161
    162impl crate::serde::Serialize for CustomResourceDefinitionVersion {
    163    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    164        let mut state = serializer.serialize_struct(
    165            "CustomResourceDefinitionVersion",
    166            3 +
    167            self.additional_printer_columns.as_ref().map_or(0, |_| 1) +
    168            self.deprecated.as_ref().map_or(0, |_| 1) +
    169            self.deprecation_warning.as_ref().map_or(0, |_| 1) +
    170            self.schema.as_ref().map_or(0, |_| 1) +
    171            self.selectable_fields.as_ref().map_or(0, |_| 1) +
    172            self.subresources.as_ref().map_or(0, |_| 1),
    173        )?;
    174        if let Some(value) = &self.additional_printer_columns {
    175            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "additionalPrinterColumns", value)?;
    176        }
    177        if let Some(value) = &self.deprecated {
    178            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "deprecated", value)?;
    179        }
    180        if let Some(value) = &self.deprecation_warning {
    181            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "deprecationWarning", value)?;
    182        }
    183        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
    184        if let Some(value) = &self.schema {
    185            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "schema", value)?;
    186        }
    187        if let Some(value) = &self.selectable_fields {
    188            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "selectableFields", value)?;
    189        }
    190        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "served", &self.served)?;
    191        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "storage", &self.storage)?;
    192        if let Some(value) = &self.subresources {
    193            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "subresources", value)?;
    194        }
    195        crate::serde::ser::SerializeStruct::end(state)
    196    }
    197}
    198
    199#[cfg(feature = "schemars")]
    200impl crate::schemars::JsonSchema for CustomResourceDefinitionVersion {
    201    fn schema_name() -> std::borrow::Cow<'static, str> {
    202        "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceDefinitionVersion".into()
    203    }
    204
    205    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    206        crate::schemars::json_schema!({
    207            "description": "CustomResourceDefinitionVersion describes a version for CRD.",
    208            "type": "object",
    209            "properties": {
    210                "additionalPrinterColumns": {
    211                    "description": "additionalPrinterColumns specifies additional columns returned in Table output. See https://kubernetes.io/docs/reference/using-api/api-concepts/#receiving-resources-as-tables for details. If no columns are specified, a single column displaying the age of the custom resource is used.",
    212                    "type": "array",
    213                    "items": (__gen.subschema_for::<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceColumnDefinition>()),
    214                },
    215                "deprecated": {
    216                    "description": "deprecated indicates this version of the custom resource API is deprecated. When set to true, API requests to this version receive a warning header in the server response. Defaults to false.",
    217                    "type": "boolean",
    218                },
    219                "deprecationWarning": {
    220                    "description": "deprecationWarning overrides the default warning returned to API clients. May only be set when `deprecated` is true. The default warning indicates this version is deprecated and recommends use of the newest served version of equal or greater stability, if one exists.",
    221                    "type": "string",
    222                },
    223                "name": {
    224                    "description": "name is the version name, e.g. “v1”, “v2beta1”, etc. The custom resources are served under this version at `/apis/<group>/<version>/...` if `served` is true.",
    225                    "type": "string",
    226                },
    227                "schema": ({
    228                    let mut schema_obj = __gen.subschema_for::<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceValidation>();
    229                    schema_obj.ensure_object().insert("description".into(), "schema describes the schema used for validation, pruning, and defaulting of this version of the custom resource.".into());
    230                    schema_obj
    231                }),
    232                "selectableFields": {
    233                    "description": "selectableFields specifies paths to fields that may be used as field selectors. A maximum of 8 selectable fields are allowed. See https://kubernetes.io/docs/concepts/overview/working-with-objects/field-selectors",
    234                    "type": "array",
    235                    "items": (__gen.subschema_for::<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::SelectableField>()),
    236                },
    237                "served": {
    238                    "description": "served is a flag enabling/disabling this version from being served via REST APIs",
    239                    "type": "boolean",
    240                },
    241                "storage": {
    242                    "description": "storage indicates this version should be used when persisting custom resources to storage. There must be exactly one version with storage=true.",
    243                    "type": "boolean",
    244                },
    245                "subresources": ({
    246                    let mut schema_obj = __gen.subschema_for::<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceSubresources>();
    247                    schema_obj.ensure_object().insert("description".into(), "subresources specify what subresources this version of the defined custom resource have.".into());
    248                    schema_obj
    249                }),
    250            },
    251            "required": [
    252                "name",
    253                "served",
    254                "storage",
    255            ],
    256        })
    257    }
    258}