1// Generated from definition io.k8s.api.autoscaling.v2.MetricSpec
23/// MetricSpec specifies how to scale based on a single metric (only `type` and one other matching field should be set at once).
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct MetricSpec {
6/// containerResource refers to a resource metric (such as those specified in requests and limits) known to Kubernetes describing a single container in each pod of the current scale target (e.g. CPU or memory). 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.
7pub container_resource: Option<crate::api::autoscaling::v2::ContainerResourceMetricSource>,
89/// external refers to a global metric that is not associated with any Kubernetes object. It allows autoscaling based on information coming from components running outside of cluster (for example length of queue in cloud messaging service, or QPS from loadbalancer running outside of cluster).
10pub external: Option<crate::api::autoscaling::v2::ExternalMetricSource>,
1112/// object refers to a metric describing a single kubernetes object (for example, hits-per-second on an Ingress object).
13pub object: Option<crate::api::autoscaling::v2::ObjectMetricSource>,
1415/// pods refers to a metric describing each pod in the current scale target (for example, transactions-processed-per-second). The values will be averaged together before being compared to the target value.
16pub pods: Option<crate::api::autoscaling::v2::PodsMetricSource>,
1718/// resource refers to a resource metric (such as those specified in requests and limits) known to Kubernetes describing each pod in the current scale target (e.g. CPU or memory). 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.
19pub resource: Option<crate::api::autoscaling::v2::ResourceMetricSource>,
2021/// type is the type of metric source. It should be one of "ContainerResource", "External", "Object", "Pods" or "Resource", each mapping to a matching field in the object.
22pub type_: std::string::String,
23}
2425impl crate::DeepMerge for MetricSpec {
26fn merge_from(&mut self, other: Self) {
27crate::DeepMerge::merge_from(&mut self.container_resource, other.container_resource);
28crate::DeepMerge::merge_from(&mut self.external, other.external);
29crate::DeepMerge::merge_from(&mut self.object, other.object);
30crate::DeepMerge::merge_from(&mut self.pods, other.pods);
31crate::DeepMerge::merge_from(&mut self.resource, other.resource);
32crate::DeepMerge::merge_from(&mut self.type_, other.type_);
33 }
34}
3536impl<'de> crate::serde::Deserialize<'de> for MetricSpec {
37fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
38#[allow(non_camel_case_types)]
39enum Field {
40 Key_container_resource,
41 Key_external,
42 Key_object,
43 Key_pods,
44 Key_resource,
45 Key_type_,
46 Other,
47 }
4849impl<'de> crate::serde::Deserialize<'de> for Field {
50fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
51struct Visitor;
5253impl crate::serde::de::Visitor<'_> for Visitor {
54type Value = Field;
5556fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
57 f.write_str("field identifier")
58 }
5960fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
61Ok(match v {
62"containerResource" => Field::Key_container_resource,
63"external" => Field::Key_external,
64"object" => Field::Key_object,
65"pods" => Field::Key_pods,
66"resource" => Field::Key_resource,
67"type" => Field::Key_type_,
68_ => Field::Other,
69 })
70 }
71 }
7273 deserializer.deserialize_identifier(Visitor)
74 }
75 }
7677struct Visitor;
7879impl<'de> crate::serde::de::Visitor<'de> for Visitor {
80type Value = MetricSpec;
8182fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
83 f.write_str("MetricSpec")
84 }
8586fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
87let mut value_container_resource: Option<crate::api::autoscaling::v2::ContainerResourceMetricSource> = None;
88let mut value_external: Option<crate::api::autoscaling::v2::ExternalMetricSource> = None;
89let mut value_object: Option<crate::api::autoscaling::v2::ObjectMetricSource> = None;
90let mut value_pods: Option<crate::api::autoscaling::v2::PodsMetricSource> = None;
91let mut value_resource: Option<crate::api::autoscaling::v2::ResourceMetricSource> = None;
92let mut value_type_: Option<std::string::String> = None;
9394while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
95match key {
96 Field::Key_container_resource => value_container_resource = crate::serde::de::MapAccess::next_value(&mut map)?,
97 Field::Key_external => value_external = crate::serde::de::MapAccess::next_value(&mut map)?,
98 Field::Key_object => value_object = crate::serde::de::MapAccess::next_value(&mut map)?,
99 Field::Key_pods => value_pods = crate::serde::de::MapAccess::next_value(&mut map)?,
100 Field::Key_resource => value_resource = crate::serde::de::MapAccess::next_value(&mut map)?,
101 Field::Key_type_ => value_type_ = 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 }
105106Ok(MetricSpec {
107 container_resource: value_container_resource,
108 external: value_external,
109 object: value_object,
110 pods: value_pods,
111 resource: value_resource,
112 type_: value_type_.unwrap_or_default(),
113 })
114 }
115 }
116117 deserializer.deserialize_struct(
118"MetricSpec",
119&[
120"containerResource",
121"external",
122"object",
123"pods",
124"resource",
125"type",
126 ],
127 Visitor,
128 )
129 }
130}
131132impl crate::serde::Serialize for MetricSpec {
133fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
134let mut state = serializer.serialize_struct(
135"MetricSpec",
1361 +
137self.container_resource.as_ref().map_or(0, |_| 1) +
138self.external.as_ref().map_or(0, |_| 1) +
139self.object.as_ref().map_or(0, |_| 1) +
140self.pods.as_ref().map_or(0, |_| 1) +
141self.resource.as_ref().map_or(0, |_| 1),
142 )?;
143if let Some(value) = &self.container_resource {
144crate::serde::ser::SerializeStruct::serialize_field(&mut state, "containerResource", value)?;
145 }
146if let Some(value) = &self.external {
147crate::serde::ser::SerializeStruct::serialize_field(&mut state, "external", value)?;
148 }
149if let Some(value) = &self.object {
150crate::serde::ser::SerializeStruct::serialize_field(&mut state, "object", value)?;
151 }
152if let Some(value) = &self.pods {
153crate::serde::ser::SerializeStruct::serialize_field(&mut state, "pods", value)?;
154 }
155if let Some(value) = &self.resource {
156crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resource", value)?;
157 }
158crate::serde::ser::SerializeStruct::serialize_field(&mut state, "type", &self.type_)?;
159crate::serde::ser::SerializeStruct::end(state)
160 }
161}
162163#[cfg(feature = "schemars")]
164impl crate::schemars::JsonSchema for MetricSpec {
165fn schema_name() -> std::string::String {
166"io.k8s.api.autoscaling.v2.MetricSpec".into()
167 }
168169fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
170crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
171 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
172 description: Some("MetricSpec specifies how to scale based on a single metric (only `type` and one other matching field should be set at once).".into()),
173 ..Default::default()
174 })),
175 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
176 object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
177 properties: [
178 (
179"containerResource".into(),
180 {
181let mut schema_obj = __gen.subschema_for::<crate::api::autoscaling::v2::ContainerResourceMetricSource>().into_object();
182 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
183 description: Some("containerResource refers to a resource metric (such as those specified in requests and limits) known to Kubernetes describing a single container in each pod of the current scale target (e.g. CPU or memory). 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.".into()),
184 ..Default::default()
185 }));
186crate::schemars::schema::Schema::Object(schema_obj)
187 },
188 ),
189 (
190"external".into(),
191 {
192let mut schema_obj = __gen.subschema_for::<crate::api::autoscaling::v2::ExternalMetricSource>().into_object();
193 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
194 description: Some("external refers to a global metric that is not associated with any Kubernetes object. It allows autoscaling based on information coming from components running outside of cluster (for example length of queue in cloud messaging service, or QPS from loadbalancer running outside of cluster).".into()),
195 ..Default::default()
196 }));
197crate::schemars::schema::Schema::Object(schema_obj)
198 },
199 ),
200 (
201"object".into(),
202 {
203let mut schema_obj = __gen.subschema_for::<crate::api::autoscaling::v2::ObjectMetricSource>().into_object();
204 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
205 description: Some("object refers to a metric describing a single kubernetes object (for example, hits-per-second on an Ingress object).".into()),
206 ..Default::default()
207 }));
208crate::schemars::schema::Schema::Object(schema_obj)
209 },
210 ),
211 (
212"pods".into(),
213 {
214let mut schema_obj = __gen.subschema_for::<crate::api::autoscaling::v2::PodsMetricSource>().into_object();
215 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
216 description: Some("pods refers to a metric describing each pod in the current scale target (for example, transactions-processed-per-second). The values will be averaged together before being compared to the target value.".into()),
217 ..Default::default()
218 }));
219crate::schemars::schema::Schema::Object(schema_obj)
220 },
221 ),
222 (
223"resource".into(),
224 {
225let mut schema_obj = __gen.subschema_for::<crate::api::autoscaling::v2::ResourceMetricSource>().into_object();
226 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
227 description: Some("resource refers to a resource metric (such as those specified in requests and limits) known to Kubernetes describing each pod in the current scale target (e.g. CPU or memory). 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.".into()),
228 ..Default::default()
229 }));
230crate::schemars::schema::Schema::Object(schema_obj)
231 },
232 ),
233 (
234"type".into(),
235crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
236 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
237 description: Some("type is the type of metric source. It should be one of \"ContainerResource\", \"External\", \"Object\", \"Pods\" or \"Resource\", each mapping to a matching field in the object.".into()),
238 ..Default::default()
239 })),
240 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
241 ..Default::default()
242 }),
243 ),
244 ].into(),
245 required: [
246"type".into(),
247 ].into(),
248 ..Default::default()
249 })),
250 ..Default::default()
251 })
252 }
253}