Skip to main content

k8s_openapi/v1_36/api/scheduling/v1alpha2/
workload_spec.rs

1// Generated from definition io.k8s.api.scheduling.v1alpha2.WorkloadSpec
2
3/// WorkloadSpec defines the desired state of a Workload.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct WorkloadSpec {
6    /// 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.
7    pub controller_ref: Option<crate::api::scheduling::v1alpha2::TypedLocalObjectReference>,
8
9    /// PodGroupTemplates is the list of templates that make up the Workload. The maximum number of templates is 8. This field is immutable.
10    pub pod_group_templates: std::vec::Vec<crate::api::scheduling::v1alpha2::PodGroupTemplate>,
11}
12
13impl crate::DeepMerge for WorkloadSpec {
14    fn merge_from(&mut self, other: Self) {
15        crate::DeepMerge::merge_from(&mut self.controller_ref, other.controller_ref);
16        crate::merge_strategies::list::map(
17            &mut self.pod_group_templates,
18            other.pod_group_templates,
19            &[|lhs, rhs| lhs.name == rhs.name],
20            |current_item, other_item| {
21                crate::DeepMerge::merge_from(current_item, other_item);
22            },
23        );
24    }
25}
26
27impl<'de> crate::serde::Deserialize<'de> for WorkloadSpec {
28    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
29        #[allow(non_camel_case_types)]
30        enum Field {
31            Key_controller_ref,
32            Key_pod_group_templates,
33            Other,
34        }
35
36        impl<'de> crate::serde::Deserialize<'de> for Field {
37            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
38                struct Visitor;
39
40                impl crate::serde::de::Visitor<'_> for Visitor {
41                    type Value = Field;
42
43                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
44                        f.write_str("field identifier")
45                    }
46
47                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
48                        Ok(match v {
49                            "controllerRef" => Field::Key_controller_ref,
50                            "podGroupTemplates" => Field::Key_pod_group_templates,
51                            _ => Field::Other,
52                        })
53                    }
54                }
55
56                deserializer.deserialize_identifier(Visitor)
57            }
58        }
59
60        struct Visitor;
61
62        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
63            type Value = WorkloadSpec;
64
65            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
66                f.write_str("WorkloadSpec")
67            }
68
69            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
70                let mut value_controller_ref: Option<crate::api::scheduling::v1alpha2::TypedLocalObjectReference> = None;
71                let mut value_pod_group_templates: Option<std::vec::Vec<crate::api::scheduling::v1alpha2::PodGroupTemplate>> = None;
72
73                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
74                    match key {
75                        Field::Key_controller_ref => value_controller_ref = crate::serde::de::MapAccess::next_value(&mut map)?,
76                        Field::Key_pod_group_templates => value_pod_group_templates = crate::serde::de::MapAccess::next_value(&mut map)?,
77                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
78                    }
79                }
80
81                Ok(WorkloadSpec {
82                    controller_ref: value_controller_ref,
83                    pod_group_templates: value_pod_group_templates.unwrap_or_default(),
84                })
85            }
86        }
87
88        deserializer.deserialize_struct(
89            "WorkloadSpec",
90            &[
91                "controllerRef",
92                "podGroupTemplates",
93            ],
94            Visitor,
95        )
96    }
97}
98
99impl crate::serde::Serialize for WorkloadSpec {
100    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
101        let mut state = serializer.serialize_struct(
102            "WorkloadSpec",
103            1 +
104            self.controller_ref.as_ref().map_or(0, |_| 1),
105        )?;
106        if let Some(value) = &self.controller_ref {
107            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "controllerRef", value)?;
108        }
109        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "podGroupTemplates", &self.pod_group_templates)?;
110        crate::serde::ser::SerializeStruct::end(state)
111    }
112}
113
114#[cfg(feature = "schemars")]
115impl crate::schemars::JsonSchema for WorkloadSpec {
116    fn schema_name() -> std::borrow::Cow<'static, str> {
117        "io.k8s.api.scheduling.v1alpha2.WorkloadSpec".into()
118    }
119
120    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
121        crate::schemars::json_schema!({
122            "description": "WorkloadSpec defines the desired state of a Workload.",
123            "type": "object",
124            "properties": {
125                "controllerRef": ({
126                    let mut schema_obj = __gen.subschema_for::<crate::api::scheduling::v1alpha2::TypedLocalObjectReference>();
127                    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());
128                    schema_obj
129                }),
130                "podGroupTemplates": {
131                    "description": "PodGroupTemplates is the list of templates that make up the Workload. The maximum number of templates is 8. This field is immutable.",
132                    "type": "array",
133                    "items": (__gen.subschema_for::<crate::api::scheduling::v1alpha2::PodGroupTemplate>()),
134                },
135            },
136            "required": [
137                "podGroupTemplates",
138            ],
139        })
140    }
141}
142
143#[cfg(feature = "schemars08")]
144impl crate::schemars08::JsonSchema for WorkloadSpec {
145    fn schema_name() -> std::string::String {
146        "io.k8s.api.scheduling.v1alpha2.WorkloadSpec".into()
147    }
148
149    fn json_schema(__gen: &mut crate::schemars08::gen::SchemaGenerator) -> crate::schemars08::schema::Schema {
150        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
151            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
152                description: Some("WorkloadSpec defines the desired state of a Workload.".into()),
153                ..Default::default()
154            })),
155            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Object))),
156            object: Some(std::boxed::Box::new(crate::schemars08::schema::ObjectValidation {
157                properties: [
158                    (
159                        "controllerRef".into(),
160                        {
161                            let mut schema_obj = __gen.subschema_for::<crate::api::scheduling::v1alpha2::TypedLocalObjectReference>().into_object();
162                            schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
163                                description: Some("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()),
164                                ..Default::default()
165                            }));
166                            crate::schemars08::schema::Schema::Object(schema_obj)
167                        },
168                    ),
169                    (
170                        "podGroupTemplates".into(),
171                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
172                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
173                                description: Some("PodGroupTemplates is the list of templates that make up the Workload. The maximum number of templates is 8. This field is immutable.".into()),
174                                ..Default::default()
175                            })),
176                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Array))),
177                            array: Some(std::boxed::Box::new(crate::schemars08::schema::ArrayValidation {
178                                items: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::scheduling::v1alpha2::PodGroupTemplate>()))),
179                                ..Default::default()
180                            })),
181                            ..Default::default()
182                        }),
183                    ),
184                ].into(),
185                required: [
186                    "podGroupTemplates".into(),
187                ].into(),
188                ..Default::default()
189            })),
190            ..Default::default()
191        })
192    }
193}