Skip to main content

k8s_openapi/v1_37/api/scheduling/v1alpha3/
workload_spec.rs

1// Generated from definition io.k8s.api.scheduling.v1alpha3.WorkloadSpec
2
3/// WorkloadSpec defines the desired state of a Workload.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct WorkloadSpec {
6    /// compositePodGroupTemplates is the list of CompositePodGroup templates that make up the Workload. The maximum number of templates is 8. This field is immutable. Exactly one of CompositePodGroupTemplates and PodGroupTemplates must be set.
7    ///
8    /// This field is used only when the CompositePodGroup feature gate is enabled.
9    pub composite_pod_group_templates: Option<std::vec::Vec<crate::api::scheduling::v1alpha3::CompositePodGroupTemplate>>,
10
11    /// controllerRef is an optional reference to the controlling object, such as a Deployment or Job. This field is intended for use by tools like CLIs to provide a link back to the original workload definition. This field is immutable.
12    pub controller_ref: Option<crate::api::scheduling::v1alpha3::TypedLocalObjectReference>,
13
14    /// podGroupTemplates is the list of templates that make up the Workload. The maximum number of templates is 8. Templates cannot be added or removed after the workload is created. Existing templates may still be updated where their individual fields allow it. Exactly one of CompositePodGroupTemplates and PodGroupTemplates must be set.
15    pub pod_group_templates: Option<std::vec::Vec<crate::api::scheduling::v1alpha3::PodGroupTemplate>>,
16}
17
18impl crate::DeepMerge for WorkloadSpec {
19    fn merge_from(&mut self, other: Self) {
20        crate::merge_strategies::list::map(
21            &mut self.composite_pod_group_templates,
22            other.composite_pod_group_templates,
23            &[|lhs, rhs| lhs.name == rhs.name],
24            |current_item, other_item| {
25                crate::DeepMerge::merge_from(current_item, other_item);
26            },
27        );
28        crate::DeepMerge::merge_from(&mut self.controller_ref, other.controller_ref);
29        crate::merge_strategies::list::map(
30            &mut self.pod_group_templates,
31            other.pod_group_templates,
32            &[|lhs, rhs| lhs.name == rhs.name],
33            |current_item, other_item| {
34                crate::DeepMerge::merge_from(current_item, other_item);
35            },
36        );
37    }
38}
39
40impl<'de> crate::serde::Deserialize<'de> for WorkloadSpec {
41    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
42        #[allow(non_camel_case_types)]
43        enum Field {
44            Key_composite_pod_group_templates,
45            Key_controller_ref,
46            Key_pod_group_templates,
47            Other,
48        }
49
50        impl<'de> crate::serde::Deserialize<'de> for Field {
51            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
52                struct Visitor;
53
54                impl crate::serde::de::Visitor<'_> for Visitor {
55                    type Value = Field;
56
57                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
58                        f.write_str("field identifier")
59                    }
60
61                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
62                        Ok(match v {
63                            "compositePodGroupTemplates" => Field::Key_composite_pod_group_templates,
64                            "controllerRef" => Field::Key_controller_ref,
65                            "podGroupTemplates" => Field::Key_pod_group_templates,
66                            _ => Field::Other,
67                        })
68                    }
69                }
70
71                deserializer.deserialize_identifier(Visitor)
72            }
73        }
74
75        struct Visitor;
76
77        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
78            type Value = WorkloadSpec;
79
80            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
81                f.write_str("WorkloadSpec")
82            }
83
84            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
85                let mut value_composite_pod_group_templates: Option<std::vec::Vec<crate::api::scheduling::v1alpha3::CompositePodGroupTemplate>> = None;
86                let mut value_controller_ref: Option<crate::api::scheduling::v1alpha3::TypedLocalObjectReference> = None;
87                let mut value_pod_group_templates: Option<std::vec::Vec<crate::api::scheduling::v1alpha3::PodGroupTemplate>> = None;
88
89                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
90                    match key {
91                        Field::Key_composite_pod_group_templates => value_composite_pod_group_templates = crate::serde::de::MapAccess::next_value(&mut map)?,
92                        Field::Key_controller_ref => value_controller_ref = crate::serde::de::MapAccess::next_value(&mut map)?,
93                        Field::Key_pod_group_templates => value_pod_group_templates = crate::serde::de::MapAccess::next_value(&mut map)?,
94                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
95                    }
96                }
97
98                Ok(WorkloadSpec {
99                    composite_pod_group_templates: value_composite_pod_group_templates,
100                    controller_ref: value_controller_ref,
101                    pod_group_templates: value_pod_group_templates,
102                })
103            }
104        }
105
106        deserializer.deserialize_struct(
107            "WorkloadSpec",
108            &[
109                "compositePodGroupTemplates",
110                "controllerRef",
111                "podGroupTemplates",
112            ],
113            Visitor,
114        )
115    }
116}
117
118impl crate::serde::Serialize for WorkloadSpec {
119    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
120        let mut state = serializer.serialize_struct(
121            "WorkloadSpec",
122            self.composite_pod_group_templates.as_ref().map_or(0, |_| 1) +
123            self.controller_ref.as_ref().map_or(0, |_| 1) +
124            self.pod_group_templates.as_ref().map_or(0, |_| 1),
125        )?;
126        if let Some(value) = &self.composite_pod_group_templates {
127            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "compositePodGroupTemplates", value)?;
128        }
129        if let Some(value) = &self.controller_ref {
130            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "controllerRef", value)?;
131        }
132        if let Some(value) = &self.pod_group_templates {
133            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "podGroupTemplates", value)?;
134        }
135        crate::serde::ser::SerializeStruct::end(state)
136    }
137}
138
139#[cfg(feature = "schemars")]
140impl crate::schemars::JsonSchema for WorkloadSpec {
141    fn schema_name() -> std::borrow::Cow<'static, str> {
142        "io.k8s.api.scheduling.v1alpha3.WorkloadSpec".into()
143    }
144
145    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
146        crate::schemars::json_schema!({
147            "description": "WorkloadSpec defines the desired state of a Workload.",
148            "type": "object",
149            "properties": {
150                "compositePodGroupTemplates": {
151                    "description": "compositePodGroupTemplates is the list of CompositePodGroup templates that make up the Workload. The maximum number of templates is 8. This field is immutable. Exactly one of CompositePodGroupTemplates and PodGroupTemplates must be set.\n\nThis field is used only when the CompositePodGroup feature gate is enabled.",
152                    "type": "array",
153                    "items": (__gen.subschema_for::<crate::api::scheduling::v1alpha3::CompositePodGroupTemplate>()),
154                },
155                "controllerRef": ({
156                    let mut schema_obj = __gen.subschema_for::<crate::api::scheduling::v1alpha3::TypedLocalObjectReference>();
157                    schema_obj.ensure_object().insert("description".into(), "controllerRef is an optional reference to the controlling object, such as a Deployment or Job. This field is intended for use by tools like CLIs to provide a link back to the original workload definition. This field is immutable.".into());
158                    schema_obj
159                }),
160                "podGroupTemplates": {
161                    "description": "podGroupTemplates is the list of templates that make up the Workload. The maximum number of templates is 8. Templates cannot be added or removed after the workload is created. Existing templates may still be updated where their individual fields allow it. Exactly one of CompositePodGroupTemplates and PodGroupTemplates must be set.",
162                    "type": "array",
163                    "items": (__gen.subschema_for::<crate::api::scheduling::v1alpha3::PodGroupTemplate>()),
164                },
165            },
166        })
167    }
168}