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

    1// Generated from definition io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceDefinitionSpec
    2
    3/// CustomResourceDefinitionSpec describes how a user wants their resource to appear
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct CustomResourceDefinitionSpec {
    6    /// conversion defines conversion settings for the CRD.
    7    pub conversion: Option<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceConversion>,
    8
    9    /// group is the API group of the defined custom resource. The custom resources are served under `/apis/\<group\>/...`. Must match the name of the CustomResourceDefinition (in the form `\<names.plural\>.\<group\>`).
    10    pub group: std::string::String,
    11
    12    /// names specify the resource and kind names for the custom resource.
    13    pub names: crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinitionNames,
    14
    15    /// preserveUnknownFields indicates that object fields which are not specified in the OpenAPI schema should be preserved when persisting to storage. apiVersion, kind, metadata and known fields inside metadata are always preserved. This field is deprecated in favor of setting `x-preserve-unknown-fields` to true in `spec.versions\[*\].schema.openAPIV3Schema`. See https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#field-pruning for details.
    16    pub preserve_unknown_fields: Option<bool>,
    17
    18    /// scope indicates whether the defined custom resource is cluster- or namespace-scoped. Allowed values are `Cluster` and `Namespaced`.
    19    pub scope: std::string::String,
    20
    21    /// versions is the list of all API versions of the defined custom resource. Version names are used to compute the order in which served versions are listed in API discovery. If the version string is "kube-like", it will sort above non "kube-like" version strings, which are ordered lexicographically. "Kube-like" versions start with a "v", then are followed by a number (the major version), then optionally the string "alpha" or "beta" and another number (the minor version). These are sorted first by GA \> beta \> alpha (where GA is a version with no suffix such as beta or alpha), and then by comparing major version, then minor version. An example sorted list of versions: v10, v2, v1, v11beta2, v10beta3, v3beta1, v12alpha1, v11alpha2, foo1, foo10.
    22    pub versions: std::vec::Vec<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinitionVersion>,
    23}
    24
    25impl crate::DeepMerge for CustomResourceDefinitionSpec {
    26    fn merge_from(&mut self, other: Self) {
    27        crate::DeepMerge::merge_from(&mut self.conversion, other.conversion);
    28        crate::DeepMerge::merge_from(&mut self.group, other.group);
    29        crate::DeepMerge::merge_from(&mut self.names, other.names);
    30        crate::DeepMerge::merge_from(&mut self.preserve_unknown_fields, other.preserve_unknown_fields);
    31        crate::DeepMerge::merge_from(&mut self.scope, other.scope);
    32        crate::merge_strategies::list::atomic(&mut self.versions, other.versions);
    33    }
    34}
    35
    36impl<'de> crate::serde::Deserialize<'de> for CustomResourceDefinitionSpec {
    37    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    38        #[allow(non_camel_case_types)]
    39        enum Field {
    40            Key_conversion,
    41            Key_group,
    42            Key_names,
    43            Key_preserve_unknown_fields,
    44            Key_scope,
    45            Key_versions,
    46            Other,
    47        }
    48
    49        impl<'de> crate::serde::Deserialize<'de> for Field {
    50            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    51                struct Visitor;
    52
    53                impl crate::serde::de::Visitor<'_> for Visitor {
    54                    type Value = Field;
    55
    56                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    57                        f.write_str("field identifier")
    58                    }
    59
    60                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    61                        Ok(match v {
    62                            "conversion" => Field::Key_conversion,
    63                            "group" => Field::Key_group,
    64                            "names" => Field::Key_names,
    65                            "preserveUnknownFields" => Field::Key_preserve_unknown_fields,
    66                            "scope" => Field::Key_scope,
    67                            "versions" => Field::Key_versions,
    68                            _ => Field::Other,
    69                        })
    70                    }
    71                }
    72
    73                deserializer.deserialize_identifier(Visitor)
    74            }
    75        }
    76
    77        struct Visitor;
    78
    79        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    80            type Value = CustomResourceDefinitionSpec;
    81
    82            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    83                f.write_str("CustomResourceDefinitionSpec")
    84            }
    85
    86            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    87                let mut value_conversion: Option<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceConversion> = None;
    88                let mut value_group: Option<std::string::String> = None;
    89                let mut value_names: Option<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinitionNames> = None;
    90                let mut value_preserve_unknown_fields: Option<bool> = None;
    91                let mut value_scope: Option<std::string::String> = None;
    92                let mut value_versions: Option<std::vec::Vec<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinitionVersion>> = None;
    93
    94                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    95                    match key {
    96                        Field::Key_conversion => value_conversion = crate::serde::de::MapAccess::next_value(&mut map)?,
    97                        Field::Key_group => value_group = crate::serde::de::MapAccess::next_value(&mut map)?,
    98                        Field::Key_names => value_names = crate::serde::de::MapAccess::next_value(&mut map)?,
    99                        Field::Key_preserve_unknown_fields => value_preserve_unknown_fields = crate::serde::de::MapAccess::next_value(&mut map)?,
    100                        Field::Key_scope => value_scope = crate::serde::de::MapAccess::next_value(&mut map)?,
    101                        Field::Key_versions => value_versions = crate::serde::de::MapAccess::next_value(&mut map)?,
    102                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    103                    }
    104                }
    105
    106                Ok(CustomResourceDefinitionSpec {
    107                    conversion: value_conversion,
    108                    group: value_group.unwrap_or_default(),
    109                    names: value_names.unwrap_or_default(),
    110                    preserve_unknown_fields: value_preserve_unknown_fields,
    111                    scope: value_scope.unwrap_or_default(),
    112                    versions: value_versions.unwrap_or_default(),
    113                })
    114            }
    115        }
    116
    117        deserializer.deserialize_struct(
    118            "CustomResourceDefinitionSpec",
    119            &[
    120                "conversion",
    121                "group",
    122                "names",
    123                "preserveUnknownFields",
    124                "scope",
    125                "versions",
    126            ],
    127            Visitor,
    128        )
    129    }
    130}
    131
    132impl crate::serde::Serialize for CustomResourceDefinitionSpec {
    133    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    134        let mut state = serializer.serialize_struct(
    135            "CustomResourceDefinitionSpec",
    136            4 +
    137            self.conversion.as_ref().map_or(0, |_| 1) +
    138            self.preserve_unknown_fields.as_ref().map_or(0, |_| 1),
    139        )?;
    140        if let Some(value) = &self.conversion {
    141            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "conversion", value)?;
    142        }
    143        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "group", &self.group)?;
    144        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "names", &self.names)?;
    145        if let Some(value) = &self.preserve_unknown_fields {
    146            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "preserveUnknownFields", value)?;
    147        }
    148        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "scope", &self.scope)?;
    149        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "versions", &self.versions)?;
    150        crate::serde::ser::SerializeStruct::end(state)
    151    }
    152}
    153
    154#[cfg(feature = "schemars")]
    155impl crate::schemars::JsonSchema for CustomResourceDefinitionSpec {
    156    fn schema_name() -> std::borrow::Cow<'static, str> {
    157        "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceDefinitionSpec".into()
    158    }
    159
    160    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    161        crate::schemars::json_schema!({
    162            "description": "CustomResourceDefinitionSpec describes how a user wants their resource to appear",
    163            "type": "object",
    164            "properties": {
    165                "conversion": ({
    166                    let mut schema_obj = __gen.subschema_for::<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceConversion>();
    167                    schema_obj.ensure_object().insert("description".into(), "conversion defines conversion settings for the CRD.".into());
    168                    schema_obj
    169                }),
    170                "group": {
    171                    "description": "group is the API group of the defined custom resource. The custom resources are served under `/apis/<group>/...`. Must match the name of the CustomResourceDefinition (in the form `<names.plural>.<group>`).",
    172                    "type": "string",
    173                },
    174                "names": ({
    175                    let mut schema_obj = __gen.subschema_for::<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinitionNames>();
    176                    schema_obj.ensure_object().insert("description".into(), "names specify the resource and kind names for the custom resource.".into());
    177                    schema_obj
    178                }),
    179                "preserveUnknownFields": {
    180                    "description": "preserveUnknownFields indicates that object fields which are not specified in the OpenAPI schema should be preserved when persisting to storage. apiVersion, kind, metadata and known fields inside metadata are always preserved. This field is deprecated in favor of setting `x-preserve-unknown-fields` to true in `spec.versions[*].schema.openAPIV3Schema`. See https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#field-pruning for details.",
    181                    "type": "boolean",
    182                },
    183                "scope": {
    184                    "description": "scope indicates whether the defined custom resource is cluster- or namespace-scoped. Allowed values are `Cluster` and `Namespaced`.",
    185                    "type": "string",
    186                },
    187                "versions": {
    188                    "description": "versions is the list of all API versions of the defined custom resource. Version names are used to compute the order in which served versions are listed in API discovery. If the version string is \"kube-like\", it will sort above non \"kube-like\" version strings, which are ordered lexicographically. \"Kube-like\" versions start with a \"v\", then are followed by a number (the major version), then optionally the string \"alpha\" or \"beta\" and another number (the minor version). These are sorted first by GA > beta > alpha (where GA is a version with no suffix such as beta or alpha), and then by comparing major version, then minor version. An example sorted list of versions: v10, v2, v1, v11beta2, v10beta3, v3beta1, v12alpha1, v11alpha2, foo1, foo10.",
    189                    "type": "array",
    190                    "items": (__gen.subschema_for::<crate::apiextensions_apiserver::pkg::apis::apiextensions::v1::CustomResourceDefinitionVersion>()),
    191                },
    192            },
    193            "required": [
    194                "group",
    195                "names",
    196                "scope",
    197                "versions",
    198            ],
    199        })
    200    }
    201}