k8s_openapi/v1_37/api/scheduling/v1/
priority_class.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct PriorityClass {
6 pub description: Option<std::string::String>,
8
9 pub global_default: Option<bool>,
11
12 pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
14
15 pub preemption_policy: Option<std::string::String>,
17
18 pub value: Option<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 core::fmt::Formatter<'_>) -> core::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 core::fmt::Formatter<'_>) -> core::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<std::string::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<std::string::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: std::string::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: std::string::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,
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 3 +
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 self.value.as_ref().map_or(0, |_| 1),
174 )?;
175 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as crate::Resource>::API_VERSION)?;
176 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as crate::Resource>::KIND)?;
177 if let Some(value) = &self.description {
178 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "description", value)?;
179 }
180 if let Some(value) = &self.global_default {
181 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "globalDefault", value)?;
182 }
183 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
184 if let Some(value) = &self.preemption_policy {
185 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "preemptionPolicy", value)?;
186 }
187 if let Some(value) = &self.value {
188 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "value", value)?;
189 }
190 crate::serde::ser::SerializeStruct::end(state)
191 }
192}
193
194#[cfg(feature = "schemars")]
195impl crate::schemars::JsonSchema for PriorityClass {
196 fn schema_name() -> std::borrow::Cow<'static, str> {
197 "io.k8s.api.scheduling.v1.PriorityClass".into()
198 }
199
200 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
201 crate::schemars::json_schema!({
202 "description": "PriorityClass defines mapping from a priority class name to the priority integer value. The value can be any valid integer.",
203 "type": "object",
204 "properties": {
205 "apiVersion": {
206 "description": "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",
207 "type": "string",
208 },
209 "description": {
210 "description": "description is an arbitrary string that usually provides guidelines on when this priority class should be used.",
211 "type": "string",
212 },
213 "globalDefault": {
214 "description": "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.",
215 "type": "boolean",
216 },
217 "kind": {
218 "description": "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",
219 "type": "string",
220 },
221 "metadata": ({
222 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>();
223 schema_obj.ensure_object().insert("description".into(), "metadata is the standard object metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata".into());
224 schema_obj
225 }),
226 "preemptionPolicy": {
227 "description": "preemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset.",
228 "type": "string",
229 },
230 "value": {
231 "description": "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.",
232 "type": "integer",
233 "format": "int32",
234 },
235 },
236 "required": [
237 "metadata",
238 ],
239 })
240 }
241}