k8s_openapi/v1_30/api/batch/v1/
cron_job_spec.rs

1// Generated from definition io.k8s.api.batch.v1.CronJobSpec
2
3/// CronJobSpec describes how the job execution will look like and when it will actually run.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct CronJobSpec {
6    /// Specifies how to treat concurrent executions of a Job. Valid values are:
7    ///
8    /// - "Allow" (default): allows CronJobs to run concurrently; - "Forbid": forbids concurrent runs, skipping next run if previous run hasn't finished yet; - "Replace": cancels currently running job and replaces it with a new one
9    pub concurrency_policy: Option<String>,
10
11    /// The number of failed finished jobs to retain. Value must be non-negative integer. Defaults to 1.
12    pub failed_jobs_history_limit: Option<i32>,
13
14    /// Specifies the job that will be created when executing a CronJob.
15    pub job_template: crate::api::batch::v1::JobTemplateSpec,
16
17    /// The schedule in Cron format, see https://en.wikipedia.org/wiki/Cron.
18    pub schedule: String,
19
20    /// Optional deadline in seconds for starting the job if it misses scheduled time for any reason.  Missed jobs executions will be counted as failed ones.
21    pub starting_deadline_seconds: Option<i64>,
22
23    /// The number of successful finished jobs to retain. Value must be non-negative integer. Defaults to 3.
24    pub successful_jobs_history_limit: Option<i32>,
25
26    /// This flag tells the controller to suspend subsequent executions, it does not apply to already started executions.  Defaults to false.
27    pub suspend: Option<bool>,
28
29    /// The time zone name for the given schedule, see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones. If not specified, this will default to the time zone of the kube-controller-manager process. The set of valid time zone names and the time zone offset is loaded from the system-wide time zone database by the API server during CronJob validation and the controller manager during execution. If no system-wide time zone database can be found a bundled version of the database is used instead. If the time zone name becomes invalid during the lifetime of a CronJob or due to a change in host configuration, the controller will stop creating new new Jobs and will create a system event with the reason UnknownTimeZone. More information can be found in https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/#time-zones
30    pub time_zone: Option<String>,
31}
32
33impl crate::DeepMerge for CronJobSpec {
34    fn merge_from(&mut self, other: Self) {
35        crate::DeepMerge::merge_from(&mut self.concurrency_policy, other.concurrency_policy);
36        crate::DeepMerge::merge_from(&mut self.failed_jobs_history_limit, other.failed_jobs_history_limit);
37        crate::DeepMerge::merge_from(&mut self.job_template, other.job_template);
38        crate::DeepMerge::merge_from(&mut self.schedule, other.schedule);
39        crate::DeepMerge::merge_from(&mut self.starting_deadline_seconds, other.starting_deadline_seconds);
40        crate::DeepMerge::merge_from(&mut self.successful_jobs_history_limit, other.successful_jobs_history_limit);
41        crate::DeepMerge::merge_from(&mut self.suspend, other.suspend);
42        crate::DeepMerge::merge_from(&mut self.time_zone, other.time_zone);
43    }
44}
45
46impl<'de> crate::serde::Deserialize<'de> for CronJobSpec {
47    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
48        #[allow(non_camel_case_types)]
49        enum Field {
50            Key_concurrency_policy,
51            Key_failed_jobs_history_limit,
52            Key_job_template,
53            Key_schedule,
54            Key_starting_deadline_seconds,
55            Key_successful_jobs_history_limit,
56            Key_suspend,
57            Key_time_zone,
58            Other,
59        }
60
61        impl<'de> crate::serde::Deserialize<'de> for Field {
62            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
63                struct Visitor;
64
65                impl<'de> crate::serde::de::Visitor<'de> for Visitor {
66                    type Value = Field;
67
68                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
69                        f.write_str("field identifier")
70                    }
71
72                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
73                        Ok(match v {
74                            "concurrencyPolicy" => Field::Key_concurrency_policy,
75                            "failedJobsHistoryLimit" => Field::Key_failed_jobs_history_limit,
76                            "jobTemplate" => Field::Key_job_template,
77                            "schedule" => Field::Key_schedule,
78                            "startingDeadlineSeconds" => Field::Key_starting_deadline_seconds,
79                            "successfulJobsHistoryLimit" => Field::Key_successful_jobs_history_limit,
80                            "suspend" => Field::Key_suspend,
81                            "timeZone" => Field::Key_time_zone,
82                            _ => Field::Other,
83                        })
84                    }
85                }
86
87                deserializer.deserialize_identifier(Visitor)
88            }
89        }
90
91        struct Visitor;
92
93        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
94            type Value = CronJobSpec;
95
96            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
97                f.write_str("CronJobSpec")
98            }
99
100            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
101                let mut value_concurrency_policy: Option<String> = None;
102                let mut value_failed_jobs_history_limit: Option<i32> = None;
103                let mut value_job_template: Option<crate::api::batch::v1::JobTemplateSpec> = None;
104                let mut value_schedule: Option<String> = None;
105                let mut value_starting_deadline_seconds: Option<i64> = None;
106                let mut value_successful_jobs_history_limit: Option<i32> = None;
107                let mut value_suspend: Option<bool> = None;
108                let mut value_time_zone: Option<String> = None;
109
110                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
111                    match key {
112                        Field::Key_concurrency_policy => value_concurrency_policy = crate::serde::de::MapAccess::next_value(&mut map)?,
113                        Field::Key_failed_jobs_history_limit => value_failed_jobs_history_limit = crate::serde::de::MapAccess::next_value(&mut map)?,
114                        Field::Key_job_template => value_job_template = crate::serde::de::MapAccess::next_value(&mut map)?,
115                        Field::Key_schedule => value_schedule = crate::serde::de::MapAccess::next_value(&mut map)?,
116                        Field::Key_starting_deadline_seconds => value_starting_deadline_seconds = crate::serde::de::MapAccess::next_value(&mut map)?,
117                        Field::Key_successful_jobs_history_limit => value_successful_jobs_history_limit = crate::serde::de::MapAccess::next_value(&mut map)?,
118                        Field::Key_suspend => value_suspend = crate::serde::de::MapAccess::next_value(&mut map)?,
119                        Field::Key_time_zone => value_time_zone = crate::serde::de::MapAccess::next_value(&mut map)?,
120                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
121                    }
122                }
123
124                Ok(CronJobSpec {
125                    concurrency_policy: value_concurrency_policy,
126                    failed_jobs_history_limit: value_failed_jobs_history_limit,
127                    job_template: value_job_template.unwrap_or_default(),
128                    schedule: value_schedule.unwrap_or_default(),
129                    starting_deadline_seconds: value_starting_deadline_seconds,
130                    successful_jobs_history_limit: value_successful_jobs_history_limit,
131                    suspend: value_suspend,
132                    time_zone: value_time_zone,
133                })
134            }
135        }
136
137        deserializer.deserialize_struct(
138            "CronJobSpec",
139            &[
140                "concurrencyPolicy",
141                "failedJobsHistoryLimit",
142                "jobTemplate",
143                "schedule",
144                "startingDeadlineSeconds",
145                "successfulJobsHistoryLimit",
146                "suspend",
147                "timeZone",
148            ],
149            Visitor,
150        )
151    }
152}
153
154impl crate::serde::Serialize for CronJobSpec {
155    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
156        let mut state = serializer.serialize_struct(
157            "CronJobSpec",
158            2 +
159            self.concurrency_policy.as_ref().map_or(0, |_| 1) +
160            self.failed_jobs_history_limit.as_ref().map_or(0, |_| 1) +
161            self.starting_deadline_seconds.as_ref().map_or(0, |_| 1) +
162            self.successful_jobs_history_limit.as_ref().map_or(0, |_| 1) +
163            self.suspend.as_ref().map_or(0, |_| 1) +
164            self.time_zone.as_ref().map_or(0, |_| 1),
165        )?;
166        if let Some(value) = &self.concurrency_policy {
167            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "concurrencyPolicy", value)?;
168        }
169        if let Some(value) = &self.failed_jobs_history_limit {
170            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "failedJobsHistoryLimit", value)?;
171        }
172        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "jobTemplate", &self.job_template)?;
173        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "schedule", &self.schedule)?;
174        if let Some(value) = &self.starting_deadline_seconds {
175            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "startingDeadlineSeconds", value)?;
176        }
177        if let Some(value) = &self.successful_jobs_history_limit {
178            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "successfulJobsHistoryLimit", value)?;
179        }
180        if let Some(value) = &self.suspend {
181            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "suspend", value)?;
182        }
183        if let Some(value) = &self.time_zone {
184            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "timeZone", value)?;
185        }
186        crate::serde::ser::SerializeStruct::end(state)
187    }
188}
189
190#[cfg(feature = "schemars")]
191impl crate::schemars::JsonSchema for CronJobSpec {
192    fn schema_name() -> String {
193        "io.k8s.api.batch.v1.CronJobSpec".to_owned()
194    }
195
196    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
197        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
198            metadata: Some(Box::new(crate::schemars::schema::Metadata {
199                description: Some("CronJobSpec describes how the job execution will look like and when it will actually run.".to_owned()),
200                ..Default::default()
201            })),
202            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
203            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
204                properties: [
205                    (
206                        "concurrencyPolicy".to_owned(),
207                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
208                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
209                                description: Some("Specifies how to treat concurrent executions of a Job. Valid values are:\n\n- \"Allow\" (default): allows CronJobs to run concurrently; - \"Forbid\": forbids concurrent runs, skipping next run if previous run hasn't finished yet; - \"Replace\": cancels currently running job and replaces it with a new one".to_owned()),
210                                ..Default::default()
211                            })),
212                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
213                            ..Default::default()
214                        }),
215                    ),
216                    (
217                        "failedJobsHistoryLimit".to_owned(),
218                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
219                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
220                                description: Some("The number of failed finished jobs to retain. Value must be non-negative integer. Defaults to 1.".to_owned()),
221                                ..Default::default()
222                            })),
223                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Integer))),
224                            format: Some("int32".to_owned()),
225                            ..Default::default()
226                        }),
227                    ),
228                    (
229                        "jobTemplate".to_owned(),
230                        {
231                            let mut schema_obj = __gen.subschema_for::<crate::api::batch::v1::JobTemplateSpec>().into_object();
232                            schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
233                                description: Some("Specifies the job that will be created when executing a CronJob.".to_owned()),
234                                ..Default::default()
235                            }));
236                            crate::schemars::schema::Schema::Object(schema_obj)
237                        },
238                    ),
239                    (
240                        "schedule".to_owned(),
241                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
242                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
243                                description: Some("The schedule in Cron format, see https://en.wikipedia.org/wiki/Cron.".to_owned()),
244                                ..Default::default()
245                            })),
246                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
247                            ..Default::default()
248                        }),
249                    ),
250                    (
251                        "startingDeadlineSeconds".to_owned(),
252                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
253                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
254                                description: Some("Optional deadline in seconds for starting the job if it misses scheduled time for any reason.  Missed jobs executions will be counted as failed ones.".to_owned()),
255                                ..Default::default()
256                            })),
257                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Integer))),
258                            format: Some("int64".to_owned()),
259                            ..Default::default()
260                        }),
261                    ),
262                    (
263                        "successfulJobsHistoryLimit".to_owned(),
264                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
265                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
266                                description: Some("The number of successful finished jobs to retain. Value must be non-negative integer. Defaults to 3.".to_owned()),
267                                ..Default::default()
268                            })),
269                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Integer))),
270                            format: Some("int32".to_owned()),
271                            ..Default::default()
272                        }),
273                    ),
274                    (
275                        "suspend".to_owned(),
276                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
277                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
278                                description: Some("This flag tells the controller to suspend subsequent executions, it does not apply to already started executions.  Defaults to false.".to_owned()),
279                                ..Default::default()
280                            })),
281                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Boolean))),
282                            ..Default::default()
283                        }),
284                    ),
285                    (
286                        "timeZone".to_owned(),
287                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
288                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
289                                description: Some("The time zone name for the given schedule, see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones. If not specified, this will default to the time zone of the kube-controller-manager process. The set of valid time zone names and the time zone offset is loaded from the system-wide time zone database by the API server during CronJob validation and the controller manager during execution. If no system-wide time zone database can be found a bundled version of the database is used instead. If the time zone name becomes invalid during the lifetime of a CronJob or due to a change in host configuration, the controller will stop creating new new Jobs and will create a system event with the reason UnknownTimeZone. More information can be found in https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/#time-zones".to_owned()),
290                                ..Default::default()
291                            })),
292                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
293                            ..Default::default()
294                        }),
295                    ),
296                ].into(),
297                required: [
298                    "jobTemplate".to_owned(),
299                    "schedule".to_owned(),
300                ].into(),
301                ..Default::default()
302            })),
303            ..Default::default()
304        })
305    }
306}