Skip to main content

k8s_openapi/v1_36/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<std::string::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: std::string::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<std::string::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 crate::serde::de::Visitor<'_> for Visitor {
66                    type Value = Field;
67
68                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::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 core::fmt::Formatter<'_>) -> core::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<std::string::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<std::string::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<std::string::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() -> std::borrow::Cow<'static, str> {
193        "io.k8s.api.batch.v1.CronJobSpec".into()
194    }
195
196    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
197        crate::schemars::json_schema!({
198            "description": "CronJobSpec describes how the job execution will look like and when it will actually run.",
199            "type": "object",
200            "properties": {
201                "concurrencyPolicy": {
202                    "description": "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",
203                    "type": "string",
204                },
205                "failedJobsHistoryLimit": {
206                    "description": "The number of failed finished jobs to retain. Value must be non-negative integer. Defaults to 1.",
207                    "type": "integer",
208                    "format": "int32",
209                },
210                "jobTemplate": ({
211                    let mut schema_obj = __gen.subschema_for::<crate::api::batch::v1::JobTemplateSpec>();
212                    schema_obj.ensure_object().insert("description".into(), "Specifies the job that will be created when executing a CronJob.".into());
213                    schema_obj
214                }),
215                "schedule": {
216                    "description": "The schedule in Cron format, see https://en.wikipedia.org/wiki/Cron.",
217                    "type": "string",
218                },
219                "startingDeadlineSeconds": {
220                    "description": "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.",
221                    "type": "integer",
222                    "format": "int64",
223                },
224                "successfulJobsHistoryLimit": {
225                    "description": "The number of successful finished jobs to retain. Value must be non-negative integer. Defaults to 3.",
226                    "type": "integer",
227                    "format": "int32",
228                },
229                "suspend": {
230                    "description": "This flag tells the controller to suspend subsequent executions, it does not apply to already started executions.  Defaults to false.",
231                    "type": "boolean",
232                },
233                "timeZone": {
234                    "description": "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",
235                    "type": "string",
236                },
237            },
238            "required": [
239                "jobTemplate",
240                "schedule",
241            ],
242        })
243    }
244}
245
246#[cfg(feature = "schemars08")]
247impl crate::schemars08::JsonSchema for CronJobSpec {
248    fn schema_name() -> std::string::String {
249        "io.k8s.api.batch.v1.CronJobSpec".into()
250    }
251
252    fn json_schema(__gen: &mut crate::schemars08::gen::SchemaGenerator) -> crate::schemars08::schema::Schema {
253        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
254            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
255                description: Some("CronJobSpec describes how the job execution will look like and when it will actually run.".into()),
256                ..Default::default()
257            })),
258            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Object))),
259            object: Some(std::boxed::Box::new(crate::schemars08::schema::ObjectValidation {
260                properties: [
261                    (
262                        "concurrencyPolicy".into(),
263                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
264                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
265                                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".into()),
266                                ..Default::default()
267                            })),
268                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
269                            ..Default::default()
270                        }),
271                    ),
272                    (
273                        "failedJobsHistoryLimit".into(),
274                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
275                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
276                                description: Some("The number of failed finished jobs to retain. Value must be non-negative integer. Defaults to 1.".into()),
277                                ..Default::default()
278                            })),
279                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Integer))),
280                            format: Some("int32".into()),
281                            ..Default::default()
282                        }),
283                    ),
284                    (
285                        "jobTemplate".into(),
286                        {
287                            let mut schema_obj = __gen.subschema_for::<crate::api::batch::v1::JobTemplateSpec>().into_object();
288                            schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
289                                description: Some("Specifies the job that will be created when executing a CronJob.".into()),
290                                ..Default::default()
291                            }));
292                            crate::schemars08::schema::Schema::Object(schema_obj)
293                        },
294                    ),
295                    (
296                        "schedule".into(),
297                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
298                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
299                                description: Some("The schedule in Cron format, see https://en.wikipedia.org/wiki/Cron.".into()),
300                                ..Default::default()
301                            })),
302                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
303                            ..Default::default()
304                        }),
305                    ),
306                    (
307                        "startingDeadlineSeconds".into(),
308                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
309                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
310                                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.".into()),
311                                ..Default::default()
312                            })),
313                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Integer))),
314                            format: Some("int64".into()),
315                            ..Default::default()
316                        }),
317                    ),
318                    (
319                        "successfulJobsHistoryLimit".into(),
320                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
321                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
322                                description: Some("The number of successful finished jobs to retain. Value must be non-negative integer. Defaults to 3.".into()),
323                                ..Default::default()
324                            })),
325                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Integer))),
326                            format: Some("int32".into()),
327                            ..Default::default()
328                        }),
329                    ),
330                    (
331                        "suspend".into(),
332                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
333                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
334                                description: Some("This flag tells the controller to suspend subsequent executions, it does not apply to already started executions.  Defaults to false.".into()),
335                                ..Default::default()
336                            })),
337                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Boolean))),
338                            ..Default::default()
339                        }),
340                    ),
341                    (
342                        "timeZone".into(),
343                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
344                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
345                                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".into()),
346                                ..Default::default()
347                            })),
348                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
349                            ..Default::default()
350                        }),
351                    ),
352                ].into(),
353                required: [
354                    "jobTemplate".into(),
355                    "schedule".into(),
356                ].into(),
357                ..Default::default()
358            })),
359            ..Default::default()
360        })
361    }
362}