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

    1// Generated from definition io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceSubresourceScale
    2
    3/// CustomResourceSubresourceScale defines how to serve the scale subresource for CustomResources.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct CustomResourceSubresourceScale {
    6    /// labelSelectorPath defines the JSON path inside of a custom resource that corresponds to Scale `status.selector`. Only JSON paths without the array notation are allowed. Must be a JSON Path under `.status` or `.spec`. Must be set to work with HorizontalPodAutoscaler. The field pointed by this JSON path must be a string field (not a complex selector struct) which contains a serialized label selector in string form. More info: https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions#scale-subresource If there is no value under the given path in the custom resource, the `status.selector` value in the `/scale` subresource will default to the empty string.
    7    pub label_selector_path: Option<std::string::String>,
    8
    9    /// specReplicasPath defines the JSON path inside of a custom resource that corresponds to Scale `spec.replicas`. Only JSON paths without the array notation are allowed. Must be a JSON Path under `.spec`. If there is no value under the given path in the custom resource, the `/scale` subresource will return an error on GET.
    10    pub spec_replicas_path: std::string::String,
    11
    12    /// statusReplicasPath defines the JSON path inside of a custom resource that corresponds to Scale `status.replicas`. Only JSON paths without the array notation are allowed. Must be a JSON Path under `.status`. If there is no value under the given path in the custom resource, the `status.replicas` value in the `/scale` subresource will default to 0.
    13    pub status_replicas_path: std::string::String,
    14}
    15
    16impl crate::DeepMerge for CustomResourceSubresourceScale {
    17    fn merge_from(&mut self, other: Self) {
    18        crate::DeepMerge::merge_from(&mut self.label_selector_path, other.label_selector_path);
    19        crate::DeepMerge::merge_from(&mut self.spec_replicas_path, other.spec_replicas_path);
    20        crate::DeepMerge::merge_from(&mut self.status_replicas_path, other.status_replicas_path);
    21    }
    22}
    23
    24impl<'de> crate::serde::Deserialize<'de> for CustomResourceSubresourceScale {
    25    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    26        #[allow(non_camel_case_types)]
    27        enum Field {
    28            Key_label_selector_path,
    29            Key_spec_replicas_path,
    30            Key_status_replicas_path,
    31            Other,
    32        }
    33
    34        impl<'de> crate::serde::Deserialize<'de> for Field {
    35            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    36                struct Visitor;
    37
    38                impl crate::serde::de::Visitor<'_> for Visitor {
    39                    type Value = Field;
    40
    41                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    42                        f.write_str("field identifier")
    43                    }
    44
    45                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    46                        Ok(match v {
    47                            "labelSelectorPath" => Field::Key_label_selector_path,
    48                            "specReplicasPath" => Field::Key_spec_replicas_path,
    49                            "statusReplicasPath" => Field::Key_status_replicas_path,
    50                            _ => Field::Other,
    51                        })
    52                    }
    53                }
    54
    55                deserializer.deserialize_identifier(Visitor)
    56            }
    57        }
    58
    59        struct Visitor;
    60
    61        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    62            type Value = CustomResourceSubresourceScale;
    63
    64            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    65                f.write_str("CustomResourceSubresourceScale")
    66            }
    67
    68            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    69                let mut value_label_selector_path: Option<std::string::String> = None;
    70                let mut value_spec_replicas_path: Option<std::string::String> = None;
    71                let mut value_status_replicas_path: Option<std::string::String> = None;
    72
    73                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    74                    match key {
    75                        Field::Key_label_selector_path => value_label_selector_path = crate::serde::de::MapAccess::next_value(&mut map)?,
    76                        Field::Key_spec_replicas_path => value_spec_replicas_path = crate::serde::de::MapAccess::next_value(&mut map)?,
    77                        Field::Key_status_replicas_path => value_status_replicas_path = crate::serde::de::MapAccess::next_value(&mut map)?,
    78                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    79                    }
    80                }
    81
    82                Ok(CustomResourceSubresourceScale {
    83                    label_selector_path: value_label_selector_path,
    84                    spec_replicas_path: value_spec_replicas_path.unwrap_or_default(),
    85                    status_replicas_path: value_status_replicas_path.unwrap_or_default(),
    86                })
    87            }
    88        }
    89
    90        deserializer.deserialize_struct(
    91            "CustomResourceSubresourceScale",
    92            &[
    93                "labelSelectorPath",
    94                "specReplicasPath",
    95                "statusReplicasPath",
    96            ],
    97            Visitor,
    98        )
    99    }
    100}
    101
    102impl crate::serde::Serialize for CustomResourceSubresourceScale {
    103    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    104        let mut state = serializer.serialize_struct(
    105            "CustomResourceSubresourceScale",
    106            2 +
    107            self.label_selector_path.as_ref().map_or(0, |_| 1),
    108        )?;
    109        if let Some(value) = &self.label_selector_path {
    110            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "labelSelectorPath", value)?;
    111        }
    112        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "specReplicasPath", &self.spec_replicas_path)?;
    113        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "statusReplicasPath", &self.status_replicas_path)?;
    114        crate::serde::ser::SerializeStruct::end(state)
    115    }
    116}
    117
    118#[cfg(feature = "schemars")]
    119impl crate::schemars::JsonSchema for CustomResourceSubresourceScale {
    120    fn schema_name() -> std::borrow::Cow<'static, str> {
    121        "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceSubresourceScale".into()
    122    }
    123
    124    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    125        crate::schemars::json_schema!({
    126            "description": "CustomResourceSubresourceScale defines how to serve the scale subresource for CustomResources.",
    127            "type": "object",
    128            "properties": {
    129                "labelSelectorPath": {
    130                    "description": "labelSelectorPath defines the JSON path inside of a custom resource that corresponds to Scale `status.selector`. Only JSON paths without the array notation are allowed. Must be a JSON Path under `.status` or `.spec`. Must be set to work with HorizontalPodAutoscaler. The field pointed by this JSON path must be a string field (not a complex selector struct) which contains a serialized label selector in string form. More info: https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions#scale-subresource If there is no value under the given path in the custom resource, the `status.selector` value in the `/scale` subresource will default to the empty string.",
    131                    "type": "string",
    132                },
    133                "specReplicasPath": {
    134                    "description": "specReplicasPath defines the JSON path inside of a custom resource that corresponds to Scale `spec.replicas`. Only JSON paths without the array notation are allowed. Must be a JSON Path under `.spec`. If there is no value under the given path in the custom resource, the `/scale` subresource will return an error on GET.",
    135                    "type": "string",
    136                },
    137                "statusReplicasPath": {
    138                    "description": "statusReplicasPath defines the JSON path inside of a custom resource that corresponds to Scale `status.replicas`. Only JSON paths without the array notation are allowed. Must be a JSON Path under `.status`. If there is no value under the given path in the custom resource, the `status.replicas` value in the `/scale` subresource will default to 0.",
    139                    "type": "string",
    140                },
    141            },
    142            "required": [
    143                "specReplicasPath",
    144                "statusReplicasPath",
    145            ],
    146        })
    147    }
    148}