Matteo Scandolo | a428586 | 2020-12-01 18:10:10 -0800 | [diff] [blame] | 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 v1 |
| 18 | |
| 19 | import ( |
| 20 | "k8s.io/api/core/v1" |
| 21 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 22 | ) |
| 23 | |
| 24 | // +genclient |
| 25 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 26 | |
| 27 | // Job represents the configuration of a single job. |
| 28 | type Job struct { |
| 29 | metav1.TypeMeta `json:",inline"` |
| 30 | // Standard object's metadata. |
| 31 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata |
| 32 | // +optional |
| 33 | metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` |
| 34 | |
| 35 | // Specification of the desired behavior of a job. |
| 36 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status |
| 37 | // +optional |
| 38 | Spec JobSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"` |
| 39 | |
| 40 | // Current status of a job. |
| 41 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status |
| 42 | // +optional |
| 43 | Status JobStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"` |
| 44 | } |
| 45 | |
| 46 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 47 | |
| 48 | // JobList is a collection of jobs. |
| 49 | type JobList struct { |
| 50 | metav1.TypeMeta `json:",inline"` |
| 51 | // Standard list metadata. |
| 52 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata |
| 53 | // +optional |
| 54 | metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` |
| 55 | |
| 56 | // items is the list of Jobs. |
| 57 | Items []Job `json:"items" protobuf:"bytes,2,rep,name=items"` |
| 58 | } |
| 59 | |
| 60 | // JobSpec describes how the job execution will look like. |
| 61 | type JobSpec struct { |
| 62 | |
| 63 | // Specifies the maximum desired number of pods the job should |
| 64 | // run at any given time. The actual number of pods running in steady state will |
| 65 | // be less than this number when ((.spec.completions - .status.successful) < .spec.parallelism), |
| 66 | // i.e. when the work left to do is less than max parallelism. |
| 67 | // More info: https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/ |
| 68 | // +optional |
| 69 | Parallelism *int32 `json:"parallelism,omitempty" protobuf:"varint,1,opt,name=parallelism"` |
| 70 | |
| 71 | // Specifies the desired number of successfully finished pods the |
| 72 | // job should be run with. Setting to nil means that the success of any |
| 73 | // pod signals the success of all pods, and allows parallelism to have any positive |
| 74 | // value. Setting to 1 means that parallelism is limited to 1 and the success of that |
| 75 | // pod signals the success of the job. |
| 76 | // More info: https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/ |
| 77 | // +optional |
| 78 | Completions *int32 `json:"completions,omitempty" protobuf:"varint,2,opt,name=completions"` |
| 79 | |
| 80 | // Specifies the duration in seconds relative to the startTime that the job may be active |
| 81 | // before the system tries to terminate it; value must be positive integer |
| 82 | // +optional |
| 83 | ActiveDeadlineSeconds *int64 `json:"activeDeadlineSeconds,omitempty" protobuf:"varint,3,opt,name=activeDeadlineSeconds"` |
| 84 | |
| 85 | // Specifies the number of retries before marking this job failed. |
| 86 | // Defaults to 6 |
| 87 | // +optional |
| 88 | BackoffLimit *int32 `json:"backoffLimit,omitempty" protobuf:"varint,7,opt,name=backoffLimit"` |
| 89 | |
| 90 | // TODO enabled it when https://github.com/kubernetes/kubernetes/issues/28486 has been fixed |
| 91 | // Optional number of failed pods to retain. |
| 92 | // +optional |
| 93 | // FailedPodsLimit *int32 `json:"failedPodsLimit,omitempty" protobuf:"varint,9,opt,name=failedPodsLimit"` |
| 94 | |
| 95 | // A label query over pods that should match the pod count. |
| 96 | // Normally, the system sets this field for you. |
| 97 | // More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors |
| 98 | // +optional |
| 99 | Selector *metav1.LabelSelector `json:"selector,omitempty" protobuf:"bytes,4,opt,name=selector"` |
| 100 | |
| 101 | // manualSelector controls generation of pod labels and pod selectors. |
| 102 | // Leave `manualSelector` unset unless you are certain what you are doing. |
| 103 | // When false or unset, the system pick labels unique to this job |
| 104 | // and appends those labels to the pod template. When true, |
| 105 | // the user is responsible for picking unique labels and specifying |
| 106 | // the selector. Failure to pick a unique label may cause this |
| 107 | // and other jobs to not function correctly. However, You may see |
| 108 | // `manualSelector=true` in jobs that were created with the old `extensions/v1beta1` |
| 109 | // API. |
| 110 | // More info: https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/#specifying-your-own-pod-selector |
| 111 | // +optional |
| 112 | ManualSelector *bool `json:"manualSelector,omitempty" protobuf:"varint,5,opt,name=manualSelector"` |
| 113 | |
| 114 | // Describes the pod that will be created when executing a job. |
| 115 | // More info: https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/ |
| 116 | Template v1.PodTemplateSpec `json:"template" protobuf:"bytes,6,opt,name=template"` |
| 117 | |
| 118 | // ttlSecondsAfterFinished limits the lifetime of a Job that has finished |
| 119 | // execution (either Complete or Failed). If this field is set, |
| 120 | // ttlSecondsAfterFinished after the Job finishes, it is eligible to be |
| 121 | // automatically deleted. When the Job is being deleted, its lifecycle |
| 122 | // guarantees (e.g. finalizers) will be honored. If this field is unset, |
| 123 | // the Job won't be automatically deleted. If this field is set to zero, |
| 124 | // the Job becomes eligible to be deleted immediately after it finishes. |
| 125 | // This field is alpha-level and is only honored by servers that enable the |
| 126 | // TTLAfterFinished feature. |
| 127 | // +optional |
| 128 | TTLSecondsAfterFinished *int32 `json:"ttlSecondsAfterFinished,omitempty" protobuf:"varint,8,opt,name=ttlSecondsAfterFinished"` |
| 129 | } |
| 130 | |
| 131 | // JobStatus represents the current state of a Job. |
| 132 | type JobStatus struct { |
| 133 | // The latest available observations of an object's current state. |
| 134 | // More info: https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/ |
| 135 | // +optional |
| 136 | // +patchMergeKey=type |
| 137 | // +patchStrategy=merge |
| 138 | Conditions []JobCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"` |
| 139 | |
| 140 | // Represents time when the job was acknowledged by the job controller. |
| 141 | // It is not guaranteed to be set in happens-before order across separate operations. |
| 142 | // It is represented in RFC3339 form and is in UTC. |
| 143 | // +optional |
| 144 | StartTime *metav1.Time `json:"startTime,omitempty" protobuf:"bytes,2,opt,name=startTime"` |
| 145 | |
| 146 | // Represents time when the job was completed. It is not guaranteed to |
| 147 | // be set in happens-before order across separate operations. |
| 148 | // It is represented in RFC3339 form and is in UTC. |
| 149 | // +optional |
| 150 | CompletionTime *metav1.Time `json:"completionTime,omitempty" protobuf:"bytes,3,opt,name=completionTime"` |
| 151 | |
| 152 | // The number of actively running pods. |
| 153 | // +optional |
| 154 | Active int32 `json:"active,omitempty" protobuf:"varint,4,opt,name=active"` |
| 155 | |
| 156 | // The number of pods which reached phase Succeeded. |
| 157 | // +optional |
| 158 | Succeeded int32 `json:"succeeded,omitempty" protobuf:"varint,5,opt,name=succeeded"` |
| 159 | |
| 160 | // The number of pods which reached phase Failed. |
| 161 | // +optional |
| 162 | Failed int32 `json:"failed,omitempty" protobuf:"varint,6,opt,name=failed"` |
| 163 | } |
| 164 | |
| 165 | type JobConditionType string |
| 166 | |
| 167 | // These are valid conditions of a job. |
| 168 | const ( |
| 169 | // JobComplete means the job has completed its execution. |
| 170 | JobComplete JobConditionType = "Complete" |
| 171 | // JobFailed means the job has failed its execution. |
| 172 | JobFailed JobConditionType = "Failed" |
| 173 | ) |
| 174 | |
| 175 | // JobCondition describes current state of a job. |
| 176 | type JobCondition struct { |
| 177 | // Type of job condition, Complete or Failed. |
| 178 | Type JobConditionType `json:"type" protobuf:"bytes,1,opt,name=type,casttype=JobConditionType"` |
| 179 | // Status of the condition, one of True, False, Unknown. |
| 180 | Status v1.ConditionStatus `json:"status" protobuf:"bytes,2,opt,name=status,casttype=k8s.io/api/core/v1.ConditionStatus"` |
| 181 | // Last time the condition was checked. |
| 182 | // +optional |
| 183 | LastProbeTime metav1.Time `json:"lastProbeTime,omitempty" protobuf:"bytes,3,opt,name=lastProbeTime"` |
| 184 | // Last time the condition transit from one status to another. |
| 185 | // +optional |
| 186 | LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,4,opt,name=lastTransitionTime"` |
| 187 | // (brief) reason for the condition's last transition. |
| 188 | // +optional |
| 189 | Reason string `json:"reason,omitempty" protobuf:"bytes,5,opt,name=reason"` |
| 190 | // Human readable message indicating details about last transition. |
| 191 | // +optional |
| 192 | Message string `json:"message,omitempty" protobuf:"bytes,6,opt,name=message"` |
| 193 | } |