1#[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(), "Standard object's 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}
242
243#[cfg(feature = "schemars08")]
244impl crate::schemars08::JsonSchema for PriorityClass {
245 fn schema_name() -> std::string::String {
246 "io.k8s.api.scheduling.v1.PriorityClass".into()
247 }
248
249 fn json_schema(__gen: &mut crate::schemars08::gen::SchemaGenerator) -> crate::schemars08::schema::Schema {
250 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
251 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
252 description: Some("PriorityClass defines mapping from a priority class name to the priority integer value. The value can be any valid integer.".into()),
253 ..Default::default()
254 })),
255 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Object))),
256 object: Some(std::boxed::Box::new(crate::schemars08::schema::ObjectValidation {
257 properties: [
258 (
259 "apiVersion".into(),
260 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
261 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
262 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".into()),
263 ..Default::default()
264 })),
265 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
266 ..Default::default()
267 }),
268 ),
269 (
270 "description".into(),
271 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
272 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
273 description: Some("description is an arbitrary string that usually provides guidelines on when this priority class should be used.".into()),
274 ..Default::default()
275 })),
276 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
277 ..Default::default()
278 }),
279 ),
280 (
281 "globalDefault".into(),
282 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
283 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
284 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.".into()),
285 ..Default::default()
286 })),
287 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Boolean))),
288 ..Default::default()
289 }),
290 ),
291 (
292 "kind".into(),
293 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
294 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
295 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".into()),
296 ..Default::default()
297 })),
298 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
299 ..Default::default()
300 }),
301 ),
302 (
303 "metadata".into(),
304 {
305 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>().into_object();
306 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
307 description: Some("Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata".into()),
308 ..Default::default()
309 }));
310 crate::schemars08::schema::Schema::Object(schema_obj)
311 },
312 ),
313 (
314 "preemptionPolicy".into(),
315 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
316 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
317 description: Some("preemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset.".into()),
318 ..Default::default()
319 })),
320 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
321 ..Default::default()
322 }),
323 ),
324 (
325 "value".into(),
326 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
327 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
328 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.".into()),
329 ..Default::default()
330 })),
331 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Integer))),
332 format: Some("int32".into()),
333 ..Default::default()
334 }),
335 ),
336 ].into(),
337 required: [
338 "metadata".into(),
339 ].into(),
340 ..Default::default()
341 })),
342 ..Default::default()
343 })
344 }
345}