#
k8s_openapi/v1_35/api/core/v1/
replication_controller_spec.rs

    1// Generated from definition io.k8s.api.core.v1.ReplicationControllerSpec
    2
    3/// ReplicationControllerSpec is the specification of a replication controller.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct ReplicationControllerSpec {
    6    /// Minimum number of seconds for which a newly created pod should be ready without any of its container crashing, for it to be considered available. Defaults to 0 (pod will be considered available as soon as it is ready)
    7    pub min_ready_seconds: Option<i32>,
    8
    9    /// Replicas is the number of desired replicas. This is a pointer to distinguish between explicit zero and unspecified. Defaults to 1. More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#what-is-a-replicationcontroller
    10    pub replicas: Option<i32>,
    11
    12    /// Selector is a label query over pods that should match the Replicas count. If Selector is empty, it is defaulted to the labels present on the Pod template. Label keys and values that must match in order to be controlled by this replication controller, if empty defaulted to labels on Pod template. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors
    13    pub selector: Option<std::collections::BTreeMap<std::string::String, std::string::String>>,
    14
    15    /// Template is the object that describes the pod that will be created if insufficient replicas are detected. This takes precedence over a TemplateRef. The only allowed template.spec.restartPolicy value is "Always". More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#pod-template
    16    pub template: Option<crate::api::core::v1::PodTemplateSpec>,
    17}
    18
    19impl crate::DeepMerge for ReplicationControllerSpec {
    20    fn merge_from(&mut self, other: Self) {
    21        crate::DeepMerge::merge_from(&mut self.min_ready_seconds, other.min_ready_seconds);
    22        crate::DeepMerge::merge_from(&mut self.replicas, other.replicas);
    23        crate::merge_strategies::map::atomic(&mut self.selector, other.selector);
    24        crate::DeepMerge::merge_from(&mut self.template, other.template);
    25    }
    26}
    27
    28impl<'de> crate::serde::Deserialize<'de> for ReplicationControllerSpec {
    29    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    30        #[allow(non_camel_case_types)]
    31        enum Field {
    32            Key_min_ready_seconds,
    33            Key_replicas,
    34            Key_selector,
    35            Key_template,
    36            Other,
    37        }
    38
    39        impl<'de> crate::serde::Deserialize<'de> for Field {
    40            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    41                struct Visitor;
    42
    43                impl crate::serde::de::Visitor<'_> for Visitor {
    44                    type Value = Field;
    45
    46                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    47                        f.write_str("field identifier")
    48                    }
    49
    50                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    51                        Ok(match v {
    52                            "minReadySeconds" => Field::Key_min_ready_seconds,
    53                            "replicas" => Field::Key_replicas,
    54                            "selector" => Field::Key_selector,
    55                            "template" => Field::Key_template,
    56                            _ => Field::Other,
    57                        })
    58                    }
    59                }
    60
    61                deserializer.deserialize_identifier(Visitor)
    62            }
    63        }
    64
    65        struct Visitor;
    66
    67        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    68            type Value = ReplicationControllerSpec;
    69
    70            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    71                f.write_str("ReplicationControllerSpec")
    72            }
    73
    74            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    75                let mut value_min_ready_seconds: Option<i32> = None;
    76                let mut value_replicas: Option<i32> = None;
    77                let mut value_selector: Option<std::collections::BTreeMap<std::string::String, std::string::String>> = None;
    78                let mut value_template: Option<crate::api::core::v1::PodTemplateSpec> = None;
    79
    80                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    81                    match key {
    82                        Field::Key_min_ready_seconds => value_min_ready_seconds = crate::serde::de::MapAccess::next_value(&mut map)?,
    83                        Field::Key_replicas => value_replicas = crate::serde::de::MapAccess::next_value(&mut map)?,
    84                        Field::Key_selector => value_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
    85                        Field::Key_template => value_template = crate::serde::de::MapAccess::next_value(&mut map)?,
    86                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    87                    }
    88                }
    89
    90                Ok(ReplicationControllerSpec {
    91                    min_ready_seconds: value_min_ready_seconds,
    92                    replicas: value_replicas,
    93                    selector: value_selector,
    94                    template: value_template,
    95                })
    96            }
    97        }
    98
    99        deserializer.deserialize_struct(
    100            "ReplicationControllerSpec",
    101            &[
    102                "minReadySeconds",
    103                "replicas",
    104                "selector",
    105                "template",
    106            ],
    107            Visitor,
    108        )
    109    }
    110}
    111
    112impl crate::serde::Serialize for ReplicationControllerSpec {
    113    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    114        let mut state = serializer.serialize_struct(
    115            "ReplicationControllerSpec",
    116            self.min_ready_seconds.as_ref().map_or(0, |_| 1) +
    117            self.replicas.as_ref().map_or(0, |_| 1) +
    118            self.selector.as_ref().map_or(0, |_| 1) +
    119            self.template.as_ref().map_or(0, |_| 1),
    120        )?;
    121        if let Some(value) = &self.min_ready_seconds {
    122            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "minReadySeconds", value)?;
    123        }
    124        if let Some(value) = &self.replicas {
    125            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "replicas", value)?;
    126        }
    127        if let Some(value) = &self.selector {
    128            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "selector", value)?;
    129        }
    130        if let Some(value) = &self.template {
    131            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "template", value)?;
    132        }
    133        crate::serde::ser::SerializeStruct::end(state)
    134    }
    135}
    136
    137#[cfg(feature = "schemars")]
    138impl crate::schemars::JsonSchema for ReplicationControllerSpec {
    139    fn schema_name() -> std::borrow::Cow<'static, str> {
    140        "io.k8s.api.core.v1.ReplicationControllerSpec".into()
    141    }
    142
    143    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    144        crate::schemars::json_schema!({
    145            "description": "ReplicationControllerSpec is the specification of a replication controller.",
    146            "type": "object",
    147            "properties": {
    148                "minReadySeconds": {
    149                    "description": "Minimum number of seconds for which a newly created pod should be ready without any of its container crashing, for it to be considered available. Defaults to 0 (pod will be considered available as soon as it is ready)",
    150                    "type": "integer",
    151                    "format": "int32",
    152                },
    153                "replicas": {
    154                    "description": "Replicas is the number of desired replicas. This is a pointer to distinguish between explicit zero and unspecified. Defaults to 1. More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#what-is-a-replicationcontroller",
    155                    "type": "integer",
    156                    "format": "int32",
    157                },
    158                "selector": {
    159                    "description": "Selector is a label query over pods that should match the Replicas count. If Selector is empty, it is defaulted to the labels present on the Pod template. Label keys and values that must match in order to be controlled by this replication controller, if empty defaulted to labels on Pod template. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors",
    160                    "type": "object",
    161                    "additionalProperties": {
    162                        "type": "string",
    163                    },
    164                },
    165                "template": ({
    166                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::PodTemplateSpec>();
    167                    schema_obj.ensure_object().insert("description".into(), "Template is the object that describes the pod that will be created if insufficient replicas are detected. This takes precedence over a TemplateRef. The only allowed template.spec.restartPolicy value is \"Always\". More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#pod-template".into());
    168                    schema_obj
    169                }),
    170            },
    171        })
    172    }
    173}