blob: 6f49cc2a3f5959470bb2f9da63687a07eb9c40c6 [file] [log] [blame]
Matteo Scandoloa4285862020-12-01 18:10:10 -08001/*
2Copyright 2017 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package v1beta1
18
19import (
20 batchv1 "k8s.io/api/batch/v1"
21 v1 "k8s.io/api/core/v1"
22 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23)
24
25// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
26// +k8s:prerelease-lifecycle-gen:introduced=1.8
27// +k8s:prerelease-lifecycle-gen:deprecated=1.22
28
29// JobTemplate describes a template for creating copies of a predefined pod.
30type JobTemplate struct {
31 metav1.TypeMeta `json:",inline"`
32 // Standard object's metadata.
33 // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
34 // +optional
35 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
36
37 // Defines jobs that will be created from this template.
38 // https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
39 // +optional
40 Template JobTemplateSpec `json:"template,omitempty" protobuf:"bytes,2,opt,name=template"`
41}
42
43// JobTemplateSpec describes the data a Job should have when created from a template
44type JobTemplateSpec struct {
45 // Standard object's metadata of the jobs created from this template.
46 // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
47 // +optional
48 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
49
50 // Specification of the desired behavior of the job.
51 // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
52 // +optional
53 Spec batchv1.JobSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
54}
55
56// +genclient
57// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
58// +k8s:prerelease-lifecycle-gen:introduced=1.8
59// +k8s:prerelease-lifecycle-gen:deprecated=1.22
60
61// CronJob represents the configuration of a single cron job.
62type CronJob struct {
63 metav1.TypeMeta `json:",inline"`
64 // Standard object's metadata.
65 // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
66 // +optional
67 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
68
69 // Specification of the desired behavior of a cron job, including the schedule.
70 // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
71 // +optional
72 Spec CronJobSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
73
74 // Current status of a cron job.
75 // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
76 // +optional
77 Status CronJobStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
78}
79
80// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
81// +k8s:prerelease-lifecycle-gen:introduced=1.8
82// +k8s:prerelease-lifecycle-gen:deprecated=1.22
83
84// CronJobList is a collection of cron jobs.
85type CronJobList struct {
86 metav1.TypeMeta `json:",inline"`
87
88 // Standard list metadata.
89 // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
90 // +optional
91 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
92
93 // items is the list of CronJobs.
94 Items []CronJob `json:"items" protobuf:"bytes,2,rep,name=items"`
95}
96
97// CronJobSpec describes how the job execution will look like and when it will actually run.
98type CronJobSpec struct {
99
100 // The schedule in Cron format, see https://en.wikipedia.org/wiki/Cron.
101 Schedule string `json:"schedule" protobuf:"bytes,1,opt,name=schedule"`
102
103 // Optional deadline in seconds for starting the job if it misses scheduled
104 // time for any reason. Missed jobs executions will be counted as failed ones.
105 // +optional
106 StartingDeadlineSeconds *int64 `json:"startingDeadlineSeconds,omitempty" protobuf:"varint,2,opt,name=startingDeadlineSeconds"`
107
108 // Specifies how to treat concurrent executions of a Job.
109 // Valid values are:
110 // - "Allow" (default): allows CronJobs to run concurrently;
111 // - "Forbid": forbids concurrent runs, skipping next run if previous run hasn't finished yet;
112 // - "Replace": cancels currently running job and replaces it with a new one
113 // +optional
114 ConcurrencyPolicy ConcurrencyPolicy `json:"concurrencyPolicy,omitempty" protobuf:"bytes,3,opt,name=concurrencyPolicy,casttype=ConcurrencyPolicy"`
115
116 // This flag tells the controller to suspend subsequent executions, it does
117 // not apply to already started executions. Defaults to false.
118 // +optional
119 Suspend *bool `json:"suspend,omitempty" protobuf:"varint,4,opt,name=suspend"`
120
121 // Specifies the job that will be created when executing a CronJob.
122 JobTemplate JobTemplateSpec `json:"jobTemplate" protobuf:"bytes,5,opt,name=jobTemplate"`
123
124 // The number of successful finished jobs to retain.
125 // This is a pointer to distinguish between explicit zero and not specified.
126 // Defaults to 3.
127 // +optional
128 SuccessfulJobsHistoryLimit *int32 `json:"successfulJobsHistoryLimit,omitempty" protobuf:"varint,6,opt,name=successfulJobsHistoryLimit"`
129
130 // The number of failed finished jobs to retain.
131 // This is a pointer to distinguish between explicit zero and not specified.
132 // Defaults to 1.
133 // +optional
134 FailedJobsHistoryLimit *int32 `json:"failedJobsHistoryLimit,omitempty" protobuf:"varint,7,opt,name=failedJobsHistoryLimit"`
135}
136
137// ConcurrencyPolicy describes how the job will be handled.
138// Only one of the following concurrent policies may be specified.
139// If none of the following policies is specified, the default one
140// is AllowConcurrent.
141type ConcurrencyPolicy string
142
143const (
144 // AllowConcurrent allows CronJobs to run concurrently.
145 AllowConcurrent ConcurrencyPolicy = "Allow"
146
147 // ForbidConcurrent forbids concurrent runs, skipping next run if previous
148 // hasn't finished yet.
149 ForbidConcurrent ConcurrencyPolicy = "Forbid"
150
151 // ReplaceConcurrent cancels currently running job and replaces it with a new one.
152 ReplaceConcurrent ConcurrencyPolicy = "Replace"
153)
154
155// CronJobStatus represents the current state of a cron job.
156type CronJobStatus struct {
157 // A list of pointers to currently running jobs.
158 // +optional
159 Active []v1.ObjectReference `json:"active,omitempty" protobuf:"bytes,1,rep,name=active"`
160
161 // Information when was the last time the job was successfully scheduled.
162 // +optional
163 LastScheduleTime *metav1.Time `json:"lastScheduleTime,omitempty" protobuf:"bytes,4,opt,name=lastScheduleTime"`
164}