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

1// Generated from definition io.k8s.api.resource.v1alpha2.PodSchedulingContext
2
3/// PodSchedulingContext objects hold information that is needed to schedule a Pod with ResourceClaims that use "WaitForFirstConsumer" allocation mode.
4///
5/// This is an alpha type and requires enabling the DynamicResourceAllocation feature gate.
6#[derive(Clone, Debug, Default, PartialEq)]
7pub struct PodSchedulingContext {
8    /// Standard object metadata
9    pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
10
11    /// Spec describes where resources for the Pod are needed.
12    pub spec: crate::api::resource::v1alpha2::PodSchedulingContextSpec,
13
14    /// Status describes where resources for the Pod can be allocated.
15    pub status: Option<crate::api::resource::v1alpha2::PodSchedulingContextStatus>,
16}
17
18impl crate::Resource for PodSchedulingContext {
19    const API_VERSION: &'static str = "resource.k8s.io/v1alpha2";
20    const GROUP: &'static str = "resource.k8s.io";
21    const KIND: &'static str = "PodSchedulingContext";
22    const VERSION: &'static str = "v1alpha2";
23    const URL_PATH_SEGMENT: &'static str = "podschedulingcontexts";
24    type Scope = crate::NamespaceResourceScope;
25}
26
27impl crate::ListableResource for PodSchedulingContext {
28    const LIST_KIND: &'static str = "PodSchedulingContextList";
29}
30
31impl crate::Metadata for PodSchedulingContext {
32    type Ty = crate::apimachinery::pkg::apis::meta::v1::ObjectMeta;
33
34    fn metadata(&self) -> &<Self as crate::Metadata>::Ty {
35        &self.metadata
36    }
37
38    fn metadata_mut(&mut self) -> &mut<Self as crate::Metadata>::Ty {
39        &mut self.metadata
40    }
41}
42
43impl crate::DeepMerge for PodSchedulingContext {
44    fn merge_from(&mut self, other: Self) {
45        crate::DeepMerge::merge_from(&mut self.metadata, other.metadata);
46        crate::DeepMerge::merge_from(&mut self.spec, other.spec);
47        crate::DeepMerge::merge_from(&mut self.status, other.status);
48    }
49}
50
51impl<'de> crate::serde::Deserialize<'de> for PodSchedulingContext {
52    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
53        #[allow(non_camel_case_types)]
54        enum Field {
55            Key_api_version,
56            Key_kind,
57            Key_metadata,
58            Key_spec,
59            Key_status,
60            Other,
61        }
62
63        impl<'de> crate::serde::Deserialize<'de> for Field {
64            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
65                struct Visitor;
66
67                impl<'de> crate::serde::de::Visitor<'de> for Visitor {
68                    type Value = Field;
69
70                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
71                        f.write_str("field identifier")
72                    }
73
74                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
75                        Ok(match v {
76                            "apiVersion" => Field::Key_api_version,
77                            "kind" => Field::Key_kind,
78                            "metadata" => Field::Key_metadata,
79                            "spec" => Field::Key_spec,
80                            "status" => Field::Key_status,
81                            _ => Field::Other,
82                        })
83                    }
84                }
85
86                deserializer.deserialize_identifier(Visitor)
87            }
88        }
89
90        struct Visitor;
91
92        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
93            type Value = PodSchedulingContext;
94
95            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
96                f.write_str(<Self::Value as crate::Resource>::KIND)
97            }
98
99            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
100                let mut value_metadata: Option<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
101                let mut value_spec: Option<crate::api::resource::v1alpha2::PodSchedulingContextSpec> = None;
102                let mut value_status: Option<crate::api::resource::v1alpha2::PodSchedulingContextStatus> = None;
103
104                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
105                    match key {
106                        Field::Key_api_version => {
107                            let value_api_version: String = crate::serde::de::MapAccess::next_value(&mut map)?;
108                            if value_api_version != <Self::Value as crate::Resource>::API_VERSION {
109                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_api_version), &<Self::Value as crate::Resource>::API_VERSION));
110                            }
111                        },
112                        Field::Key_kind => {
113                            let value_kind: String = crate::serde::de::MapAccess::next_value(&mut map)?;
114                            if value_kind != <Self::Value as crate::Resource>::KIND {
115                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_kind), &<Self::Value as crate::Resource>::KIND));
116                            }
117                        },
118                        Field::Key_metadata => value_metadata = crate::serde::de::MapAccess::next_value(&mut map)?,
119                        Field::Key_spec => value_spec = crate::serde::de::MapAccess::next_value(&mut map)?,
120                        Field::Key_status => value_status = crate::serde::de::MapAccess::next_value(&mut map)?,
121                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
122                    }
123                }
124
125                Ok(PodSchedulingContext {
126                    metadata: value_metadata.unwrap_or_default(),
127                    spec: value_spec.unwrap_or_default(),
128                    status: value_status,
129                })
130            }
131        }
132
133        deserializer.deserialize_struct(
134            <Self as crate::Resource>::KIND,
135            &[
136                "apiVersion",
137                "kind",
138                "metadata",
139                "spec",
140                "status",
141            ],
142            Visitor,
143        )
144    }
145}
146
147impl crate::serde::Serialize for PodSchedulingContext {
148    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
149        let mut state = serializer.serialize_struct(
150            <Self as crate::Resource>::KIND,
151            4 +
152            self.status.as_ref().map_or(0, |_| 1),
153        )?;
154        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as crate::Resource>::API_VERSION)?;
155        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as crate::Resource>::KIND)?;
156        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
157        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "spec", &self.spec)?;
158        if let Some(value) = &self.status {
159            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "status", value)?;
160        }
161        crate::serde::ser::SerializeStruct::end(state)
162    }
163}
164
165#[cfg(feature = "schemars")]
166impl crate::schemars::JsonSchema for PodSchedulingContext {
167    fn schema_name() -> String {
168        "io.k8s.api.resource.v1alpha2.PodSchedulingContext".to_owned()
169    }
170
171    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
172        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
173            metadata: Some(Box::new(crate::schemars::schema::Metadata {
174                description: Some("PodSchedulingContext objects hold information that is needed to schedule a Pod with ResourceClaims that use \"WaitForFirstConsumer\" allocation mode.\n\nThis is an alpha type and requires enabling the DynamicResourceAllocation feature gate.".to_owned()),
175                ..Default::default()
176            })),
177            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
178            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
179                properties: [
180                    (
181                        "apiVersion".to_owned(),
182                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
183                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
184                                description: Some("APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources".to_owned()),
185                                ..Default::default()
186                            })),
187                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
188                            ..Default::default()
189                        }),
190                    ),
191                    (
192                        "kind".to_owned(),
193                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
194                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
195                                description: Some("Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds".to_owned()),
196                                ..Default::default()
197                            })),
198                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
199                            ..Default::default()
200                        }),
201                    ),
202                    (
203                        "metadata".to_owned(),
204                        {
205                            let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>().into_object();
206                            schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
207                                description: Some("Standard object metadata".to_owned()),
208                                ..Default::default()
209                            }));
210                            crate::schemars::schema::Schema::Object(schema_obj)
211                        },
212                    ),
213                    (
214                        "spec".to_owned(),
215                        {
216                            let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1alpha2::PodSchedulingContextSpec>().into_object();
217                            schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
218                                description: Some("Spec describes where resources for the Pod are needed.".to_owned()),
219                                ..Default::default()
220                            }));
221                            crate::schemars::schema::Schema::Object(schema_obj)
222                        },
223                    ),
224                    (
225                        "status".to_owned(),
226                        {
227                            let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1alpha2::PodSchedulingContextStatus>().into_object();
228                            schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
229                                description: Some("Status describes where resources for the Pod can be allocated.".to_owned()),
230                                ..Default::default()
231                            }));
232                            crate::schemars::schema::Schema::Object(schema_obj)
233                        },
234                    ),
235                ].into(),
236                required: [
237                    "metadata".to_owned(),
238                    "spec".to_owned(),
239                ].into(),
240                ..Default::default()
241            })),
242            ..Default::default()
243        })
244    }
245}