1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct PodGroupSpec {
6 pub disruption_mode: Option<std::string::String>,
8
9 pub pod_group_template_ref: Option<crate::api::scheduling::v1alpha2::PodGroupTemplateReference>,
11
12 pub priority: Option<i32>,
14
15 pub priority_class_name: Option<std::string::String>,
17
18 pub resource_claims: Option<std::vec::Vec<crate::api::scheduling::v1alpha2::PodGroupResourceClaim>>,
24
25 pub scheduling_constraints: Option<crate::api::scheduling::v1alpha2::PodGroupSchedulingConstraints>,
27
28 pub scheduling_policy: crate::api::scheduling::v1alpha2::PodGroupSchedulingPolicy,
30}
31
32impl crate::DeepMerge for PodGroupSpec {
33 fn merge_from(&mut self, other: Self) {
34 crate::DeepMerge::merge_from(&mut self.disruption_mode, other.disruption_mode);
35 crate::DeepMerge::merge_from(&mut self.pod_group_template_ref, other.pod_group_template_ref);
36 crate::DeepMerge::merge_from(&mut self.priority, other.priority);
37 crate::DeepMerge::merge_from(&mut self.priority_class_name, other.priority_class_name);
38 crate::merge_strategies::list::map(
39 &mut self.resource_claims,
40 other.resource_claims,
41 &[|lhs, rhs| lhs.name == rhs.name],
42 |current_item, other_item| {
43 crate::DeepMerge::merge_from(current_item, other_item);
44 },
45 );
46 crate::DeepMerge::merge_from(&mut self.scheduling_constraints, other.scheduling_constraints);
47 crate::DeepMerge::merge_from(&mut self.scheduling_policy, other.scheduling_policy);
48 }
49}
50
51impl<'de> crate::serde::Deserialize<'de> for PodGroupSpec {
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_disruption_mode,
56 Key_pod_group_template_ref,
57 Key_priority,
58 Key_priority_class_name,
59 Key_resource_claims,
60 Key_scheduling_constraints,
61 Key_scheduling_policy,
62 Other,
63 }
64
65 impl<'de> crate::serde::Deserialize<'de> for Field {
66 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
67 struct Visitor;
68
69 impl crate::serde::de::Visitor<'_> for Visitor {
70 type Value = Field;
71
72 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
73 f.write_str("field identifier")
74 }
75
76 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
77 Ok(match v {
78 "disruptionMode" => Field::Key_disruption_mode,
79 "podGroupTemplateRef" => Field::Key_pod_group_template_ref,
80 "priority" => Field::Key_priority,
81 "priorityClassName" => Field::Key_priority_class_name,
82 "resourceClaims" => Field::Key_resource_claims,
83 "schedulingConstraints" => Field::Key_scheduling_constraints,
84 "schedulingPolicy" => Field::Key_scheduling_policy,
85 _ => Field::Other,
86 })
87 }
88 }
89
90 deserializer.deserialize_identifier(Visitor)
91 }
92 }
93
94 struct Visitor;
95
96 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
97 type Value = PodGroupSpec;
98
99 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
100 f.write_str("PodGroupSpec")
101 }
102
103 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
104 let mut value_disruption_mode: Option<std::string::String> = None;
105 let mut value_pod_group_template_ref: Option<crate::api::scheduling::v1alpha2::PodGroupTemplateReference> = None;
106 let mut value_priority: Option<i32> = None;
107 let mut value_priority_class_name: Option<std::string::String> = None;
108 let mut value_resource_claims: Option<std::vec::Vec<crate::api::scheduling::v1alpha2::PodGroupResourceClaim>> = None;
109 let mut value_scheduling_constraints: Option<crate::api::scheduling::v1alpha2::PodGroupSchedulingConstraints> = None;
110 let mut value_scheduling_policy: Option<crate::api::scheduling::v1alpha2::PodGroupSchedulingPolicy> = None;
111
112 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
113 match key {
114 Field::Key_disruption_mode => value_disruption_mode = crate::serde::de::MapAccess::next_value(&mut map)?,
115 Field::Key_pod_group_template_ref => value_pod_group_template_ref = crate::serde::de::MapAccess::next_value(&mut map)?,
116 Field::Key_priority => value_priority = crate::serde::de::MapAccess::next_value(&mut map)?,
117 Field::Key_priority_class_name => value_priority_class_name = crate::serde::de::MapAccess::next_value(&mut map)?,
118 Field::Key_resource_claims => value_resource_claims = crate::serde::de::MapAccess::next_value(&mut map)?,
119 Field::Key_scheduling_constraints => value_scheduling_constraints = crate::serde::de::MapAccess::next_value(&mut map)?,
120 Field::Key_scheduling_policy => value_scheduling_policy = 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(PodGroupSpec {
126 disruption_mode: value_disruption_mode,
127 pod_group_template_ref: value_pod_group_template_ref,
128 priority: value_priority,
129 priority_class_name: value_priority_class_name,
130 resource_claims: value_resource_claims,
131 scheduling_constraints: value_scheduling_constraints,
132 scheduling_policy: value_scheduling_policy.unwrap_or_default(),
133 })
134 }
135 }
136
137 deserializer.deserialize_struct(
138 "PodGroupSpec",
139 &[
140 "disruptionMode",
141 "podGroupTemplateRef",
142 "priority",
143 "priorityClassName",
144 "resourceClaims",
145 "schedulingConstraints",
146 "schedulingPolicy",
147 ],
148 Visitor,
149 )
150 }
151}
152
153impl crate::serde::Serialize for PodGroupSpec {
154 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
155 let mut state = serializer.serialize_struct(
156 "PodGroupSpec",
157 1 +
158 self.disruption_mode.as_ref().map_or(0, |_| 1) +
159 self.pod_group_template_ref.as_ref().map_or(0, |_| 1) +
160 self.priority.as_ref().map_or(0, |_| 1) +
161 self.priority_class_name.as_ref().map_or(0, |_| 1) +
162 self.resource_claims.as_ref().map_or(0, |_| 1) +
163 self.scheduling_constraints.as_ref().map_or(0, |_| 1),
164 )?;
165 if let Some(value) = &self.disruption_mode {
166 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "disruptionMode", value)?;
167 }
168 if let Some(value) = &self.pod_group_template_ref {
169 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "podGroupTemplateRef", value)?;
170 }
171 if let Some(value) = &self.priority {
172 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "priority", value)?;
173 }
174 if let Some(value) = &self.priority_class_name {
175 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "priorityClassName", value)?;
176 }
177 if let Some(value) = &self.resource_claims {
178 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resourceClaims", value)?;
179 }
180 if let Some(value) = &self.scheduling_constraints {
181 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "schedulingConstraints", value)?;
182 }
183 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "schedulingPolicy", &self.scheduling_policy)?;
184 crate::serde::ser::SerializeStruct::end(state)
185 }
186}
187
188#[cfg(feature = "schemars")]
189impl crate::schemars::JsonSchema for PodGroupSpec {
190 fn schema_name() -> std::borrow::Cow<'static, str> {
191 "io.k8s.api.scheduling.v1alpha2.PodGroupSpec".into()
192 }
193
194 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
195 crate::schemars::json_schema!({
196 "description": "PodGroupSpec defines the desired state of a PodGroup.",
197 "type": "object",
198 "properties": {
199 "disruptionMode": {
200 "description": "DisruptionMode defines the mode in which a given PodGroup can be disrupted. Controllers are expected to fill this field by copying it from a PodGroupTemplate. One of Pod, PodGroup. Defaults to Pod if unset. This field is immutable. This field is available only when the WorkloadAwarePreemption feature gate is enabled.",
201 "type": "string",
202 },
203 "podGroupTemplateRef": ({
204 let mut schema_obj = __gen.subschema_for::<crate::api::scheduling::v1alpha2::PodGroupTemplateReference>();
205 schema_obj.ensure_object().insert("description".into(), "PodGroupTemplateRef references an optional PodGroup template within other object (e.g. Workload) that was used to create the PodGroup. This field is immutable.".into());
206 schema_obj
207 }),
208 "priority": {
209 "description": "Priority is the value of priority of this pod group. Various system components use this field to find the priority of the pod group. When Priority Admission Controller is enabled, it prevents users from setting this field. The admission controller populates this field from PriorityClassName. The higher the value, the higher the priority. This field is immutable. This field is available only when the WorkloadAwarePreemption feature gate is enabled.",
210 "type": "integer",
211 "format": "int32",
212 },
213 "priorityClassName": {
214 "description": "PriorityClassName defines the priority that should be considered when scheduling this pod group. Controllers are expected to fill this field by copying it from a PodGroupTemplate. Otherwise, it is validated and resolved similarly to the PriorityClassName on PodGroupTemplate (i.e. if no priority class is specified, admission control can set this to the global default priority class if it exists. Otherwise, the pod group's priority will be zero). This field is immutable. This field is available only when the WorkloadAwarePreemption feature gate is enabled.",
215 "type": "string",
216 },
217 "resourceClaims": {
218 "description": "ResourceClaims defines which ResourceClaims may be shared among Pods in the group. Pods consume the devices allocated to a PodGroup's claim by defining a claim in its own Spec.ResourceClaims that matches the PodGroup's claim exactly. The claim must have the same name and refer to the same ResourceClaim or ResourceClaimTemplate.\n\nThis is an alpha-level field and requires that the DRAWorkloadResourceClaims feature gate is enabled.\n\nThis field is immutable.",
219 "type": "array",
220 "items": (__gen.subschema_for::<crate::api::scheduling::v1alpha2::PodGroupResourceClaim>()),
221 },
222 "schedulingConstraints": ({
223 let mut schema_obj = __gen.subschema_for::<crate::api::scheduling::v1alpha2::PodGroupSchedulingConstraints>();
224 schema_obj.ensure_object().insert("description".into(), "SchedulingConstraints defines optional scheduling constraints (e.g. topology) for this PodGroup. Controllers are expected to fill this field by copying it from a PodGroupTemplate. This field is immutable. This field is only available when the TopologyAwareWorkloadScheduling feature gate is enabled.".into());
225 schema_obj
226 }),
227 "schedulingPolicy": ({
228 let mut schema_obj = __gen.subschema_for::<crate::api::scheduling::v1alpha2::PodGroupSchedulingPolicy>();
229 schema_obj.ensure_object().insert("description".into(), "SchedulingPolicy defines the scheduling policy for this instance of the PodGroup. Controllers are expected to fill this field by copying it from a PodGroupTemplate. This field is immutable.".into());
230 schema_obj
231 }),
232 },
233 "required": [
234 "schedulingPolicy",
235 ],
236 })
237 }
238}
239
240#[cfg(feature = "schemars08")]
241impl crate::schemars08::JsonSchema for PodGroupSpec {
242 fn schema_name() -> std::string::String {
243 "io.k8s.api.scheduling.v1alpha2.PodGroupSpec".into()
244 }
245
246 fn json_schema(__gen: &mut crate::schemars08::gen::SchemaGenerator) -> crate::schemars08::schema::Schema {
247 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
248 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
249 description: Some("PodGroupSpec defines the desired state of a PodGroup.".into()),
250 ..Default::default()
251 })),
252 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Object))),
253 object: Some(std::boxed::Box::new(crate::schemars08::schema::ObjectValidation {
254 properties: [
255 (
256 "disruptionMode".into(),
257 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
258 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
259 description: Some("DisruptionMode defines the mode in which a given PodGroup can be disrupted. Controllers are expected to fill this field by copying it from a PodGroupTemplate. One of Pod, PodGroup. Defaults to Pod if unset. This field is immutable. This field is available only when the WorkloadAwarePreemption feature gate is enabled.".into()),
260 ..Default::default()
261 })),
262 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
263 ..Default::default()
264 }),
265 ),
266 (
267 "podGroupTemplateRef".into(),
268 {
269 let mut schema_obj = __gen.subschema_for::<crate::api::scheduling::v1alpha2::PodGroupTemplateReference>().into_object();
270 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
271 description: Some("PodGroupTemplateRef references an optional PodGroup template within other object (e.g. Workload) that was used to create the PodGroup. This field is immutable.".into()),
272 ..Default::default()
273 }));
274 crate::schemars08::schema::Schema::Object(schema_obj)
275 },
276 ),
277 (
278 "priority".into(),
279 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
280 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
281 description: Some("Priority is the value of priority of this pod group. Various system components use this field to find the priority of the pod group. When Priority Admission Controller is enabled, it prevents users from setting this field. The admission controller populates this field from PriorityClassName. The higher the value, the higher the priority. This field is immutable. This field is available only when the WorkloadAwarePreemption feature gate is enabled.".into()),
282 ..Default::default()
283 })),
284 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Integer))),
285 format: Some("int32".into()),
286 ..Default::default()
287 }),
288 ),
289 (
290 "priorityClassName".into(),
291 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
292 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
293 description: Some("PriorityClassName defines the priority that should be considered when scheduling this pod group. Controllers are expected to fill this field by copying it from a PodGroupTemplate. Otherwise, it is validated and resolved similarly to the PriorityClassName on PodGroupTemplate (i.e. if no priority class is specified, admission control can set this to the global default priority class if it exists. Otherwise, the pod group's priority will be zero). This field is immutable. This field is available only when the WorkloadAwarePreemption feature gate is enabled.".into()),
294 ..Default::default()
295 })),
296 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
297 ..Default::default()
298 }),
299 ),
300 (
301 "resourceClaims".into(),
302 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
303 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
304 description: Some("ResourceClaims defines which ResourceClaims may be shared among Pods in the group. Pods consume the devices allocated to a PodGroup's claim by defining a claim in its own Spec.ResourceClaims that matches the PodGroup's claim exactly. The claim must have the same name and refer to the same ResourceClaim or ResourceClaimTemplate.\n\nThis is an alpha-level field and requires that the DRAWorkloadResourceClaims feature gate is enabled.\n\nThis field is immutable.".into()),
305 ..Default::default()
306 })),
307 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Array))),
308 array: Some(std::boxed::Box::new(crate::schemars08::schema::ArrayValidation {
309 items: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::scheduling::v1alpha2::PodGroupResourceClaim>()))),
310 ..Default::default()
311 })),
312 ..Default::default()
313 }),
314 ),
315 (
316 "schedulingConstraints".into(),
317 {
318 let mut schema_obj = __gen.subschema_for::<crate::api::scheduling::v1alpha2::PodGroupSchedulingConstraints>().into_object();
319 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
320 description: Some("SchedulingConstraints defines optional scheduling constraints (e.g. topology) for this PodGroup. Controllers are expected to fill this field by copying it from a PodGroupTemplate. This field is immutable. This field is only available when the TopologyAwareWorkloadScheduling feature gate is enabled.".into()),
321 ..Default::default()
322 }));
323 crate::schemars08::schema::Schema::Object(schema_obj)
324 },
325 ),
326 (
327 "schedulingPolicy".into(),
328 {
329 let mut schema_obj = __gen.subschema_for::<crate::api::scheduling::v1alpha2::PodGroupSchedulingPolicy>().into_object();
330 schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
331 description: Some("SchedulingPolicy defines the scheduling policy for this instance of the PodGroup. Controllers are expected to fill this field by copying it from a PodGroupTemplate. This field is immutable.".into()),
332 ..Default::default()
333 }));
334 crate::schemars08::schema::Schema::Object(schema_obj)
335 },
336 ),
337 ].into(),
338 required: [
339 "schedulingPolicy".into(),
340 ].into(),
341 ..Default::default()
342 })),
343 ..Default::default()
344 })
345 }
346}