-
Notifications
You must be signed in to change notification settings - Fork 1.6k
🌱 Update cronjob-tutorial automatically #3231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,9 @@ | |
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| source "$(dirname "$0")/../../test/common.sh" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to add this one here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems we need to prepare a kb for the pipeline based on the above discussion: #3231 (comment) |
||
|
|
||
| build_kb | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, why are we adding it here? |
||
|
|
||
| check_directory="$(dirname "$0")/../../docs/book/src/" | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| /* | ||
| Copyright 2023 The Kubernetes Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package cronjob | ||
|
|
||
| const CronjobSpecExplaination = ` | ||
|
|
||
| // +kubebuilder:docs-gen:collapse=Imports | ||
|
|
||
| /* | ||
| First, let's take a look at our spec. As we discussed before, spec holds | ||
| *desired state*, so any "inputs" to our controller go here. | ||
|
|
||
| Fundamentally a CronJob needs the following pieces: | ||
|
|
||
| - A schedule (the *cron* in CronJob) | ||
| - A template for the Job to run (the | ||
| *job* in CronJob) | ||
|
|
||
| We'll also want a few extras, which will make our users' lives easier: | ||
|
|
||
| - A deadline for starting jobs (if we miss this deadline, we'll just wait till | ||
| the next scheduled time) | ||
| - What to do if multiple jobs would run at once (do we wait? stop the old one? run both?) | ||
| - A way to pause the running of a CronJob, in case something's wrong with it | ||
| - Limits on old job history | ||
|
|
||
| Remember, since we never read our own status, we need to have some other way to | ||
| keep track of whether a job has run. We can use at least one old job to do | ||
| this. | ||
|
|
||
| We'll use several markers (` + "`" + `// +comment` + "`" + `) to specify additional metadata. These | ||
| will be used by [controller-tools](https://github.com/kubernetes-sigs/controller-tools) when generating our CRD manifest. | ||
| As we'll see in a bit, controller-tools will also use GoDoc to form descriptions for | ||
| the fields. | ||
| */ | ||
| ` | ||
|
|
||
| const CronjobSpecStruct = ` | ||
| //+kubebuilder:validation:MinLength=0 | ||
|
|
||
| // The schedule in Cron format, see https://en.wikipedia.org/wiki/Cron. | ||
| Schedule string` + " `" + `json:"schedule"` + "`" + ` | ||
|
|
||
| //+kubebuilder:validation:Minimum=0 | ||
|
|
||
| // Optional deadline in seconds for starting the job if it misses scheduled | ||
| // time for any reason. Missed jobs executions will be counted as failed ones. | ||
| // +optional | ||
| StartingDeadlineSeconds *int64` + " `" + `json:"startingDeadlineSeconds,omitempty"` + "`" + ` | ||
|
|
||
| // Specifies how to treat concurrent executions of a Job. | ||
| // Valid values are: | ||
| // - "Allow" (default): allows CronJobs to run concurrently; | ||
| // - "Forbid": forbids concurrent runs, skipping next run if previous run hasn't finished yet; | ||
| // - "Replace": cancels currently running job and replaces it with a new one | ||
| // +optional | ||
| ConcurrencyPolicy ConcurrencyPolicy` + " `" + `json:"concurrencyPolicy,omitempty"` + "`" + ` | ||
|
|
||
| // This flag tells the controller to suspend subsequent executions, it does | ||
| // not apply to already started executions. Defaults to false. | ||
| // +optional | ||
| Suspend *bool` + " `" + `json:"suspend,omitempty"` + "`" + ` | ||
|
|
||
| // Specifies the job that will be created when executing a CronJob. | ||
| JobTemplate batchv1.JobTemplateSpec` + " `" + `json:"jobTemplate"` + "`" + ` | ||
|
|
||
| //+kubebuilder:validation:Minimum=0 | ||
|
|
||
| // The number of successful finished jobs to retain. | ||
| // This is a pointer to distinguish between explicit zero and not specified. | ||
| // +optional | ||
| SuccessfulJobsHistoryLimit *int32` + " `" + `json:"successfulJobsHistoryLimit,omitempty"` + "`" + ` | ||
|
|
||
| //+kubebuilder:validation:Minimum=0 | ||
|
|
||
| // The number of failed finished jobs to retain. | ||
| // This is a pointer to distinguish between explicit zero and not specified. | ||
| // +optional | ||
| FailedJobsHistoryLimit *int32` + " `" + `json:"failedJobsHistoryLimit,omitempty"` + "`" + ` | ||
| } | ||
|
|
||
| /* | ||
| We define a custom type to hold our concurrency policy. It's actually | ||
| just a string under the hood, but the type gives extra documentation, | ||
| and allows us to attach validation on the type instead of the field, | ||
| making the validation more easily reusable. | ||
| */ | ||
|
|
||
| // ConcurrencyPolicy describes how the job will be handled. | ||
| // Only one of the following concurrent policies may be specified. | ||
| // If none of the following policies is specified, the default one | ||
| // is AllowConcurrent. | ||
| // +kubebuilder:validation:Enum=Allow;Forbid;Replace | ||
| type ConcurrencyPolicy string | ||
|
|
||
| const ( | ||
| // AllowConcurrent allows CronJobs to run concurrently. | ||
| AllowConcurrent ConcurrencyPolicy = "Allow" | ||
|
|
||
| // ForbidConcurrent forbids concurrent runs, skipping next run if previous | ||
| // hasn't finished yet. | ||
| ForbidConcurrent ConcurrencyPolicy = "Forbid" | ||
|
|
||
| // ReplaceConcurrent cancels currently running job and replaces it with a new one. | ||
| ReplaceConcurrent ConcurrencyPolicy = "Replace" | ||
| ) | ||
|
|
||
| /* | ||
| Next, let's design our status, which holds observed state. It contains any information | ||
| we want users or other controllers to be able to easily obtain. | ||
|
|
||
| We'll keep a list of actively running jobs, as well as the last time that we successfully | ||
| ran our job. Notice that we use` + " `" + `metav1.Time` + "`" + ` instead of` + " `" + `time.Time` + "`" + ` to get the stable | ||
| serialization, as mentioned above. | ||
| */` | ||
|
|
||
| const CronjobList = ` | ||
|
|
||
| // A list of pointers to currently running jobs. | ||
| // +optional | ||
| Active []corev1.ObjectReference` + " `" + `json:"active,omitempty"` + "`" + ` | ||
|
|
||
| // Information when was the last time the job was successfully scheduled. | ||
| // +optional | ||
| LastScheduleTime *metav1.Time` + " `" + `json:"lastScheduleTime,omitempty"` + "`" + ` | ||
| } | ||
|
|
||
| /* | ||
| Finally, we have the rest of the boilerplate that we've already discussed. | ||
| As previously noted, we don't need to change this, except to mark that | ||
| we want a status subresource, so that we behave like built-in kubernetes types. | ||
| */ | ||
|
|
||
| ` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Eileen-Yu,
This change is the root cause of the issue.
Can we ensure that it is == before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have updated the code to fix the pipeline.