k8s_openapi/v1_36/api/resource/v1beta1/
device_capacity.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct DeviceCapacity {
6 pub request_policy: Option<crate::api::resource::v1beta1::CapacityRequestPolicy>,
12
13 pub value: crate::apimachinery::pkg::api::resource::Quantity,
17}
18
19impl crate::DeepMerge for DeviceCapacity {
20 fn merge_from(&mut self, other: Self) {
21 crate::DeepMerge::merge_from(&mut self.request_policy, other.request_policy);
22 crate::DeepMerge::merge_from(&mut self.value, other.value);
23 }
24}
25
26impl<'de> crate::serde::Deserialize<'de> for DeviceCapacity {
27 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
28 #[allow(non_camel_case_types)]
29 enum Field {
30 Key_request_policy,
31 Key_value,
32 Other,
33 }
34
35 impl<'de> crate::serde::Deserialize<'de> for Field {
36 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
37 struct Visitor;
38
39 impl crate::serde::de::Visitor<'_> for Visitor {
40 type Value = Field;
41
42 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
43 f.write_str("field identifier")
44 }
45
46 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
47 Ok(match v {
48 "requestPolicy" => Field::Key_request_policy,
49 "value" => Field::Key_value,
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 = DeviceCapacity;
63
64 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
65 f.write_str("DeviceCapacity")
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_request_policy: Option<crate::api::resource::v1beta1::CapacityRequestPolicy> = None;
70 let mut value_value: Option<crate::apimachinery::pkg::api::resource::Quantity> = None;
71
72 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
73 match key {
74 Field::Key_request_policy => value_request_policy = crate::serde::de::MapAccess::next_value(&mut map)?,
75 Field::Key_value => value_value = crate::serde::de::MapAccess::next_value(&mut map)?,
76 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
77 }
78 }
79
80 Ok(DeviceCapacity {
81 request_policy: value_request_policy,
82 value: value_value.unwrap_or_default(),
83 })
84 }
85 }
86
87 deserializer.deserialize_struct(
88 "DeviceCapacity",
89 &[
90 "requestPolicy",
91 "value",
92 ],
93 Visitor,
94 )
95 }
96}
97
98impl crate::serde::Serialize for DeviceCapacity {
99 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
100 let mut state = serializer.serialize_struct(
101 "DeviceCapacity",
102 1 +
103 self.request_policy.as_ref().map_or(0, |_| 1),
104 )?;
105 if let Some(value) = &self.request_policy {
106 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "requestPolicy", value)?;
107 }
108 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "value", &self.value)?;
109 crate::serde::ser::SerializeStruct::end(state)
110 }
111}
112
113#[cfg(feature = "schemars")]
114impl crate::schemars::JsonSchema for DeviceCapacity {
115 fn schema_name() -> std::borrow::Cow<'static, str> {
116 "io.k8s.api.resource.v1beta1.DeviceCapacity".into()
117 }
118
119 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
120 crate::schemars::json_schema!({
121 "description": "DeviceCapacity describes a quantity associated with a device.",
122 "type": "object",
123 "properties": {
124 "requestPolicy": ({
125 let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta1::CapacityRequestPolicy>();
126 schema_obj.ensure_object().insert("description".into(), "RequestPolicy defines how this DeviceCapacity must be consumed when the device is allowed to be shared by multiple allocations.\n\nThe Device must have allowMultipleAllocations set to true in order to set a requestPolicy.\n\nIf unset, capacity requests are unconstrained: requests can consume any amount of capacity, as long as the total consumed across all allocations does not exceed the device's defined capacity. If request is also unset, default is the full capacity value.".into());
127 schema_obj
128 }),
129 "value": ({
130 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>();
131 schema_obj.ensure_object().insert("description".into(), "Value defines how much of a certain capacity that device has.\n\nThis field reflects the fixed total capacity and does not change. The consumed amount is tracked separately by scheduler and does not affect this value.".into());
132 schema_obj
133 }),
134 },
135 "required": [
136 "value",
137 ],
138 })
139 }
140}
141
142#[cfg(feature = "schemars08")]
143impl crate::schemars08::JsonSchema for DeviceCapacity {
144 fn schema_name() -> std::string::String {
145 "io.k8s.api.resource.v1beta1.DeviceCapacity".into()
146 }
147
148 fn json_schema(__gen: &mut crate::schemars08::gen::SchemaGenerator) -> crate::schemars08::schema::Schema {
149 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
150 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
151 description: Some("DeviceCapacity describes a quantity associated with a device.".into()),
152 ..Default::default()
153 })),
154 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Object))),
155 object: Some(std::boxed::Box::new(crate::schemars08::schema::ObjectValidation {
156 properties: [
157 (
158 "requestPolicy".into(),
159 {
160 let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta1::CapacityRequestPolicy>().into_object();
161 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
162 description: Some("RequestPolicy defines how this DeviceCapacity must be consumed when the device is allowed to be shared by multiple allocations.\n\nThe Device must have allowMultipleAllocations set to true in order to set a requestPolicy.\n\nIf unset, capacity requests are unconstrained: requests can consume any amount of capacity, as long as the total consumed across all allocations does not exceed the device's defined capacity. If request is also unset, default is the full capacity value.".into()),
163 ..Default::default()
164 }));
165 crate::schemars08::schema::Schema::Object(schema_obj)
166 },
167 ),
168 (
169 "value".into(),
170 {
171 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>().into_object();
172 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
173 description: Some("Value defines how much of a certain capacity that device has.\n\nThis field reflects the fixed total capacity and does not change. The consumed amount is tracked separately by scheduler and does not affect this value.".into()),
174 ..Default::default()
175 }));
176 crate::schemars08::schema::Schema::Object(schema_obj)
177 },
178 ),
179 ].into(),
180 required: [
181 "value".into(),
182 ].into(),
183 ..Default::default()
184 })),
185 ..Default::default()
186 })
187 }
188}