k8s_openapi/v1_35/api/core/v1/
pod_resource_claim.rs

1// Generated from definition io.k8s.api.core.v1.PodResourceClaim
2
3/// PodResourceClaim references exactly one ResourceClaim, either directly or by naming a ResourceClaimTemplate which is then turned into a ResourceClaim for the pod.
4///
5/// It adds a name to it that uniquely identifies the ResourceClaim inside the Pod. Containers that need access to the ResourceClaim reference it with this name.
6#[derive(Clone, Debug, Default, PartialEq)]
7pub struct PodResourceClaim {
8    /// Name uniquely identifies this resource claim inside the pod. This must be a DNS_LABEL.
9    pub name: std::string::String,
10
11    /// ResourceClaimName is the name of a ResourceClaim object in the same namespace as this pod.
12    ///
13    /// Exactly one of ResourceClaimName and ResourceClaimTemplateName must be set.
14    pub resource_claim_name: Option<std::string::String>,
15
16    /// ResourceClaimTemplateName is the name of a ResourceClaimTemplate object in the same namespace as this pod.
17    ///
18    /// The template will be used to create a new ResourceClaim, which will be bound to this pod. When this pod is deleted, the ResourceClaim will also be deleted. The pod name and resource name, along with a generated component, will be used to form a unique name for the ResourceClaim, which will be recorded in pod.status.resourceClaimStatuses.
19    ///
20    /// This field is immutable and no changes will be made to the corresponding ResourceClaim by the control plane after creating the ResourceClaim.
21    ///
22    /// Exactly one of ResourceClaimName and ResourceClaimTemplateName must be set.
23    pub resource_claim_template_name: Option<std::string::String>,
24}
25
26impl crate::DeepMerge for PodResourceClaim {
27    fn merge_from(&mut self, other: Self) {
28        crate::DeepMerge::merge_from(&mut self.name, other.name);
29        crate::DeepMerge::merge_from(&mut self.resource_claim_name, other.resource_claim_name);
30        crate::DeepMerge::merge_from(&mut self.resource_claim_template_name, other.resource_claim_template_name);
31    }
32}
33
34impl<'de> crate::serde::Deserialize<'de> for PodResourceClaim {
35    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
36        #[allow(non_camel_case_types)]
37        enum Field {
38            Key_name,
39            Key_resource_claim_name,
40            Key_resource_claim_template_name,
41            Other,
42        }
43
44        impl<'de> crate::serde::Deserialize<'de> for Field {
45            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
46                struct Visitor;
47
48                impl crate::serde::de::Visitor<'_> for Visitor {
49                    type Value = Field;
50
51                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
52                        f.write_str("field identifier")
53                    }
54
55                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
56                        Ok(match v {
57                            "name" => Field::Key_name,
58                            "resourceClaimName" => Field::Key_resource_claim_name,
59                            "resourceClaimTemplateName" => Field::Key_resource_claim_template_name,
60                            _ => Field::Other,
61                        })
62                    }
63                }
64
65                deserializer.deserialize_identifier(Visitor)
66            }
67        }
68
69        struct Visitor;
70
71        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
72            type Value = PodResourceClaim;
73
74            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
75                f.write_str("PodResourceClaim")
76            }
77
78            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
79                let mut value_name: Option<std::string::String> = None;
80                let mut value_resource_claim_name: Option<std::string::String> = None;
81                let mut value_resource_claim_template_name: Option<std::string::String> = None;
82
83                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
84                    match key {
85                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
86                        Field::Key_resource_claim_name => value_resource_claim_name = crate::serde::de::MapAccess::next_value(&mut map)?,
87                        Field::Key_resource_claim_template_name => value_resource_claim_template_name = crate::serde::de::MapAccess::next_value(&mut map)?,
88                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
89                    }
90                }
91
92                Ok(PodResourceClaim {
93                    name: value_name.unwrap_or_default(),
94                    resource_claim_name: value_resource_claim_name,
95                    resource_claim_template_name: value_resource_claim_template_name,
96                })
97            }
98        }
99
100        deserializer.deserialize_struct(
101            "PodResourceClaim",
102            &[
103                "name",
104                "resourceClaimName",
105                "resourceClaimTemplateName",
106            ],
107            Visitor,
108        )
109    }
110}
111
112impl crate::serde::Serialize for PodResourceClaim {
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            "PodResourceClaim",
116            1 +
117            self.resource_claim_name.as_ref().map_or(0, |_| 1) +
118            self.resource_claim_template_name.as_ref().map_or(0, |_| 1),
119        )?;
120        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
121        if let Some(value) = &self.resource_claim_name {
122            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resourceClaimName", value)?;
123        }
124        if let Some(value) = &self.resource_claim_template_name {
125            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resourceClaimTemplateName", value)?;
126        }
127        crate::serde::ser::SerializeStruct::end(state)
128    }
129}
130
131#[cfg(feature = "schemars")]
132impl crate::schemars::JsonSchema for PodResourceClaim {
133    fn schema_name() -> std::borrow::Cow<'static, str> {
134        "io.k8s.api.core.v1.PodResourceClaim".into()
135    }
136
137    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
138        crate::schemars::json_schema!({
139            "description": "PodResourceClaim references exactly one ResourceClaim, either directly or by naming a ResourceClaimTemplate which is then turned into a ResourceClaim for the pod.\n\nIt adds a name to it that uniquely identifies the ResourceClaim inside the Pod. Containers that need access to the ResourceClaim reference it with this name.",
140            "type": "object",
141            "properties": {
142                "name": {
143                    "description": "Name uniquely identifies this resource claim inside the pod. This must be a DNS_LABEL.",
144                    "type": "string",
145                },
146                "resourceClaimName": {
147                    "description": "ResourceClaimName is the name of a ResourceClaim object in the same namespace as this pod.\n\nExactly one of ResourceClaimName and ResourceClaimTemplateName must be set.",
148                    "type": "string",
149                },
150                "resourceClaimTemplateName": {
151                    "description": "ResourceClaimTemplateName is the name of a ResourceClaimTemplate object in the same namespace as this pod.\n\nThe template will be used to create a new ResourceClaim, which will be bound to this pod. When this pod is deleted, the ResourceClaim will also be deleted. The pod name and resource name, along with a generated component, will be used to form a unique name for the ResourceClaim, which will be recorded in pod.status.resourceClaimStatuses.\n\nThis field is immutable and no changes will be made to the corresponding ResourceClaim by the control plane after creating the ResourceClaim.\n\nExactly one of ResourceClaimName and ResourceClaimTemplateName must be set.",
152                    "type": "string",
153                },
154            },
155            "required": [
156                "name",
157            ],
158        })
159    }
160}