k8s_openapi/v1_32/api/scheduling/v1/
priority_class.rs

1// Generated from definition io.k8s.api.scheduling.v1.PriorityClass
2
3/// PriorityClass defines mapping from a priority class name to the priority integer value. The value can be any valid integer.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct PriorityClass {
6    /// description is an arbitrary string that usually provides guidelines on when this priority class should be used.
7    pub description: Option<String>,
8
9    /// globalDefault specifies whether this PriorityClass should be considered as the default priority for pods that do not have any priority class. Only one PriorityClass can be marked as `globalDefault`. However, if more than one PriorityClasses exists with their `globalDefault` field set to true, the smallest value of such global default PriorityClasses will be used as the default priority.
10    pub global_default: Option<bool>,
11
12    /// Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
13    pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
14
15    /// preemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset.
16    pub preemption_policy: Option<String>,
17
18    /// value represents the integer value of this priority class. This is the actual priority that pods receive when they have the name of this class in their pod spec.
19    pub value: i32,
20}
21
22impl crate::Resource for PriorityClass {
23    const API_VERSION: &'static str = "scheduling.k8s.io/v1";
24    const GROUP: &'static str = "scheduling.k8s.io";
25    const KIND: &'static str = "PriorityClass";
26    const VERSION: &'static str = "v1";
27    const URL_PATH_SEGMENT: &'static str = "priorityclasses";
28    type Scope = crate::ClusterResourceScope;
29}
30
31impl crate::ListableResource for PriorityClass {
32    const LIST_KIND: &'static str = "PriorityClassList";
33}
34
35impl crate::Metadata for PriorityClass {
36    type Ty = crate::apimachinery::pkg::apis::meta::v1::ObjectMeta;
37
38    fn metadata(&self) -> &<Self as crate::Metadata>::Ty {
39        &self.metadata
40    }
41
42    fn metadata_mut(&mut self) -> &mut<Self as crate::Metadata>::Ty {
43        &mut self.metadata
44    }
45}
46
47impl crate::DeepMerge for PriorityClass {
48    fn merge_from(&mut self, other: Self) {
49        crate::DeepMerge::merge_from(&mut self.description, other.description);
50        crate::DeepMerge::merge_from(&mut self.global_default, other.global_default);
51        crate::DeepMerge::merge_from(&mut self.metadata, other.metadata);
52        crate::DeepMerge::merge_from(&mut self.preemption_policy, other.preemption_policy);
53        crate::DeepMerge::merge_from(&mut self.value, other.value);
54    }
55}
56
57impl<'de> crate::serde::Deserialize<'de> for PriorityClass {
58    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
59        #[allow(non_camel_case_types)]
60        enum Field {
61            Key_api_version,
62            Key_kind,
63            Key_description,
64            Key_global_default,
65            Key_metadata,
66            Key_preemption_policy,
67            Key_value,
68            Other,
69        }
70
71        impl<'de> crate::serde::Deserialize<'de> for Field {
72            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
73                struct Visitor;
74
75                impl crate::serde::de::Visitor<'_> for Visitor {
76                    type Value = Field;
77
78                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
79                        f.write_str("field identifier")
80                    }
81
82                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
83                        Ok(match v {
84                            "apiVersion" => Field::Key_api_version,
85                            "kind" => Field::Key_kind,
86                            "description" => Field::Key_description,
87                            "globalDefault" => Field::Key_global_default,
88                            "metadata" => Field::Key_metadata,
89                            "preemptionPolicy" => Field::Key_preemption_policy,
90                            "value" => Field::Key_value,
91                            _ => Field::Other,
92                        })
93                    }
94                }
95
96                deserializer.deserialize_identifier(Visitor)
97            }
98        }
99
100        struct Visitor;
101
102        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
103            type Value = PriorityClass;
104
105            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
106                f.write_str(<Self::Value as crate::Resource>::KIND)
107            }
108
109            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
110                let mut value_description: Option<String> = None;
111                let mut value_global_default: Option<bool> = None;
112                let mut value_metadata: Option<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
113                let mut value_preemption_policy: Option<String> = None;
114                let mut value_value: Option<i32> = None;
115
116                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
117                    match key {
118                        Field::Key_api_version => {
119                            let value_api_version: String = crate::serde::de::MapAccess::next_value(&mut map)?;
120                            if value_api_version != <Self::Value as crate::Resource>::API_VERSION {
121                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_api_version), &<Self::Value as crate::Resource>::API_VERSION));
122                            }
123                        },
124                        Field::Key_kind => {
125                            let value_kind: String = crate::serde::de::MapAccess::next_value(&mut map)?;
126                            if value_kind != <Self::Value as crate::Resource>::KIND {
127                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_kind), &<Self::Value as crate::Resource>::KIND));
128                            }
129                        },
130                        Field::Key_description => value_description = crate::serde::de::MapAccess::next_value(&mut map)?,
131                        Field::Key_global_default => value_global_default = crate::serde::de::MapAccess::next_value(&mut map)?,
132                        Field::Key_metadata => value_metadata = crate::serde::de::MapAccess::next_value(&mut map)?,
133                        Field::Key_preemption_policy => value_preemption_policy = crate::serde::de::MapAccess::next_value(&mut map)?,
134                        Field::Key_value => value_value = crate::serde::de::MapAccess::next_value(&mut map)?,
135                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
136                    }
137                }
138
139                Ok(PriorityClass {
140                    description: value_description,
141                    global_default: value_global_default,
142                    metadata: value_metadata.unwrap_or_default(),
143                    preemption_policy: value_preemption_policy,
144                    value: value_value.unwrap_or_default(),
145                })
146            }
147        }
148
149        deserializer.deserialize_struct(
150            <Self as crate::Resource>::KIND,
151            &[
152                "apiVersion",
153                "kind",
154                "description",
155                "globalDefault",
156                "metadata",
157                "preemptionPolicy",
158                "value",
159            ],
160            Visitor,
161        )
162    }
163}
164
165impl crate::serde::Serialize for PriorityClass {
166    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
167        let mut state = serializer.serialize_struct(
168            <Self as crate::Resource>::KIND,
169            4 +
170            self.description.as_ref().map_or(0, |_| 1) +
171            self.global_default.as_ref().map_or(0, |_| 1) +
172            self.preemption_policy.as_ref().map_or(0, |_| 1),
173        )?;
174        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as crate::Resource>::API_VERSION)?;
175        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as crate::Resource>::KIND)?;
176        if let Some(value) = &self.description {
177            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "description", value)?;
178        }
179        if let Some(value) = &self.global_default {
180            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "globalDefault", value)?;
181        }
182        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
183        if let Some(value) = &self.preemption_policy {
184            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "preemptionPolicy", value)?;
185        }
186        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "value", &self.value)?;
187        crate::serde::ser::SerializeStruct::end(state)
188    }
189}
190
191#[cfg(feature = "schemars")]
192impl crate::schemars::JsonSchema for PriorityClass {
193    fn schema_name() -> String {
194        "io.k8s.api.scheduling.v1.PriorityClass".to_owned()
195    }
196
197    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
198        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
199            metadata: Some(Box::new(crate::schemars::schema::Metadata {
200                description: Some("PriorityClass defines mapping from a priority class name to the priority integer value. The value can be any valid integer.".to_owned()),
201                ..Default::default()
202            })),
203            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
204            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
205                properties: [
206                    (
207                        "apiVersion".to_owned(),
208                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
209                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
210                                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()),
211                                ..Default::default()
212                            })),
213                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
214                            ..Default::default()
215                        }),
216                    ),
217                    (
218                        "description".to_owned(),
219                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
220                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
221                                description: Some("description is an arbitrary string that usually provides guidelines on when this priority class should be used.".to_owned()),
222                                ..Default::default()
223                            })),
224                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
225                            ..Default::default()
226                        }),
227                    ),
228                    (
229                        "globalDefault".to_owned(),
230                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
231                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
232                                description: Some("globalDefault specifies whether this PriorityClass should be considered as the default priority for pods that do not have any priority class. Only one PriorityClass can be marked as `globalDefault`. However, if more than one PriorityClasses exists with their `globalDefault` field set to true, the smallest value of such global default PriorityClasses will be used as the default priority.".to_owned()),
233                                ..Default::default()
234                            })),
235                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Boolean))),
236                            ..Default::default()
237                        }),
238                    ),
239                    (
240                        "kind".to_owned(),
241                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
242                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
243                                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()),
244                                ..Default::default()
245                            })),
246                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
247                            ..Default::default()
248                        }),
249                    ),
250                    (
251                        "metadata".to_owned(),
252                        {
253                            let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>().into_object();
254                            schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
255                                description: Some("Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata".to_owned()),
256                                ..Default::default()
257                            }));
258                            crate::schemars::schema::Schema::Object(schema_obj)
259                        },
260                    ),
261                    (
262                        "preemptionPolicy".to_owned(),
263                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
264                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
265                                description: Some("preemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset.".to_owned()),
266                                ..Default::default()
267                            })),
268                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
269                            ..Default::default()
270                        }),
271                    ),
272                    (
273                        "value".to_owned(),
274                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
275                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
276                                description: Some("value represents the integer value of this priority class. This is the actual priority that pods receive when they have the name of this class in their pod spec.".to_owned()),
277                                ..Default::default()
278                            })),
279                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Integer))),
280                            format: Some("int32".to_owned()),
281                            ..Default::default()
282                        }),
283                    ),
284                ].into(),
285                required: [
286                    "metadata".to_owned(),
287                    "value".to_owned(),
288                ].into(),
289                ..Default::default()
290            })),
291            ..Default::default()
292        })
293    }
294}