k8s_openapi/v1_30/api/resource/v1alpha2/
resource_claim_spec.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ResourceClaimSpec {
6 pub allocation_mode: Option<std::string::String>,
8
9 pub parameters_ref: Option<crate::api::resource::v1alpha2::ResourceClaimParametersReference>,
13
14 pub resource_class_name: std::string::String,
16}
17
18impl crate::DeepMerge for ResourceClaimSpec {
19 fn merge_from(&mut self, other: Self) {
20 crate::DeepMerge::merge_from(&mut self.allocation_mode, other.allocation_mode);
21 crate::DeepMerge::merge_from(&mut self.parameters_ref, other.parameters_ref);
22 crate::DeepMerge::merge_from(&mut self.resource_class_name, other.resource_class_name);
23 }
24}
25
26impl<'de> crate::serde::Deserialize<'de> for ResourceClaimSpec {
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_allocation_mode,
31 Key_parameters_ref,
32 Key_resource_class_name,
33 Other,
34 }
35
36 impl<'de> crate::serde::Deserialize<'de> for Field {
37 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
38 struct Visitor;
39
40 impl crate::serde::de::Visitor<'_> for Visitor {
41 type Value = Field;
42
43 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
44 f.write_str("field identifier")
45 }
46
47 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
48 Ok(match v {
49 "allocationMode" => Field::Key_allocation_mode,
50 "parametersRef" => Field::Key_parameters_ref,
51 "resourceClassName" => Field::Key_resource_class_name,
52 _ => Field::Other,
53 })
54 }
55 }
56
57 deserializer.deserialize_identifier(Visitor)
58 }
59 }
60
61 struct Visitor;
62
63 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
64 type Value = ResourceClaimSpec;
65
66 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
67 f.write_str("ResourceClaimSpec")
68 }
69
70 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
71 let mut value_allocation_mode: Option<std::string::String> = None;
72 let mut value_parameters_ref: Option<crate::api::resource::v1alpha2::ResourceClaimParametersReference> = None;
73 let mut value_resource_class_name: Option<std::string::String> = None;
74
75 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
76 match key {
77 Field::Key_allocation_mode => value_allocation_mode = crate::serde::de::MapAccess::next_value(&mut map)?,
78 Field::Key_parameters_ref => value_parameters_ref = crate::serde::de::MapAccess::next_value(&mut map)?,
79 Field::Key_resource_class_name => value_resource_class_name = crate::serde::de::MapAccess::next_value(&mut map)?,
80 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
81 }
82 }
83
84 Ok(ResourceClaimSpec {
85 allocation_mode: value_allocation_mode,
86 parameters_ref: value_parameters_ref,
87 resource_class_name: value_resource_class_name.unwrap_or_default(),
88 })
89 }
90 }
91
92 deserializer.deserialize_struct(
93 "ResourceClaimSpec",
94 &[
95 "allocationMode",
96 "parametersRef",
97 "resourceClassName",
98 ],
99 Visitor,
100 )
101 }
102}
103
104impl crate::serde::Serialize for ResourceClaimSpec {
105 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
106 let mut state = serializer.serialize_struct(
107 "ResourceClaimSpec",
108 1 +
109 self.allocation_mode.as_ref().map_or(0, |_| 1) +
110 self.parameters_ref.as_ref().map_or(0, |_| 1),
111 )?;
112 if let Some(value) = &self.allocation_mode {
113 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allocationMode", value)?;
114 }
115 if let Some(value) = &self.parameters_ref {
116 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "parametersRef", value)?;
117 }
118 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resourceClassName", &self.resource_class_name)?;
119 crate::serde::ser::SerializeStruct::end(state)
120 }
121}
122
123#[cfg(feature = "schemars")]
124impl crate::schemars::JsonSchema for ResourceClaimSpec {
125 fn schema_name() -> std::borrow::Cow<'static, str> {
126 "io.k8s.api.resource.v1alpha2.ResourceClaimSpec".into()
127 }
128
129 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
130 crate::schemars::json_schema!({
131 "description": "ResourceClaimSpec defines how a resource is to be allocated.",
132 "type": "object",
133 "properties": {
134 "allocationMode": {
135 "description": "Allocation can start immediately or when a Pod wants to use the resource. \"WaitForFirstConsumer\" is the default.",
136 "type": "string",
137 },
138 "parametersRef": ({
139 let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1alpha2::ResourceClaimParametersReference>();
140 schema_obj.ensure_object().insert("description".into(), "ParametersRef references a separate object with arbitrary parameters that will be used by the driver when allocating a resource for the claim.\n\nThe object must be in the same namespace as the ResourceClaim.".into());
141 schema_obj
142 }),
143 "resourceClassName": {
144 "description": "ResourceClassName references the driver and additional parameters via the name of a ResourceClass that was created as part of the driver deployment.",
145 "type": "string",
146 },
147 },
148 "required": [
149 "resourceClassName",
150 ],
151 })
152 }
153}