1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct JobSpec {
6 pub active_deadline_seconds: Option<i64>,
8
9 pub backoff_limit: Option<i32>,
11
12 pub backoff_limit_per_index: Option<i32>,
14
15 pub completion_mode: Option<std::string::String>,
23
24 pub completions: Option<i32>,
26
27 pub managed_by: Option<std::string::String>,
29
30 pub manual_selector: Option<bool>,
32
33 pub max_failed_indexes: Option<i32>,
35
36 pub parallelism: Option<i32>,
38
39 pub pod_failure_policy: Option<crate::api::batch::v1::PodFailurePolicy>,
41
42 pub pod_replacement_policy: Option<std::string::String>,
49
50 pub scheduling: Option<crate::api::batch::v1::JobSchedulingConfiguration>,
52
53 pub selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>,
55
56 pub success_policy: Option<crate::api::batch::v1::SuccessPolicy>,
58
59 pub suspend: Option<bool>,
61
62 pub template: crate::api::core::v1::PodTemplateSpec,
64
65 pub ttl_seconds_after_finished: Option<i32>,
67}
68
69impl crate::DeepMerge for JobSpec {
70 fn merge_from(&mut self, other: Self) {
71 crate::DeepMerge::merge_from(&mut self.active_deadline_seconds, other.active_deadline_seconds);
72 crate::DeepMerge::merge_from(&mut self.backoff_limit, other.backoff_limit);
73 crate::DeepMerge::merge_from(&mut self.backoff_limit_per_index, other.backoff_limit_per_index);
74 crate::DeepMerge::merge_from(&mut self.completion_mode, other.completion_mode);
75 crate::DeepMerge::merge_from(&mut self.completions, other.completions);
76 crate::DeepMerge::merge_from(&mut self.managed_by, other.managed_by);
77 crate::DeepMerge::merge_from(&mut self.manual_selector, other.manual_selector);
78 crate::DeepMerge::merge_from(&mut self.max_failed_indexes, other.max_failed_indexes);
79 crate::DeepMerge::merge_from(&mut self.parallelism, other.parallelism);
80 crate::DeepMerge::merge_from(&mut self.pod_failure_policy, other.pod_failure_policy);
81 crate::DeepMerge::merge_from(&mut self.pod_replacement_policy, other.pod_replacement_policy);
82 crate::DeepMerge::merge_from(&mut self.scheduling, other.scheduling);
83 crate::DeepMerge::merge_from(&mut self.selector, other.selector);
84 crate::DeepMerge::merge_from(&mut self.success_policy, other.success_policy);
85 crate::DeepMerge::merge_from(&mut self.suspend, other.suspend);
86 crate::DeepMerge::merge_from(&mut self.template, other.template);
87 crate::DeepMerge::merge_from(&mut self.ttl_seconds_after_finished, other.ttl_seconds_after_finished);
88 }
89}
90
91impl<'de> crate::serde::Deserialize<'de> for JobSpec {
92 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
93 #[allow(non_camel_case_types)]
94 enum Field {
95 Key_active_deadline_seconds,
96 Key_backoff_limit,
97 Key_backoff_limit_per_index,
98 Key_completion_mode,
99 Key_completions,
100 Key_managed_by,
101 Key_manual_selector,
102 Key_max_failed_indexes,
103 Key_parallelism,
104 Key_pod_failure_policy,
105 Key_pod_replacement_policy,
106 Key_scheduling,
107 Key_selector,
108 Key_success_policy,
109 Key_suspend,
110 Key_template,
111 Key_ttl_seconds_after_finished,
112 Other,
113 }
114
115 impl<'de> crate::serde::Deserialize<'de> for Field {
116 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
117 struct Visitor;
118
119 impl crate::serde::de::Visitor<'_> for Visitor {
120 type Value = Field;
121
122 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
123 f.write_str("field identifier")
124 }
125
126 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
127 Ok(match v {
128 "activeDeadlineSeconds" => Field::Key_active_deadline_seconds,
129 "backoffLimit" => Field::Key_backoff_limit,
130 "backoffLimitPerIndex" => Field::Key_backoff_limit_per_index,
131 "completionMode" => Field::Key_completion_mode,
132 "completions" => Field::Key_completions,
133 "managedBy" => Field::Key_managed_by,
134 "manualSelector" => Field::Key_manual_selector,
135 "maxFailedIndexes" => Field::Key_max_failed_indexes,
136 "parallelism" => Field::Key_parallelism,
137 "podFailurePolicy" => Field::Key_pod_failure_policy,
138 "podReplacementPolicy" => Field::Key_pod_replacement_policy,
139 "scheduling" => Field::Key_scheduling,
140 "selector" => Field::Key_selector,
141 "successPolicy" => Field::Key_success_policy,
142 "suspend" => Field::Key_suspend,
143 "template" => Field::Key_template,
144 "ttlSecondsAfterFinished" => Field::Key_ttl_seconds_after_finished,
145 _ => Field::Other,
146 })
147 }
148 }
149
150 deserializer.deserialize_identifier(Visitor)
151 }
152 }
153
154 struct Visitor;
155
156 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
157 type Value = JobSpec;
158
159 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
160 f.write_str("JobSpec")
161 }
162
163 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
164 let mut value_active_deadline_seconds: Option<i64> = None;
165 let mut value_backoff_limit: Option<i32> = None;
166 let mut value_backoff_limit_per_index: Option<i32> = None;
167 let mut value_completion_mode: Option<std::string::String> = None;
168 let mut value_completions: Option<i32> = None;
169 let mut value_managed_by: Option<std::string::String> = None;
170 let mut value_manual_selector: Option<bool> = None;
171 let mut value_max_failed_indexes: Option<i32> = None;
172 let mut value_parallelism: Option<i32> = None;
173 let mut value_pod_failure_policy: Option<crate::api::batch::v1::PodFailurePolicy> = None;
174 let mut value_pod_replacement_policy: Option<std::string::String> = None;
175 let mut value_scheduling: Option<crate::api::batch::v1::JobSchedulingConfiguration> = None;
176 let mut value_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector> = None;
177 let mut value_success_policy: Option<crate::api::batch::v1::SuccessPolicy> = None;
178 let mut value_suspend: Option<bool> = None;
179 let mut value_template: Option<crate::api::core::v1::PodTemplateSpec> = None;
180 let mut value_ttl_seconds_after_finished: Option<i32> = None;
181
182 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
183 match key {
184 Field::Key_active_deadline_seconds => value_active_deadline_seconds = crate::serde::de::MapAccess::next_value(&mut map)?,
185 Field::Key_backoff_limit => value_backoff_limit = crate::serde::de::MapAccess::next_value(&mut map)?,
186 Field::Key_backoff_limit_per_index => value_backoff_limit_per_index = crate::serde::de::MapAccess::next_value(&mut map)?,
187 Field::Key_completion_mode => value_completion_mode = crate::serde::de::MapAccess::next_value(&mut map)?,
188 Field::Key_completions => value_completions = crate::serde::de::MapAccess::next_value(&mut map)?,
189 Field::Key_managed_by => value_managed_by = crate::serde::de::MapAccess::next_value(&mut map)?,
190 Field::Key_manual_selector => value_manual_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
191 Field::Key_max_failed_indexes => value_max_failed_indexes = crate::serde::de::MapAccess::next_value(&mut map)?,
192 Field::Key_parallelism => value_parallelism = crate::serde::de::MapAccess::next_value(&mut map)?,
193 Field::Key_pod_failure_policy => value_pod_failure_policy = crate::serde::de::MapAccess::next_value(&mut map)?,
194 Field::Key_pod_replacement_policy => value_pod_replacement_policy = crate::serde::de::MapAccess::next_value(&mut map)?,
195 Field::Key_scheduling => value_scheduling = crate::serde::de::MapAccess::next_value(&mut map)?,
196 Field::Key_selector => value_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
197 Field::Key_success_policy => value_success_policy = crate::serde::de::MapAccess::next_value(&mut map)?,
198 Field::Key_suspend => value_suspend = crate::serde::de::MapAccess::next_value(&mut map)?,
199 Field::Key_template => value_template = crate::serde::de::MapAccess::next_value(&mut map)?,
200 Field::Key_ttl_seconds_after_finished => value_ttl_seconds_after_finished = crate::serde::de::MapAccess::next_value(&mut map)?,
201 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
202 }
203 }
204
205 Ok(JobSpec {
206 active_deadline_seconds: value_active_deadline_seconds,
207 backoff_limit: value_backoff_limit,
208 backoff_limit_per_index: value_backoff_limit_per_index,
209 completion_mode: value_completion_mode,
210 completions: value_completions,
211 managed_by: value_managed_by,
212 manual_selector: value_manual_selector,
213 max_failed_indexes: value_max_failed_indexes,
214 parallelism: value_parallelism,
215 pod_failure_policy: value_pod_failure_policy,
216 pod_replacement_policy: value_pod_replacement_policy,
217 scheduling: value_scheduling,
218 selector: value_selector,
219 success_policy: value_success_policy,
220 suspend: value_suspend,
221 template: value_template.unwrap_or_default(),
222 ttl_seconds_after_finished: value_ttl_seconds_after_finished,
223 })
224 }
225 }
226
227 deserializer.deserialize_struct(
228 "JobSpec",
229 &[
230 "activeDeadlineSeconds",
231 "backoffLimit",
232 "backoffLimitPerIndex",
233 "completionMode",
234 "completions",
235 "managedBy",
236 "manualSelector",
237 "maxFailedIndexes",
238 "parallelism",
239 "podFailurePolicy",
240 "podReplacementPolicy",
241 "scheduling",
242 "selector",
243 "successPolicy",
244 "suspend",
245 "template",
246 "ttlSecondsAfterFinished",
247 ],
248 Visitor,
249 )
250 }
251}
252
253impl crate::serde::Serialize for JobSpec {
254 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
255 let mut state = serializer.serialize_struct(
256 "JobSpec",
257 1 +
258 self.active_deadline_seconds.as_ref().map_or(0, |_| 1) +
259 self.backoff_limit.as_ref().map_or(0, |_| 1) +
260 self.backoff_limit_per_index.as_ref().map_or(0, |_| 1) +
261 self.completion_mode.as_ref().map_or(0, |_| 1) +
262 self.completions.as_ref().map_or(0, |_| 1) +
263 self.managed_by.as_ref().map_or(0, |_| 1) +
264 self.manual_selector.as_ref().map_or(0, |_| 1) +
265 self.max_failed_indexes.as_ref().map_or(0, |_| 1) +
266 self.parallelism.as_ref().map_or(0, |_| 1) +
267 self.pod_failure_policy.as_ref().map_or(0, |_| 1) +
268 self.pod_replacement_policy.as_ref().map_or(0, |_| 1) +
269 self.scheduling.as_ref().map_or(0, |_| 1) +
270 self.selector.as_ref().map_or(0, |_| 1) +
271 self.success_policy.as_ref().map_or(0, |_| 1) +
272 self.suspend.as_ref().map_or(0, |_| 1) +
273 self.ttl_seconds_after_finished.as_ref().map_or(0, |_| 1),
274 )?;
275 if let Some(value) = &self.active_deadline_seconds {
276 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "activeDeadlineSeconds", value)?;
277 }
278 if let Some(value) = &self.backoff_limit {
279 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "backoffLimit", value)?;
280 }
281 if let Some(value) = &self.backoff_limit_per_index {
282 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "backoffLimitPerIndex", value)?;
283 }
284 if let Some(value) = &self.completion_mode {
285 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "completionMode", value)?;
286 }
287 if let Some(value) = &self.completions {
288 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "completions", value)?;
289 }
290 if let Some(value) = &self.managed_by {
291 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "managedBy", value)?;
292 }
293 if let Some(value) = &self.manual_selector {
294 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "manualSelector", value)?;
295 }
296 if let Some(value) = &self.max_failed_indexes {
297 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "maxFailedIndexes", value)?;
298 }
299 if let Some(value) = &self.parallelism {
300 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "parallelism", value)?;
301 }
302 if let Some(value) = &self.pod_failure_policy {
303 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "podFailurePolicy", value)?;
304 }
305 if let Some(value) = &self.pod_replacement_policy {
306 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "podReplacementPolicy", value)?;
307 }
308 if let Some(value) = &self.scheduling {
309 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "scheduling", value)?;
310 }
311 if let Some(value) = &self.selector {
312 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "selector", value)?;
313 }
314 if let Some(value) = &self.success_policy {
315 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "successPolicy", value)?;
316 }
317 if let Some(value) = &self.suspend {
318 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "suspend", value)?;
319 }
320 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "template", &self.template)?;
321 if let Some(value) = &self.ttl_seconds_after_finished {
322 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "ttlSecondsAfterFinished", value)?;
323 }
324 crate::serde::ser::SerializeStruct::end(state)
325 }
326}
327
328#[cfg(feature = "schemars")]
329impl crate::schemars::JsonSchema for JobSpec {
330 fn schema_name() -> std::borrow::Cow<'static, str> {
331 "io.k8s.api.batch.v1.JobSpec".into()
332 }
333
334 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
335 crate::schemars::json_schema!({
336 "description": "JobSpec describes how the job execution will look like.",
337 "type": "object",
338 "properties": {
339 "activeDeadlineSeconds": {
340 "description": "Specifies the duration in seconds relative to the startTime that the job may be continuously active before the system tries to terminate it; value must be positive integer. If a Job is suspended (at creation or through an update), this timer will effectively be stopped and reset when the Job is resumed again.",
341 "type": "integer",
342 "format": "int64",
343 },
344 "backoffLimit": {
345 "description": "Specifies the number of retries before marking this job failed. Defaults to 6, unless backoffLimitPerIndex (only Indexed Job) is specified. When backoffLimitPerIndex is specified, backoffLimit defaults to 2147483647.",
346 "type": "integer",
347 "format": "int32",
348 },
349 "backoffLimitPerIndex": {
350 "description": "Specifies the limit for the number of retries within an index before marking this index as failed. When enabled the number of failures per index is kept in the pod's batch.kubernetes.io/job-index-failure-count annotation. It can only be set when Job's completionMode=Indexed, and the Pod's restart policy is Never. The field is immutable.",
351 "type": "integer",
352 "format": "int32",
353 },
354 "completionMode": {
355 "description": "completionMode specifies how Pod completions are tracked. It can be `NonIndexed` (default) or `Indexed`.\n\n`NonIndexed` means that the Job is considered complete when there have been .spec.completions successfully completed Pods. Each Pod completion is homologous to each other.\n\n`Indexed` means that the Pods of a Job get an associated completion index from 0 to (.spec.completions - 1), available in the annotation batch.kubernetes.io/job-completion-index. The Job is considered complete when there is one successfully completed Pod for each index. When value is `Indexed`, .spec.completions must be specified and `.spec.parallelism` must be less than or equal to 10^5. In addition, The Pod name takes the form `$(job-name)-$(index)-$(random-string)`, the Pod hostname takes the form `$(job-name)-$(index)`.\n\nMore completion modes can be added in the future. If the Job controller observes a mode that it doesn't recognize, which is possible during upgrades due to version skew, the controller skips updates for the Job.",
356 "type": "string",
357 },
358 "completions": {
359 "description": "Specifies the desired number of successfully finished pods the job should be run with. Setting to null means that the success of any pod signals the success of all pods, and allows parallelism to have any positive value. Setting to 1 means that parallelism is limited to 1 and the success of that pod signals the success of the job. More info: https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/",
360 "type": "integer",
361 "format": "int32",
362 },
363 "managedBy": {
364 "description": "ManagedBy field indicates the controller that manages a Job. The k8s Job controller reconciles jobs which don't have this field at all or the field value is the reserved string `kubernetes.io/job-controller`, but skips reconciling Jobs with a custom value for this field. The value must be a valid domain-prefixed path (e.g. acme.io/foo) - all characters before the first \"/\" must be a valid subdomain as defined by RFC 1123. All characters trailing the first \"/\" must be valid HTTP Path characters as defined by RFC 3986. The value cannot exceed 63 characters. This field is immutable.",
365 "type": "string",
366 },
367 "manualSelector": {
368 "description": "manualSelector controls generation of pod labels and pod selectors. Leave `manualSelector` unset unless you are certain what you are doing. When false or unset, the system pick labels unique to this job and appends those labels to the pod template. When true, the user is responsible for picking unique labels and specifying the selector. Failure to pick a unique label may cause this and other jobs to not function correctly. However, You may see `manualSelector=true` in jobs that were created with the old `extensions/v1beta1` API. More info: https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/#specifying-your-own-pod-selector",
369 "type": "boolean",
370 },
371 "maxFailedIndexes": {
372 "description": "Specifies the maximal number of failed indexes before marking the Job as failed, when backoffLimitPerIndex is set. Once the number of failed indexes exceeds this number the entire Job is marked as Failed and its execution is terminated. When left as null the job continues execution of all of its indexes and is marked with the `Complete` Job condition. It can only be specified when backoffLimitPerIndex is set. It can be null or up to completions. It is required and must be less than or equal to 10^4 when is completions greater than 10^5.",
373 "type": "integer",
374 "format": "int32",
375 },
376 "parallelism": {
377 "description": "Specifies the maximum desired number of pods the job should run at any given time. The actual number of pods running in steady state will be less than this number when ((.spec.completions - .status.successful) < .spec.parallelism), i.e. when the work left to do is less than max parallelism. More info: https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/",
378 "type": "integer",
379 "format": "int32",
380 },
381 "podFailurePolicy": ({
382 let mut schema_obj = __gen.subschema_for::<crate::api::batch::v1::PodFailurePolicy>();
383 schema_obj.ensure_object().insert("description".into(), "Specifies the policy of handling failed pods. In particular, it allows to specify the set of actions and conditions which need to be satisfied to take the associated action. If empty, the default behaviour applies - the counter of failed pods, represented by the jobs's .status.failed field, is incremented and it is checked against the backoffLimit. This field cannot be used in combination with restartPolicy=OnFailure.".into());
384 schema_obj
385 }),
386 "podReplacementPolicy": {
387 "description": "podReplacementPolicy specifies when to create replacement Pods. Possible values are: - TerminatingOrFailed means that we recreate pods\n when they are terminating (has a metadata.deletionTimestamp) or failed.\n- Failed means to wait until a previously created Pod is fully terminated (has phase\n Failed or Succeeded) before creating a replacement Pod.\n\nWhen using podFailurePolicy, Failed is the the only allowed value. TerminatingOrFailed and Failed are allowed values when podFailurePolicy is not in use.",
388 "type": "string",
389 },
390 "scheduling": ({
391 let mut schema_obj = __gen.subschema_for::<crate::api::batch::v1::JobSchedulingConfiguration>();
392 schema_obj.ensure_object().insert("description".into(), "scheduling defines the Workload-aware Scheduling configuration for this Job. When set, it specifies the scheduling policy (basic or gang), topology constraints, disruption mode, and shared resource claims. When omitted, the Job defaults to the basic scheduling policy, which behaves as standard pod-by-pod scheduling. This field is alpha-level and requires the WorkloadWithJob feature gate. This field is immutable, including whether it is set at all, only policy.gang.minCount may be changed after creation.".into());
393 schema_obj
394 }),
395 "selector": ({
396 let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>();
397 schema_obj.ensure_object().insert("description".into(), "A label query over pods that should match the pod count. Normally, the system sets this field for you. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors".into());
398 schema_obj
399 }),
400 "successPolicy": ({
401 let mut schema_obj = __gen.subschema_for::<crate::api::batch::v1::SuccessPolicy>();
402 schema_obj.ensure_object().insert("description".into(), "successPolicy specifies the policy when the Job can be declared as succeeded. If empty, the default behavior applies - the Job is declared as succeeded only when the number of succeeded pods equals to the completions. When the field is specified, it must be immutable and works only for the Indexed Jobs. Once the Job meets the SuccessPolicy, the lingering pods are terminated.".into());
403 schema_obj
404 }),
405 "suspend": {
406 "description": "suspend specifies whether the Job controller should create Pods or not. If a Job is created with suspend set to true, no Pods are created by the Job controller. If a Job is suspended after creation (i.e. the flag goes from false to true), the Job controller will delete all active Pods associated with this Job. Users must design their workload to gracefully handle this. Suspending a Job will reset the StartTime field of the Job, effectively resetting the ActiveDeadlineSeconds timer too. Defaults to false.",
407 "type": "boolean",
408 },
409 "template": ({
410 let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::PodTemplateSpec>();
411 schema_obj.ensure_object().insert("description".into(), "Describes the pod that will be created when executing a job. The only allowed template.spec.restartPolicy values are \"Never\" or \"OnFailure\". More info: https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/".into());
412 schema_obj
413 }),
414 "ttlSecondsAfterFinished": {
415 "description": "ttlSecondsAfterFinished limits the lifetime of a Job that has finished execution (either Complete or Failed). If this field is set, ttlSecondsAfterFinished after the Job finishes, it is eligible to be automatically deleted. When the Job is being deleted, its lifecycle guarantees (e.g. finalizers) will be honored. If this field is unset, the Job won't be automatically deleted. If this field is set to zero, the Job becomes eligible to be deleted immediately after it finishes.",
416 "type": "integer",
417 "format": "int32",
418 },
419 },
420 "required": [
421 "template",
422 ],
423 })
424 }
425}