Skip to main content

k8s_openapi/v1_36/api/autoscaling/v2/
container_resource_metric_source.rs

1// Generated from definition io.k8s.api.autoscaling.v2.ContainerResourceMetricSource
2
3/// ContainerResourceMetricSource indicates how to scale on a resource metric known to Kubernetes, as specified in requests and limits, describing each pod in the current scale target (e.g. CPU or memory).  The values will be averaged together before being compared to the target.  Such metrics are built in to Kubernetes, and have special scaling options on top of those available to normal per-pod metrics using the "pods" source.  Only one "target" type should be set.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ContainerResourceMetricSource {
6    /// container is the name of the container in the pods of the scaling target
7    pub container: std::string::String,
8
9    /// name is the name of the resource in question.
10    pub name: std::string::String,
11
12    /// target specifies the target value for the given metric
13    pub target: crate::api::autoscaling::v2::MetricTarget,
14}
15
16impl crate::DeepMerge for ContainerResourceMetricSource {
17    fn merge_from(&mut self, other: Self) {
18        crate::DeepMerge::merge_from(&mut self.container, other.container);
19        crate::DeepMerge::merge_from(&mut self.name, other.name);
20        crate::DeepMerge::merge_from(&mut self.target, other.target);
21    }
22}
23
24impl<'de> crate::serde::Deserialize<'de> for ContainerResourceMetricSource {
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_container,
29            Key_name,
30            Key_target,
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                            "container" => Field::Key_container,
48                            "name" => Field::Key_name,
49                            "target" => Field::Key_target,
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 = ContainerResourceMetricSource;
63
64            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
65                f.write_str("ContainerResourceMetricSource")
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_container: Option<std::string::String> = None;
70                let mut value_name: Option<std::string::String> = None;
71                let mut value_target: Option<crate::api::autoscaling::v2::MetricTarget> = None;
72
73                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
74                    match key {
75                        Field::Key_container => value_container = crate::serde::de::MapAccess::next_value(&mut map)?,
76                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
77                        Field::Key_target => value_target = 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(ContainerResourceMetricSource {
83                    container: value_container.unwrap_or_default(),
84                    name: value_name.unwrap_or_default(),
85                    target: value_target.unwrap_or_default(),
86                })
87            }
88        }
89
90        deserializer.deserialize_struct(
91            "ContainerResourceMetricSource",
92            &[
93                "container",
94                "name",
95                "target",
96            ],
97            Visitor,
98        )
99    }
100}
101
102impl crate::serde::Serialize for ContainerResourceMetricSource {
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            "ContainerResourceMetricSource",
106            3,
107        )?;
108        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "container", &self.container)?;
109        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
110        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "target", &self.target)?;
111        crate::serde::ser::SerializeStruct::end(state)
112    }
113}
114
115#[cfg(feature = "schemars")]
116impl crate::schemars::JsonSchema for ContainerResourceMetricSource {
117    fn schema_name() -> std::borrow::Cow<'static, str> {
118        "io.k8s.api.autoscaling.v2.ContainerResourceMetricSource".into()
119    }
120
121    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
122        crate::schemars::json_schema!({
123            "description": "ContainerResourceMetricSource indicates how to scale on a resource metric known to Kubernetes, as specified in requests and limits, describing each pod in the current scale target (e.g. CPU or memory).  The values will be averaged together before being compared to the target.  Such metrics are built in to Kubernetes, and have special scaling options on top of those available to normal per-pod metrics using the \"pods\" source.  Only one \"target\" type should be set.",
124            "type": "object",
125            "properties": {
126                "container": {
127                    "description": "container is the name of the container in the pods of the scaling target",
128                    "type": "string",
129                },
130                "name": {
131                    "description": "name is the name of the resource in question.",
132                    "type": "string",
133                },
134                "target": ({
135                    let mut schema_obj = __gen.subschema_for::<crate::api::autoscaling::v2::MetricTarget>();
136                    schema_obj.ensure_object().insert("description".into(), "target specifies the target value for the given metric".into());
137                    schema_obj
138                }),
139            },
140            "required": [
141                "container",
142                "name",
143                "target",
144            ],
145        })
146    }
147}
148
149#[cfg(feature = "schemars08")]
150impl crate::schemars08::JsonSchema for ContainerResourceMetricSource {
151    fn schema_name() -> std::string::String {
152        "io.k8s.api.autoscaling.v2.ContainerResourceMetricSource".into()
153    }
154
155    fn json_schema(__gen: &mut crate::schemars08::gen::SchemaGenerator) -> crate::schemars08::schema::Schema {
156        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
157            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
158                description: Some("ContainerResourceMetricSource indicates how to scale on a resource metric known to Kubernetes, as specified in requests and limits, describing each pod in the current scale target (e.g. CPU or memory).  The values will be averaged together before being compared to the target.  Such metrics are built in to Kubernetes, and have special scaling options on top of those available to normal per-pod metrics using the \"pods\" source.  Only one \"target\" type should be set.".into()),
159                ..Default::default()
160            })),
161            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Object))),
162            object: Some(std::boxed::Box::new(crate::schemars08::schema::ObjectValidation {
163                properties: [
164                    (
165                        "container".into(),
166                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
167                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
168                                description: Some("container is the name of the container in the pods of the scaling target".into()),
169                                ..Default::default()
170                            })),
171                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
172                            ..Default::default()
173                        }),
174                    ),
175                    (
176                        "name".into(),
177                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
178                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
179                                description: Some("name is the name of the resource in question.".into()),
180                                ..Default::default()
181                            })),
182                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
183                            ..Default::default()
184                        }),
185                    ),
186                    (
187                        "target".into(),
188                        {
189                            let mut schema_obj = __gen.subschema_for::<crate::api::autoscaling::v2::MetricTarget>().into_object();
190                            schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
191                                description: Some("target specifies the target value for the given metric".into()),
192                                ..Default::default()
193                            }));
194                            crate::schemars08::schema::Schema::Object(schema_obj)
195                        },
196                    ),
197                ].into(),
198                required: [
199                    "container".into(),
200                    "name".into(),
201                    "target".into(),
202                ].into(),
203                ..Default::default()
204            })),
205            ..Default::default()
206        })
207    }
208}