Skip to main content

k8s_openapi/v1_37/api/batch/v1/
job_scheduling_configuration.rs

1// Generated from definition io.k8s.api.batch.v1.JobSchedulingConfiguration
2
3/// JobSchedulingConfiguration composes the reusable workload-aware scheduling building blocks.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct JobSchedulingConfiguration {
6    /// DisruptionMode defines the mode in which the Job's pods can be disrupted. One of Single, All. This field is immutable after creation: it may not be added or removed, and the selected mode may not be changed.
7    pub disruption_mode: Option<crate::api::scheduling::v1alpha3::WorkloadPodGroupDisruptionMode>,
8
9    /// ResourceClaims defines which ResourceClaims may be shared among Pods in the Job. 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. At most 4 claims may be set, matching the limit on the resulting PodGroup. This list is immutable after creation: entries may neither be added, removed, nor modified.
10    pub resource_claims: Option<std::vec::Vec<crate::api::scheduling::v1alpha3::WorkloadPodGroupResourceClaim>>,
11
12    /// SchedulingConstraints defines scheduling constraints (e.g. topology) for the Job's pods. This field is immutable after creation.
13    pub scheduling_constraints: Option<crate::api::scheduling::v1alpha3::WorkloadPodGroupSchedulingConstraints>,
14
15    /// SchedulingPolicy defines the scheduling policy for this Job. Exactly one of Basic or Gang must be set. This field is immutable after creation: the policy may not be added or removed. The policy variant (basic/gang) is frozen by hand-written validation; only schedulingPolicy.gang.minCount may be changed.
16    pub scheduling_policy: Option<crate::api::scheduling::v1alpha3::WorkloadPodGroupSchedulingPolicy>,
17}
18
19impl crate::DeepMerge for JobSchedulingConfiguration {
20    fn merge_from(&mut self, other: Self) {
21        crate::DeepMerge::merge_from(&mut self.disruption_mode, other.disruption_mode);
22        crate::merge_strategies::list::map(
23            &mut self.resource_claims,
24            other.resource_claims,
25            &[|lhs, rhs| lhs.name == rhs.name],
26            |current_item, other_item| {
27                crate::DeepMerge::merge_from(current_item, other_item);
28            },
29        );
30        crate::DeepMerge::merge_from(&mut self.scheduling_constraints, other.scheduling_constraints);
31        crate::DeepMerge::merge_from(&mut self.scheduling_policy, other.scheduling_policy);
32    }
33}
34
35impl<'de> crate::serde::Deserialize<'de> for JobSchedulingConfiguration {
36    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
37        #[allow(non_camel_case_types)]
38        enum Field {
39            Key_disruption_mode,
40            Key_resource_claims,
41            Key_scheduling_constraints,
42            Key_scheduling_policy,
43            Other,
44        }
45
46        impl<'de> crate::serde::Deserialize<'de> for Field {
47            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
48                struct Visitor;
49
50                impl crate::serde::de::Visitor<'_> for Visitor {
51                    type Value = Field;
52
53                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
54                        f.write_str("field identifier")
55                    }
56
57                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
58                        Ok(match v {
59                            "disruptionMode" => Field::Key_disruption_mode,
60                            "resourceClaims" => Field::Key_resource_claims,
61                            "schedulingConstraints" => Field::Key_scheduling_constraints,
62                            "schedulingPolicy" => Field::Key_scheduling_policy,
63                            _ => Field::Other,
64                        })
65                    }
66                }
67
68                deserializer.deserialize_identifier(Visitor)
69            }
70        }
71
72        struct Visitor;
73
74        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
75            type Value = JobSchedulingConfiguration;
76
77            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
78                f.write_str("JobSchedulingConfiguration")
79            }
80
81            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
82                let mut value_disruption_mode: Option<crate::api::scheduling::v1alpha3::WorkloadPodGroupDisruptionMode> = None;
83                let mut value_resource_claims: Option<std::vec::Vec<crate::api::scheduling::v1alpha3::WorkloadPodGroupResourceClaim>> = None;
84                let mut value_scheduling_constraints: Option<crate::api::scheduling::v1alpha3::WorkloadPodGroupSchedulingConstraints> = None;
85                let mut value_scheduling_policy: Option<crate::api::scheduling::v1alpha3::WorkloadPodGroupSchedulingPolicy> = None;
86
87                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
88                    match key {
89                        Field::Key_disruption_mode => value_disruption_mode = crate::serde::de::MapAccess::next_value(&mut map)?,
90                        Field::Key_resource_claims => value_resource_claims = crate::serde::de::MapAccess::next_value(&mut map)?,
91                        Field::Key_scheduling_constraints => value_scheduling_constraints = crate::serde::de::MapAccess::next_value(&mut map)?,
92                        Field::Key_scheduling_policy => value_scheduling_policy = crate::serde::de::MapAccess::next_value(&mut map)?,
93                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
94                    }
95                }
96
97                Ok(JobSchedulingConfiguration {
98                    disruption_mode: value_disruption_mode,
99                    resource_claims: value_resource_claims,
100                    scheduling_constraints: value_scheduling_constraints,
101                    scheduling_policy: value_scheduling_policy,
102                })
103            }
104        }
105
106        deserializer.deserialize_struct(
107            "JobSchedulingConfiguration",
108            &[
109                "disruptionMode",
110                "resourceClaims",
111                "schedulingConstraints",
112                "schedulingPolicy",
113            ],
114            Visitor,
115        )
116    }
117}
118
119impl crate::serde::Serialize for JobSchedulingConfiguration {
120    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
121        let mut state = serializer.serialize_struct(
122            "JobSchedulingConfiguration",
123            self.disruption_mode.as_ref().map_or(0, |_| 1) +
124            self.resource_claims.as_ref().map_or(0, |_| 1) +
125            self.scheduling_constraints.as_ref().map_or(0, |_| 1) +
126            self.scheduling_policy.as_ref().map_or(0, |_| 1),
127        )?;
128        if let Some(value) = &self.disruption_mode {
129            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "disruptionMode", value)?;
130        }
131        if let Some(value) = &self.resource_claims {
132            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resourceClaims", value)?;
133        }
134        if let Some(value) = &self.scheduling_constraints {
135            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "schedulingConstraints", value)?;
136        }
137        if let Some(value) = &self.scheduling_policy {
138            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "schedulingPolicy", value)?;
139        }
140        crate::serde::ser::SerializeStruct::end(state)
141    }
142}
143
144#[cfg(feature = "schemars")]
145impl crate::schemars::JsonSchema for JobSchedulingConfiguration {
146    fn schema_name() -> std::borrow::Cow<'static, str> {
147        "io.k8s.api.batch.v1.JobSchedulingConfiguration".into()
148    }
149
150    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
151        crate::schemars::json_schema!({
152            "description": "JobSchedulingConfiguration composes the reusable workload-aware scheduling building blocks.",
153            "type": "object",
154            "properties": {
155                "disruptionMode": ({
156                    let mut schema_obj = __gen.subschema_for::<crate::api::scheduling::v1alpha3::WorkloadPodGroupDisruptionMode>();
157                    schema_obj.ensure_object().insert("description".into(), "DisruptionMode defines the mode in which the Job's pods can be disrupted. One of Single, All. This field is immutable after creation: it may not be added or removed, and the selected mode may not be changed.".into());
158                    schema_obj
159                }),
160                "resourceClaims": {
161                    "description": "ResourceClaims defines which ResourceClaims may be shared among Pods in the Job. 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. At most 4 claims may be set, matching the limit on the resulting PodGroup. This list is immutable after creation: entries may neither be added, removed, nor modified.",
162                    "type": "array",
163                    "items": (__gen.subschema_for::<crate::api::scheduling::v1alpha3::WorkloadPodGroupResourceClaim>()),
164                },
165                "schedulingConstraints": ({
166                    let mut schema_obj = __gen.subschema_for::<crate::api::scheduling::v1alpha3::WorkloadPodGroupSchedulingConstraints>();
167                    schema_obj.ensure_object().insert("description".into(), "SchedulingConstraints defines scheduling constraints (e.g. topology) for the Job's pods. This field is immutable after creation.".into());
168                    schema_obj
169                }),
170                "schedulingPolicy": ({
171                    let mut schema_obj = __gen.subschema_for::<crate::api::scheduling::v1alpha3::WorkloadPodGroupSchedulingPolicy>();
172                    schema_obj.ensure_object().insert("description".into(), "SchedulingPolicy defines the scheduling policy for this Job. Exactly one of Basic or Gang must be set. This field is immutable after creation: the policy may not be added or removed. The policy variant (basic/gang) is frozen by hand-written validation; only schedulingPolicy.gang.minCount may be changed.".into());
173                    schema_obj
174                }),
175            },
176        })
177    }
178}