cronjob_types.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. Copyright 2023.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package v1
  14. import (
  15. batchv1 "k8s.io/api/batch/v1"
  16. corev1 "k8s.io/api/core/v1"
  17. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  18. )
  19. // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
  20. // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
  21. // CronJobSpec defines the desired state of CronJob
  22. type CronJobSpec struct {
  23. //+kubebuilder:validation:MinLength=0
  24. // The schedule in Cron format, see https://en.wikipedia.org/wiki/Cron.
  25. Schedule string `json:"schedule"`
  26. //+kubebuilder:validation:Minimum=0
  27. // Optional deadline in seconds for starting the job if it misses scheduled
  28. // time for any reason. Missed jobs executions will be counted as failed ones.
  29. // +optional
  30. StartingDeadlineSeconds *int64 `json:"startingDeadlineSeconds,omitempty"`
  31. // Specifies how to treat concurrent executions of a Job.
  32. // Valid values are:
  33. // - "Allow" (default): allows CronJobs to run concurrently;
  34. // - "Forbid": forbids concurrent runs, skipping next run if previous run hasn't finished yet;
  35. // - "Replace": cancels currently running job and replaces it with a new one
  36. // +optional
  37. ConcurrencyPolicy ConcurrencyPolicy `json:"concurrencyPolicy,omitempty"`
  38. // This flag tells the controller to suspend subsequent executions, it does
  39. // not apply to already started executions. Defaults to false.
  40. // +optional
  41. Suspend *bool `json:"suspend,omitempty"`
  42. // Specifies the job that will be created when executing a CronJob.
  43. JobTemplate batchv1.JobTemplateSpec `json:"jobTemplate"`
  44. //+kubebuilder:validation:Minimum=0
  45. // The number of successful finished jobs to retain.
  46. // This is a pointer to distinguish between explicit zero and not specified.
  47. // +optional
  48. SuccessfulJobsHistoryLimit *int32 `json:"successfulJobsHistoryLimit,omitempty"`
  49. //+kubebuilder:validation:Minimum=0
  50. // The number of failed finished jobs to retain.
  51. // This is a pointer to distinguish between explicit zero and not specified.
  52. // +optional
  53. FailedJobsHistoryLimit *int32 `json:"failedJobsHistoryLimit,omitempty"`
  54. }
  55. // ConcurrencyPolicy describes how the job will be handled.
  56. // Only one of the following concurrent policies may be specified.
  57. // If none of the following policies is specified, the default one
  58. // is AllowConcurrent.
  59. // +kubebuilder:validation:Enum=Allow;Forbid;Replace
  60. type ConcurrencyPolicy string
  61. const (
  62. // AllowConcurrent allows CronJobs to run concurrently.
  63. AllowConcurrent ConcurrencyPolicy = "Allow"
  64. // ForbidConcurrent forbids concurrent runs, skipping next run if previous
  65. // hasn't finished yet.
  66. ForbidConcurrent ConcurrencyPolicy = "Forbid"
  67. // ReplaceConcurrent cancels currently running job and replaces it with a new one.
  68. ReplaceConcurrent ConcurrencyPolicy = "Replace"
  69. )
  70. // CronJobStatus defines the observed state of CronJob
  71. type CronJobStatus struct {
  72. // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
  73. // Important: Run "make" to regenerate code after modifying this file
  74. // A list of pointers to currently running jobs.
  75. // +optional
  76. Active []corev1.ObjectReference `json:"active,omitempty"`
  77. // Information when was the last time the job was successfully scheduled.
  78. // +optional
  79. LastScheduleTime *metav1.Time `json:"lastScheduleTime,omitempty"`
  80. }
  81. //+kubebuilder:object:root=true
  82. //+kubebuilder:subresource:status
  83. // CronJob is the Schema for the cronjobs API
  84. type CronJob struct {
  85. metav1.TypeMeta `json:",inline"`
  86. metav1.ObjectMeta `json:"metadata,omitempty"`
  87. Spec CronJobSpec `json:"spec,omitempty"`
  88. Status CronJobStatus `json:"status,omitempty"`
  89. }
  90. //+kubebuilder:object:root=true
  91. // CronJobList contains a list of CronJob
  92. type CronJobList struct {
  93. metav1.TypeMeta `json:",inline"`
  94. metav1.ListMeta `json:"metadata,omitempty"`
  95. Items []CronJob `json:"items"`
  96. }
  97. func init() {
  98. SchemeBuilder.Register(&CronJob{}, &CronJobList{})
  99. }