1/* 2Copyright 2016 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 v2alpha1 18 19import ( 20 batchv1 "k8s.io/api/batch/v1" 21 "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 27// JobTemplate describes a template for creating copies of a predefined pod. 28type JobTemplate struct { 29 metav1.TypeMeta `json:",inline"` 30 // Standard object's metadata. 31 // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata 32 // +optional 33 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 34 35 // Defines jobs that will be created from this template. 36 // https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status 37 // +optional 38 Template JobTemplateSpec `json:"template,omitempty" protobuf:"bytes,2,opt,name=template"` 39} 40 41// JobTemplateSpec describes the data a Job should have when created from a template 42type JobTemplateSpec struct { 43 // Standard object's metadata of the jobs created from this template. 44 // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata 45 // +optional 46 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 47 48 // Specification of the desired behavior of the job. 49 // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status 50 // +optional 51 Spec batchv1.JobSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"` 52} 53 54// +genclient 55// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 56 57// CronJob represents the configuration of a single cron job. 58type CronJob struct { 59 metav1.TypeMeta `json:",inline"` 60 // Standard object's metadata. 61 // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata 62 // +optional 63 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 64 65 // Specification of the desired behavior of a cron job, including the schedule. 66 // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status 67 // +optional 68 Spec CronJobSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"` 69 70 // Current status of a cron job. 71 // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status 72 // +optional 73 Status CronJobStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"` 74} 75 76// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 77 78// CronJobList is a collection of cron jobs. 79type CronJobList struct { 80 metav1.TypeMeta `json:",inline"` 81 82 // Standard list metadata. 83 // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata 84 // +optional 85 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 86 87 // items is the list of CronJobs. 88 Items []CronJob `json:"items" protobuf:"bytes,2,rep,name=items"` 89} 90 91// CronJobSpec describes how the job execution will look like and when it will actually run. 92type CronJobSpec struct { 93 94 // The schedule in Cron format, see https://en.wikipedia.org/wiki/Cron. 95 Schedule string `json:"schedule" protobuf:"bytes,1,opt,name=schedule"` 96 97 // Optional deadline in seconds for starting the job if it misses scheduled 98 // time for any reason. Missed jobs executions will be counted as failed ones. 99 // +optional 100 StartingDeadlineSeconds *int64 `json:"startingDeadlineSeconds,omitempty" protobuf:"varint,2,opt,name=startingDeadlineSeconds"` 101 102 // Specifies how to treat concurrent executions of a Job. 103 // Valid values are: 104 // - "Allow" (default): allows CronJobs to run concurrently; 105 // - "Forbid": forbids concurrent runs, skipping next run if previous run hasn't finished yet; 106 // - "Replace": cancels currently running job and replaces it with a new one 107 // +optional 108 ConcurrencyPolicy ConcurrencyPolicy `json:"concurrencyPolicy,omitempty" protobuf:"bytes,3,opt,name=concurrencyPolicy,casttype=ConcurrencyPolicy"` 109 110 // This flag tells the controller to suspend subsequent executions, it does 111 // not apply to already started executions. Defaults to false. 112 // +optional 113 Suspend *bool `json:"suspend,omitempty" protobuf:"varint,4,opt,name=suspend"` 114 115 // Specifies the job that will be created when executing a CronJob. 116 JobTemplate JobTemplateSpec `json:"jobTemplate" protobuf:"bytes,5,opt,name=jobTemplate"` 117 118 // The number of successful finished jobs to retain. 119 // This is a pointer to distinguish between explicit zero and not specified. 120 // +optional 121 SuccessfulJobsHistoryLimit *int32 `json:"successfulJobsHistoryLimit,omitempty" protobuf:"varint,6,opt,name=successfulJobsHistoryLimit"` 122 123 // The number of failed finished jobs to retain. 124 // This is a pointer to distinguish between explicit zero and not specified. 125 // +optional 126 FailedJobsHistoryLimit *int32 `json:"failedJobsHistoryLimit,omitempty" protobuf:"varint,7,opt,name=failedJobsHistoryLimit"` 127} 128 129// ConcurrencyPolicy describes how the job will be handled. 130// Only one of the following concurrent policies may be specified. 131// If none of the following policies is specified, the default one 132// is AllowConcurrent. 133type ConcurrencyPolicy string 134 135const ( 136 // AllowConcurrent allows CronJobs to run concurrently. 137 AllowConcurrent ConcurrencyPolicy = "Allow" 138 139 // ForbidConcurrent forbids concurrent runs, skipping next run if previous 140 // hasn't finished yet. 141 ForbidConcurrent ConcurrencyPolicy = "Forbid" 142 143 // ReplaceConcurrent cancels currently running job and replaces it with a new one. 144 ReplaceConcurrent ConcurrencyPolicy = "Replace" 145) 146 147// CronJobStatus represents the current state of a cron job. 148type CronJobStatus struct { 149 // A list of pointers to currently running jobs. 150 // +optional 151 Active []v1.ObjectReference `json:"active,omitempty" protobuf:"bytes,1,rep,name=active"` 152 153 // Information when was the last time the job was successfully scheduled. 154 // +optional 155 LastScheduleTime *metav1.Time `json:"lastScheduleTime,omitempty" protobuf:"bytes,4,opt,name=lastScheduleTime"` 156} 157