k8s_openapi/v1_30/api/resource/v1alpha2/
allocation_result.rs

1// Generated from definition io.k8s.api.resource.v1alpha2.AllocationResult
2
3/// AllocationResult contains attributes of an allocated resource.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct AllocationResult {
6    /// This field will get set by the resource driver after it has allocated the resource to inform the scheduler where it can schedule Pods using the ResourceClaim.
7    ///
8    /// Setting this field is optional. If null, the resource is available everywhere.
9    pub available_on_nodes: Option<crate::api::core::v1::NodeSelector>,
10
11    /// ResourceHandles contain the state associated with an allocation that should be maintained throughout the lifetime of a claim. Each ResourceHandle contains data that should be passed to a specific kubelet plugin once it lands on a node. This data is returned by the driver after a successful allocation and is opaque to Kubernetes. Driver documentation may explain to users how to interpret this data if needed.
12    ///
13    /// Setting this field is optional. It has a maximum size of 32 entries. If null (or empty), it is assumed this allocation will be processed by a single kubelet plugin with no ResourceHandle data attached. The name of the kubelet plugin invoked will match the DriverName set in the ResourceClaimStatus this AllocationResult is embedded in.
14    pub resource_handles: Option<std::vec::Vec<crate::api::resource::v1alpha2::ResourceHandle>>,
15
16    /// Shareable determines whether the resource supports more than one consumer at a time.
17    pub shareable: Option<bool>,
18}
19
20impl crate::DeepMerge for AllocationResult {
21    fn merge_from(&mut self, other: Self) {
22        crate::DeepMerge::merge_from(&mut self.available_on_nodes, other.available_on_nodes);
23        crate::merge_strategies::list::atomic(&mut self.resource_handles, other.resource_handles);
24        crate::DeepMerge::merge_from(&mut self.shareable, other.shareable);
25    }
26}
27
28impl<'de> crate::serde::Deserialize<'de> for AllocationResult {
29    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
30        #[allow(non_camel_case_types)]
31        enum Field {
32            Key_available_on_nodes,
33            Key_resource_handles,
34            Key_shareable,
35            Other,
36        }
37
38        impl<'de> crate::serde::Deserialize<'de> for Field {
39            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
40                struct Visitor;
41
42                impl crate::serde::de::Visitor<'_> for Visitor {
43                    type Value = Field;
44
45                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
46                        f.write_str("field identifier")
47                    }
48
49                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
50                        Ok(match v {
51                            "availableOnNodes" => Field::Key_available_on_nodes,
52                            "resourceHandles" => Field::Key_resource_handles,
53                            "shareable" => Field::Key_shareable,
54                            _ => Field::Other,
55                        })
56                    }
57                }
58
59                deserializer.deserialize_identifier(Visitor)
60            }
61        }
62
63        struct Visitor;
64
65        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
66            type Value = AllocationResult;
67
68            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
69                f.write_str("AllocationResult")
70            }
71
72            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
73                let mut value_available_on_nodes: Option<crate::api::core::v1::NodeSelector> = None;
74                let mut value_resource_handles: Option<std::vec::Vec<crate::api::resource::v1alpha2::ResourceHandle>> = None;
75                let mut value_shareable: Option<bool> = None;
76
77                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
78                    match key {
79                        Field::Key_available_on_nodes => value_available_on_nodes = crate::serde::de::MapAccess::next_value(&mut map)?,
80                        Field::Key_resource_handles => value_resource_handles = crate::serde::de::MapAccess::next_value(&mut map)?,
81                        Field::Key_shareable => value_shareable = crate::serde::de::MapAccess::next_value(&mut map)?,
82                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
83                    }
84                }
85
86                Ok(AllocationResult {
87                    available_on_nodes: value_available_on_nodes,
88                    resource_handles: value_resource_handles,
89                    shareable: value_shareable,
90                })
91            }
92        }
93
94        deserializer.deserialize_struct(
95            "AllocationResult",
96            &[
97                "availableOnNodes",
98                "resourceHandles",
99                "shareable",
100            ],
101            Visitor,
102        )
103    }
104}
105
106impl crate::serde::Serialize for AllocationResult {
107    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
108        let mut state = serializer.serialize_struct(
109            "AllocationResult",
110            self.available_on_nodes.as_ref().map_or(0, |_| 1) +
111            self.resource_handles.as_ref().map_or(0, |_| 1) +
112            self.shareable.as_ref().map_or(0, |_| 1),
113        )?;
114        if let Some(value) = &self.available_on_nodes {
115            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "availableOnNodes", value)?;
116        }
117        if let Some(value) = &self.resource_handles {
118            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resourceHandles", value)?;
119        }
120        if let Some(value) = &self.shareable {
121            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "shareable", value)?;
122        }
123        crate::serde::ser::SerializeStruct::end(state)
124    }
125}
126
127#[cfg(feature = "schemars")]
128impl crate::schemars::JsonSchema for AllocationResult {
129    fn schema_name() -> std::borrow::Cow<'static, str> {
130        "io.k8s.api.resource.v1alpha2.AllocationResult".into()
131    }
132
133    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
134        crate::schemars::json_schema!({
135            "description": "AllocationResult contains attributes of an allocated resource.",
136            "type": "object",
137            "properties": {
138                "availableOnNodes": ({
139                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::NodeSelector>();
140                    schema_obj.ensure_object().insert("description".into(), "This field will get set by the resource driver after it has allocated the resource to inform the scheduler where it can schedule Pods using the ResourceClaim.\n\nSetting this field is optional. If null, the resource is available everywhere.".into());
141                    schema_obj
142                }),
143                "resourceHandles": {
144                    "description": "ResourceHandles contain the state associated with an allocation that should be maintained throughout the lifetime of a claim. Each ResourceHandle contains data that should be passed to a specific kubelet plugin once it lands on a node. This data is returned by the driver after a successful allocation and is opaque to Kubernetes. Driver documentation may explain to users how to interpret this data if needed.\n\nSetting this field is optional. It has a maximum size of 32 entries. If null (or empty), it is assumed this allocation will be processed by a single kubelet plugin with no ResourceHandle data attached. The name of the kubelet plugin invoked will match the DriverName set in the ResourceClaimStatus this AllocationResult is embedded in.",
145                    "type": "array",
146                    "items": (__gen.subschema_for::<crate::api::resource::v1alpha2::ResourceHandle>()),
147                },
148                "shareable": {
149                    "description": "Shareable determines whether the resource supports more than one consumer at a time.",
150                    "type": "boolean",
151                },
152            },
153        })
154    }
155}