k8s.io/kubernetes@v1.29.3/pkg/apis/batch/types.go (about)

     1  /*
     2  Copyright 2016 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package batch
    18  
    19  import (
    20  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    21  	"k8s.io/apimachinery/pkg/types"
    22  	api "k8s.io/kubernetes/pkg/apis/core"
    23  )
    24  
    25  const (
    26  	// Unprefixed labels are reserved for end-users
    27  	// so we will add a batch.kubernetes.io to designate these labels as official Kubernetes labels.
    28  	// See https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#label-selector-and-annotation-conventions
    29  	labelPrefix = "batch.kubernetes.io/"
    30  	// JobTrackingFinalizer is a finalizer for Job's pods. It prevents them from
    31  	// being deleted before being accounted in the Job status.
    32  	//
    33  	// Additionally, the apiserver and job controller use this string as a Job
    34  	// annotation, to mark Jobs that are being tracked using pod finalizers.
    35  	// However, this behavior is deprecated in kubernetes 1.26. This means that, in
    36  	// 1.27+, one release after JobTrackingWithFinalizers graduates to GA, the
    37  	// apiserver and job controller will ignore this annotation and they will
    38  	// always track jobs using finalizers.
    39  	JobTrackingFinalizer = labelPrefix + "job-tracking"
    40  	// LegacyJobName and LegacyControllerUid are legacy labels that were set using unprefixed labels.
    41  	LegacyJobNameLabel       = "job-name"
    42  	LegacyControllerUidLabel = "controller-uid"
    43  	// JobName is a user friendly way to refer to jobs and is set in the labels for jobs.
    44  	JobNameLabel = labelPrefix + LegacyJobNameLabel
    45  	// Controller UID is used for selectors and labels for jobs
    46  	ControllerUidLabel = labelPrefix + LegacyControllerUidLabel
    47  	// Annotation indicating the number of failures for the index corresponding
    48  	// to the pod, which are counted towards the backoff limit.
    49  	JobIndexFailureCountAnnotation = labelPrefix + "job-index-failure-count"
    50  	// Annotation indicating the number of failures for the index corresponding
    51  	// to the pod, which don't count towards the backoff limit, according to the
    52  	// pod failure policy. When the annotation is absent zero is implied.
    53  	JobIndexIgnoredFailureCountAnnotation = labelPrefix + "job-index-ignored-failure-count"
    54  )
    55  
    56  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    57  
    58  // Job represents the configuration of a single job.
    59  type Job struct {
    60  	metav1.TypeMeta
    61  	// Standard object's metadata.
    62  	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
    63  	// +optional
    64  	metav1.ObjectMeta
    65  
    66  	// Specification of the desired behavior of a job.
    67  	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
    68  	// +optional
    69  	Spec JobSpec
    70  
    71  	// Current status of a job.
    72  	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
    73  	// +optional
    74  	Status JobStatus
    75  }
    76  
    77  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    78  
    79  // JobList is a collection of jobs.
    80  type JobList struct {
    81  	metav1.TypeMeta
    82  	// Standard list metadata.
    83  	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
    84  	// +optional
    85  	metav1.ListMeta
    86  
    87  	// items is the list of Jobs.
    88  	Items []Job
    89  }
    90  
    91  // JobTemplateSpec describes the data a Job should have when created from a template
    92  type JobTemplateSpec struct {
    93  	// Standard object's metadata of the jobs created from this template.
    94  	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
    95  	// +optional
    96  	metav1.ObjectMeta
    97  
    98  	// Specification of the desired behavior of the job.
    99  	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
   100  	// +optional
   101  	Spec JobSpec
   102  }
   103  
   104  // CompletionMode specifies how Pod completions of a Job are tracked.
   105  type CompletionMode string
   106  
   107  const (
   108  	// NonIndexedCompletion is a Job completion mode. In this mode, the Job is
   109  	// considered complete when there have been .spec.completions
   110  	// successfully completed Pods. Pod completions are homologous to each other.
   111  	NonIndexedCompletion CompletionMode = "NonIndexed"
   112  
   113  	// IndexedCompletion is a Job completion mode. In this mode, the Pods of a
   114  	// Job get an associated completion index from 0 to (.spec.completions - 1).
   115  	// The Job is  considered complete when a Pod completes for each completion
   116  	// index.
   117  	IndexedCompletion CompletionMode = "Indexed"
   118  )
   119  
   120  // PodFailurePolicyAction specifies how a Pod failure is handled.
   121  // +enum
   122  type PodFailurePolicyAction string
   123  
   124  const (
   125  	// This is an action which might be taken on a pod failure - mark the
   126  	// pod's job as Failed and terminate all running pods.
   127  	PodFailurePolicyActionFailJob PodFailurePolicyAction = "FailJob"
   128  
   129  	// This is an action which might be taken on a pod failure - mark the
   130  	// Job's index as failed to avoid restarts within this index. This action
   131  	// can only be used when backoffLimitPerIndex is set.
   132  	// This value is beta-level.
   133  	PodFailurePolicyActionFailIndex PodFailurePolicyAction = "FailIndex"
   134  
   135  	// This is an action which might be taken on a pod failure - the counter towards
   136  	// .backoffLimit, represented by the job's .status.failed field, is not
   137  	// incremented and a replacement pod is created.
   138  	PodFailurePolicyActionIgnore PodFailurePolicyAction = "Ignore"
   139  
   140  	// This is an action which might be taken on a pod failure - the pod failure
   141  	// is handled in the default way - the counter towards .backoffLimit,
   142  	// represented by the job's .status.failed field, is incremented.
   143  	PodFailurePolicyActionCount PodFailurePolicyAction = "Count"
   144  )
   145  
   146  // +enum
   147  type PodFailurePolicyOnExitCodesOperator string
   148  
   149  const (
   150  	PodFailurePolicyOnExitCodesOpIn    PodFailurePolicyOnExitCodesOperator = "In"
   151  	PodFailurePolicyOnExitCodesOpNotIn PodFailurePolicyOnExitCodesOperator = "NotIn"
   152  )
   153  
   154  // PodReplacementPolicy specifies the policy for creating pod replacements.
   155  // +enum
   156  type PodReplacementPolicy string
   157  
   158  const (
   159  	// TerminatingOrFailed means that we recreate pods
   160  	// when they are terminating (has a metadata.deletionTimestamp) or failed.
   161  	TerminatingOrFailed PodReplacementPolicy = "TerminatingOrFailed"
   162  	//Failed means to wait until a previously created Pod is fully terminated (has phase
   163  	//Failed or Succeeded) before creating a replacement Pod.
   164  	Failed PodReplacementPolicy = "Failed"
   165  )
   166  
   167  // PodFailurePolicyOnExitCodesRequirement describes the requirement for handling
   168  // a failed pod based on its container exit codes. In particular, it lookups the
   169  // .state.terminated.exitCode for each app container and init container status,
   170  // represented by the .status.containerStatuses and .status.initContainerStatuses
   171  // fields in the Pod status, respectively. Containers completed with success
   172  // (exit code 0) are excluded from the requirement check.
   173  type PodFailurePolicyOnExitCodesRequirement struct {
   174  	// Restricts the check for exit codes to the container with the
   175  	// specified name. When null, the rule applies to all containers.
   176  	// When specified, it should match one the container or initContainer
   177  	// names in the pod template.
   178  	// +optional
   179  	ContainerName *string
   180  
   181  	// Represents the relationship between the container exit code(s) and the
   182  	// specified values. Containers completed with success (exit code 0) are
   183  	// excluded from the requirement check. Possible values are:
   184  	//
   185  	// - In: the requirement is satisfied if at least one container exit code
   186  	//   (might be multiple if there are multiple containers not restricted
   187  	//   by the 'containerName' field) is in the set of specified values.
   188  	// - NotIn: the requirement is satisfied if at least one container exit code
   189  	//   (might be multiple if there are multiple containers not restricted
   190  	//   by the 'containerName' field) is not in the set of specified values.
   191  	// Additional values are considered to be added in the future. Clients should
   192  	// react to an unknown operator by assuming the requirement is not satisfied.
   193  	Operator PodFailurePolicyOnExitCodesOperator
   194  
   195  	// Specifies the set of values. Each returned container exit code (might be
   196  	// multiple in case of multiple containers) is checked against this set of
   197  	// values with respect to the operator. The list of values must be ordered
   198  	// and must not contain duplicates. Value '0' cannot be used for the In operator.
   199  	// At least one element is required. At most 255 elements are allowed.
   200  	// +listType=set
   201  	Values []int32
   202  }
   203  
   204  // PodFailurePolicyOnPodConditionsPattern describes a pattern for matching
   205  // an actual pod condition type.
   206  type PodFailurePolicyOnPodConditionsPattern struct {
   207  	// Specifies the required Pod condition type. To match a pod condition
   208  	// it is required that specified type equals the pod condition type.
   209  	Type api.PodConditionType
   210  	// Specifies the required Pod condition status. To match a pod condition
   211  	// it is required that the specified status equals the pod condition status.
   212  	// Defaults to True.
   213  	Status api.ConditionStatus
   214  }
   215  
   216  // PodFailurePolicyRule describes how a pod failure is handled when the requirements are met.
   217  // One of OnExitCodes and onPodConditions, but not both, can be used in each rule.
   218  type PodFailurePolicyRule struct {
   219  	// Specifies the action taken on a pod failure when the requirements are satisfied.
   220  	// Possible values are:
   221  	//
   222  	// - FailJob: indicates that the pod's job is marked as Failed and all
   223  	//   running pods are terminated.
   224  	// - FailIndex: indicates that the pod's index is marked as Failed and will
   225  	//   not be restarted.
   226  	//   This value is alpha-level. It can be used when the
   227  	//   `JobBackoffLimitPerIndex` feature gate is enabled (disabled by default).
   228  	// - Ignore: indicates that the counter towards the .backoffLimit is not
   229  	//   incremented and a replacement pod is created.
   230  	// - Count: indicates that the pod is handled in the default way - the
   231  	//   counter towards the .backoffLimit is incremented.
   232  	// Additional values are considered to be added in the future. Clients should
   233  	// react to an unknown action by skipping the rule.
   234  	Action PodFailurePolicyAction
   235  
   236  	// Represents the requirement on the container exit codes.
   237  	// +optional
   238  	OnExitCodes *PodFailurePolicyOnExitCodesRequirement
   239  
   240  	// Represents the requirement on the pod conditions. The requirement is represented
   241  	// as a list of pod condition patterns. The requirement is satisfied if at
   242  	// least one pattern matches an actual pod condition. At most 20 elements are allowed.
   243  	// +listType=atomic
   244  	// +optional
   245  	OnPodConditions []PodFailurePolicyOnPodConditionsPattern
   246  }
   247  
   248  // PodFailurePolicy describes how failed pods influence the backoffLimit.
   249  type PodFailurePolicy struct {
   250  	// A list of pod failure policy rules. The rules are evaluated in order.
   251  	// Once a rule matches a Pod failure, the remaining of the rules are ignored.
   252  	// When no rule matches the Pod failure, the default handling applies - the
   253  	// counter of pod failures is incremented and it is checked against
   254  	// the backoffLimit. At most 20 elements are allowed.
   255  	// +listType=atomic
   256  	Rules []PodFailurePolicyRule
   257  }
   258  
   259  // JobSpec describes how the job execution will look like.
   260  type JobSpec struct {
   261  
   262  	// Specifies the maximum desired number of pods the job should
   263  	// run at any given time. The actual number of pods running in steady state will
   264  	// be less than this number when ((.spec.completions - .status.successful) < .spec.parallelism),
   265  	// i.e. when the work left to do is less than max parallelism.
   266  	// +optional
   267  	Parallelism *int32
   268  
   269  	// Specifies the desired number of successfully finished pods the
   270  	// job should be run with.  Setting to null means that the success of any
   271  	// pod signals the success of all pods, and allows parallelism to have any positive
   272  	// value.  Setting to 1 means that parallelism is limited to 1 and the success of that
   273  	// pod signals the success of the job.
   274  	// +optional
   275  	Completions *int32
   276  
   277  	// Specifies the policy of handling failed pods. In particular, it allows to
   278  	// specify the set of actions and conditions which need to be
   279  	// satisfied to take the associated action.
   280  	// If empty, the default behaviour applies - the counter of failed pods,
   281  	// represented by the jobs's .status.failed field, is incremented and it is
   282  	// checked against the backoffLimit. This field cannot be used in combination
   283  	// with .spec.podTemplate.spec.restartPolicy=OnFailure.
   284  	//
   285  	// This field is beta-level. It can be used when the `JobPodFailurePolicy`
   286  	// feature gate is enabled (enabled by default).
   287  	// +optional
   288  	PodFailurePolicy *PodFailurePolicy
   289  
   290  	// Specifies the duration in seconds relative to the startTime that the job
   291  	// may be continuously active before the system tries to terminate it; value
   292  	// must be positive integer. If a Job is suspended (at creation or through an
   293  	// update), this timer will effectively be stopped and reset when the Job is
   294  	// resumed again.
   295  	// +optional
   296  	ActiveDeadlineSeconds *int64
   297  
   298  	// Optional number of retries before marking this job failed.
   299  	// Defaults to 6
   300  	// +optional
   301  	BackoffLimit *int32
   302  
   303  	// Specifies the limit for the number of retries within an
   304  	// index before marking this index as failed. When enabled the number of
   305  	// failures per index is kept in the pod's
   306  	// batch.kubernetes.io/job-index-failure-count annotation. It can only
   307  	// be set when Job's completionMode=Indexed, and the Pod's restart
   308  	// policy is Never. The field is immutable.
   309  	// This field is beta-level. It can be used when the `JobBackoffLimitPerIndex`
   310  	// feature gate is enabled (enabled by default).
   311  	// +optional
   312  	BackoffLimitPerIndex *int32
   313  
   314  	// Specifies the maximal number of failed indexes before marking the Job as
   315  	// failed, when backoffLimitPerIndex is set. Once the number of failed
   316  	// indexes exceeds this number the entire Job is marked as Failed and its
   317  	// execution is terminated. When left as null the job continues execution of
   318  	// all of its indexes and is marked with the `Complete` Job condition.
   319  	// It can only be specified when backoffLimitPerIndex is set.
   320  	// It can be null or up to completions. It is required and must be
   321  	// less than or equal to 10^4 when is completions greater than 10^5.
   322  	// This field is beta-level. It can be used when the `JobBackoffLimitPerIndex`
   323  	// feature gate is enabled (enabled by default).
   324  	// +optional
   325  	MaxFailedIndexes *int32
   326  
   327  	// TODO enabled it when https://github.com/kubernetes/kubernetes/issues/28486 has been fixed
   328  	// Optional number of failed pods to retain.
   329  	// +optional
   330  	// FailedPodsLimit *int32
   331  
   332  	// A label query over pods that should match the pod count.
   333  	// Normally, the system sets this field for you.
   334  	// +optional
   335  	Selector *metav1.LabelSelector
   336  
   337  	// manualSelector controls generation of pod labels and pod selectors.
   338  	// Leave `manualSelector` unset unless you are certain what you are doing.
   339  	// When false or unset, the system pick labels unique to this job
   340  	// and appends those labels to the pod template.  When true,
   341  	// the user is responsible for picking unique labels and specifying
   342  	// the selector.  Failure to pick a unique label may cause this
   343  	// and other jobs to not function correctly.  However, You may see
   344  	// `manualSelector=true` in jobs that were created with the old `extensions/v1beta1`
   345  	// API.
   346  	// +optional
   347  	ManualSelector *bool
   348  
   349  	// Describes the pod that will be created when executing a job.
   350  	// The only allowed template.spec.restartPolicy values are "Never" or "OnFailure".
   351  	Template api.PodTemplateSpec
   352  
   353  	// ttlSecondsAfterFinished limits the lifetime of a Job that has finished
   354  	// execution (either Complete or Failed). If this field is set,
   355  	// ttlSecondsAfterFinished after the Job finishes, it is eligible to be
   356  	// automatically deleted. When the Job is being deleted, its lifecycle
   357  	// guarantees (e.g. finalizers) will be honored. If this field is unset,
   358  	// the Job won't be automatically deleted. If this field is set to zero,
   359  	// the Job becomes eligible to be deleted immediately after it finishes.
   360  	// +optional
   361  	TTLSecondsAfterFinished *int32
   362  
   363  	// completionMode specifies how Pod completions are tracked. It can be
   364  	// `NonIndexed` (default) or `Indexed`.
   365  	//
   366  	// `NonIndexed` means that the Job is considered complete when there have
   367  	// been .spec.completions successfully completed Pods. Each Pod completion is
   368  	// homologous to each other.
   369  	//
   370  	// `Indexed` means that the Pods of a
   371  	// Job get an associated completion index from 0 to (.spec.completions - 1),
   372  	// available in the annotation batch.kubernetes.io/job-completion-index.
   373  	// The Job is considered complete when there is one successfully completed Pod
   374  	// for each index.
   375  	// When value is `Indexed`, .spec.completions must be specified and
   376  	// `.spec.parallelism` must be less than or equal to 10^5.
   377  	// In addition, The Pod name takes the form
   378  	// `$(job-name)-$(index)-$(random-string)`,
   379  	// the Pod hostname takes the form `$(job-name)-$(index)`.
   380  	//
   381  	// More completion modes can be added in the future.
   382  	// If the Job controller observes a mode that it doesn't recognize, which
   383  	// is possible during upgrades due to version skew, the controller
   384  	// skips updates for the Job.
   385  	// +optional
   386  	CompletionMode *CompletionMode
   387  
   388  	// suspend specifies whether the Job controller should create Pods or not. If
   389  	// a Job is created with suspend set to true, no Pods are created by the Job
   390  	// controller. If a Job is suspended after creation (i.e. the flag goes from
   391  	// false to true), the Job controller will delete all active Pods associated
   392  	// with this Job. Users must design their workload to gracefully handle this.
   393  	// Suspending a Job will reset the StartTime field of the Job, effectively
   394  	// resetting the ActiveDeadlineSeconds timer too. Defaults to false.
   395  	//
   396  	// +optional
   397  	Suspend *bool
   398  
   399  	// podReplacementPolicy specifies when to create replacement Pods.
   400  	// Possible values are:
   401  	// - TerminatingOrFailed means that we recreate pods
   402  	//   when they are terminating (has a metadata.deletionTimestamp) or failed.
   403  	// - Failed means to wait until a previously created Pod is fully terminated (has phase
   404  	//   Failed or Succeeded) before creating a replacement Pod.
   405  	//
   406  	// When using podFailurePolicy, Failed is the the only allowed value.
   407  	// TerminatingOrFailed and Failed are allowed values when podFailurePolicy is not in use.
   408  	// This is an beta field. To use this, enable the JobPodReplacementPolicy feature toggle.
   409  	// This is on by default.
   410  	// +optional
   411  	PodReplacementPolicy *PodReplacementPolicy
   412  }
   413  
   414  // JobStatus represents the current state of a Job.
   415  type JobStatus struct {
   416  
   417  	// The latest available observations of an object's current state. When a Job
   418  	// fails, one of the conditions will have type "Failed" and status true. When
   419  	// a Job is suspended, one of the conditions will have type "Suspended" and
   420  	// status true; when the Job is resumed, the status of this condition will
   421  	// become false. When a Job is completed, one of the conditions will have
   422  	// type "Complete" and status true.
   423  	// +optional
   424  	Conditions []JobCondition
   425  
   426  	// Represents time when the job controller started processing a job. When a
   427  	// Job is created in the suspended state, this field is not set until the
   428  	// first time it is resumed. This field is reset every time a Job is resumed
   429  	// from suspension. It is represented in RFC3339 form and is in UTC.
   430  	// +optional
   431  	StartTime *metav1.Time
   432  
   433  	// Represents time when the job was completed. It is not guaranteed to
   434  	// be set in happens-before order across separate operations.
   435  	// It is represented in RFC3339 form and is in UTC.
   436  	// The completion time is only set when the job finishes successfully.
   437  	// +optional
   438  	CompletionTime *metav1.Time
   439  
   440  	// The number of pending and running pods.
   441  	// +optional
   442  	Active int32
   443  
   444  	// The number of pods which are terminating (in phase Pending or Running
   445  	// and have a deletionTimestamp).
   446  	//
   447  	// This field is beta-level. The job controller populates the field when
   448  	// the feature gate JobPodReplacementPolicy is enabled (enabled by default).
   449  	// +optional
   450  	Terminating *int32
   451  
   452  	// The number of active pods which have a Ready condition.
   453  	// +optional
   454  	Ready *int32
   455  
   456  	// The number of pods which reached phase Succeeded.
   457  	// +optional
   458  	Succeeded int32
   459  
   460  	// The number of pods which reached phase Failed.
   461  	// +optional
   462  	Failed int32
   463  
   464  	// completedIndexes holds the completed indexes when .spec.completionMode =
   465  	// "Indexed" in a text format. The indexes are represented as decimal integers
   466  	// separated by commas. The numbers are listed in increasing order. Three or
   467  	// more consecutive numbers are compressed and represented by the first and
   468  	// last element of the series, separated by a hyphen.
   469  	// For example, if the completed indexes are 1, 3, 4, 5 and 7, they are
   470  	// represented as "1,3-5,7".
   471  	// +optional
   472  	CompletedIndexes string
   473  
   474  	// FailedIndexes holds the failed indexes when backoffLimitPerIndex=true.
   475  	// The indexes are represented in the text format analogous as for the
   476  	// `completedIndexes` field, ie. they are kept as decimal integers
   477  	// separated by commas. The numbers are listed in increasing order. Three or
   478  	// more consecutive numbers are compressed and represented by the first and
   479  	// last element of the series, separated by a hyphen.
   480  	// For example, if the failed indexes are 1, 3, 4, 5 and 7, they are
   481  	// represented as "1,3-5,7".
   482  	// This field is beta-level. It can be used when the `JobBackoffLimitPerIndex`
   483  	// feature gate is enabled (enabled by default).
   484  	// +optional
   485  	FailedIndexes *string
   486  
   487  	// uncountedTerminatedPods holds the UIDs of Pods that have terminated but
   488  	// the job controller hasn't yet accounted for in the status counters.
   489  	//
   490  	// The job controller creates pods with a finalizer. When a pod terminates
   491  	// (succeeded or failed), the controller does three steps to account for it
   492  	// in the job status:
   493  	//
   494  	// 1. Add the pod UID to the corresponding array in this field.
   495  	// 2. Remove the pod finalizer.
   496  	// 3. Remove the pod UID from the array while increasing the corresponding
   497  	//     counter.
   498  	//
   499  	// Old jobs might not be tracked using this field, in which case the field
   500  	// remains null.
   501  	// +optional
   502  	UncountedTerminatedPods *UncountedTerminatedPods
   503  }
   504  
   505  // UncountedTerminatedPods holds UIDs of Pods that have terminated but haven't
   506  // been accounted in Job status counters.
   507  type UncountedTerminatedPods struct {
   508  	// succeeded holds UIDs of succeeded Pods.
   509  	// +listType=set
   510  	// +optional
   511  	Succeeded []types.UID
   512  
   513  	// failed holds UIDs of failed Pods.
   514  	// +listType=set
   515  	// +optional
   516  	Failed []types.UID
   517  }
   518  
   519  // JobConditionType is a valid value for JobCondition.Type
   520  type JobConditionType string
   521  
   522  // These are valid conditions of a job.
   523  const (
   524  	// JobSuspended means the job has been suspended.
   525  	JobSuspended JobConditionType = "Suspended"
   526  	// JobComplete means the job has completed its execution.
   527  	JobComplete JobConditionType = "Complete"
   528  	// JobFailed means the job has failed its execution.
   529  	JobFailed JobConditionType = "Failed"
   530  	// FailureTarget means the job is about to fail its execution.
   531  	JobFailureTarget JobConditionType = "FailureTarget"
   532  )
   533  
   534  // JobCondition describes current state of a job.
   535  type JobCondition struct {
   536  	// Type of job condition.
   537  	Type JobConditionType
   538  	// Status of the condition, one of True, False, Unknown.
   539  	Status api.ConditionStatus
   540  	// Last time the condition was checked.
   541  	// +optional
   542  	LastProbeTime metav1.Time
   543  	// Last time the condition transit from one status to another.
   544  	// +optional
   545  	LastTransitionTime metav1.Time
   546  	// (brief) reason for the condition's last transition.
   547  	// +optional
   548  	Reason string
   549  	// Human readable message indicating details about last transition.
   550  	// +optional
   551  	Message string
   552  }
   553  
   554  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
   555  
   556  // CronJob represents the configuration of a single cron job.
   557  type CronJob struct {
   558  	metav1.TypeMeta
   559  	// Standard object's metadata.
   560  	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
   561  	// +optional
   562  	metav1.ObjectMeta
   563  
   564  	// Specification of the desired behavior of a cron job, including the schedule.
   565  	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
   566  	// +optional
   567  	Spec CronJobSpec
   568  
   569  	// Current status of a cron job.
   570  	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
   571  	// +optional
   572  	Status CronJobStatus
   573  }
   574  
   575  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
   576  
   577  // CronJobList is a collection of cron jobs.
   578  type CronJobList struct {
   579  	metav1.TypeMeta
   580  	// Standard list metadata.
   581  	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
   582  	// +optional
   583  	metav1.ListMeta
   584  
   585  	// items is the list of CronJobs.
   586  	Items []CronJob
   587  }
   588  
   589  // CronJobSpec describes how the job execution will look like and when it will actually run.
   590  type CronJobSpec struct {
   591  
   592  	// The schedule in Cron format, see https://en.wikipedia.org/wiki/Cron.
   593  	Schedule string
   594  
   595  	// The time zone name for the given schedule, see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones.
   596  	// If not specified, this will default to the time zone of the kube-controller-manager process.
   597  	// The set of valid time zone names and the time zone offset is loaded from the system-wide time zone
   598  	// database by the API server during CronJob validation and the controller manager during execution.
   599  	// If no system-wide time zone database can be found a bundled version of the database is used instead.
   600  	// If the time zone name becomes invalid during the lifetime of a CronJob or due to a change in host
   601  	// configuration, the controller will stop creating new new Jobs and will create a system event with the
   602  	// reason UnknownTimeZone.
   603  	// More information can be found in https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/#time-zones
   604  	// +optional
   605  	TimeZone *string
   606  
   607  	// Optional deadline in seconds for starting the job if it misses scheduled
   608  	// time for any reason.  Missed jobs executions will be counted as failed ones.
   609  	// +optional
   610  	StartingDeadlineSeconds *int64
   611  
   612  	// Specifies how to treat concurrent executions of a Job.
   613  	// Valid values are:
   614  	//
   615  	// - "Allow" (default): allows CronJobs to run concurrently;
   616  	// - "Forbid": forbids concurrent runs, skipping next run if previous run hasn't finished yet;
   617  	// - "Replace": cancels currently running job and replaces it with a new one
   618  	// +optional
   619  	ConcurrencyPolicy ConcurrencyPolicy
   620  
   621  	// This flag tells the controller to suspend subsequent executions, it does
   622  	// not apply to already started executions. Defaults to false.
   623  	// +optional
   624  	Suspend *bool
   625  
   626  	// Specifies the job that will be created when executing a CronJob.
   627  	JobTemplate JobTemplateSpec
   628  
   629  	// The number of successful finished jobs to retain.
   630  	// This is a pointer to distinguish between explicit zero and not specified.
   631  	// +optional
   632  	SuccessfulJobsHistoryLimit *int32
   633  
   634  	// The number of failed finished jobs to retain.
   635  	// This is a pointer to distinguish between explicit zero and not specified.
   636  	// +optional
   637  	FailedJobsHistoryLimit *int32
   638  }
   639  
   640  // ConcurrencyPolicy describes how the job will be handled.
   641  // Only one of the following concurrent policies may be specified.
   642  // If none of the following policies is specified, the default one
   643  // is AllowConcurrent.
   644  type ConcurrencyPolicy string
   645  
   646  const (
   647  	// AllowConcurrent allows CronJobs to run concurrently.
   648  	AllowConcurrent ConcurrencyPolicy = "Allow"
   649  
   650  	// ForbidConcurrent forbids concurrent runs, skipping next run if previous
   651  	// hasn't finished yet.
   652  	ForbidConcurrent ConcurrencyPolicy = "Forbid"
   653  
   654  	// ReplaceConcurrent cancels currently running job and replaces it with a new one.
   655  	ReplaceConcurrent ConcurrencyPolicy = "Replace"
   656  )
   657  
   658  // CronJobStatus represents the current state of a cron job.
   659  type CronJobStatus struct {
   660  	// A list of pointers to currently running jobs.
   661  	// +optional
   662  	Active []api.ObjectReference
   663  
   664  	// Information when was the last time the job was successfully scheduled.
   665  	// +optional
   666  	LastScheduleTime *metav1.Time
   667  
   668  	// Information when was the last time the job successfully completed.
   669  	// +optional
   670  	LastSuccessfulTime *metav1.Time
   671  }