@@ -16,7 +16,7 @@ limitations under the License.
16
16
17
17
/*
18
18
We'll start out with some imports. You'll see below that we'll need a few more imports
19
- than those scaffolded for us. We'll take about each one when we use it.
19
+ than those scaffolded for us. We'll talk about each one when we use it.
20
20
*/
21
21
package controllers
22
22
@@ -56,8 +56,8 @@ type CronJobReconciler struct {
56
56
}
57
57
58
58
/*
59
- We'll mock out the clock to make it easier to jump around in time while testing
60
- The "real" clock just calls time.Now.
59
+ We'll mock out the clock to make it easier to jump around in time while testing,
60
+ the "real" clock just calls ` time.Now` .
61
61
*/
62
62
type realClock struct {}
63
63
@@ -72,9 +72,9 @@ type Clock interface {
72
72
// +kubebuilder:docs-gen:collapse=Clock
73
73
74
74
/*
75
- We generally want to ignore (not requeue) on NotFound errors,
76
- since we'll get a reconcile request once the object becomes found,
77
- and requeuing in the mean time won't help.
75
+ We generally want to ignore (not requeue) NotFound errors, since we'll get a
76
+ reconciliation request once the object exists, and requeuing in the meantime
77
+ won't help.
78
78
*/
79
79
func ignoreNotFound (err error ) error {
80
80
if apierrs .IsNotFound (err ) {
@@ -107,7 +107,7 @@ func (r *CronJobReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
107
107
log := r .Log .WithValues ("cronjob" , req .NamespacedName )
108
108
109
109
/*
110
- ### 1: Load the named CronJob
110
+ ### 1: Load the CronJob by name
111
111
112
112
We'll fetch the CronJob using our client. All client methods take a context
113
113
(to allow for cancellation) as their first argument, and the object in question
@@ -146,7 +146,7 @@ func (r *CronJobReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
146
146
root object. Instead, you should reconstruct it every run. That's what we'll
147
147
do here.
148
148
149
- We can check if a job is "finished" and whether is succeeded or failed using status
149
+ We can check if a job is "finished" and whether it succeeded or failed using status
150
150
conditions. We'll put that logic in a helper to make our code cleaner.
151
151
*/
152
152
@@ -243,7 +243,7 @@ func (r *CronJobReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
243
243
/*
244
244
Using the date we've gathered, we'll update the status of our CRD.
245
245
Just like before, we use our client. To specifically update the status
246
- subresource, we'll use the the `Status` part of the client, with the `Update`
246
+ subresource, we'll use the `Status` part of the client, with the `Update`
247
247
method.
248
248
249
249
The status subresource ignores changes to spec, so it's less likely to conflict
@@ -302,7 +302,7 @@ func (r *CronJobReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
302
302
303
303
/* ### 4: Check if we're suspended
304
304
305
- If this object is supsended , we don't want to run any jobs, so we'll stop now.
305
+ If this object is suspended , we don't want to run any jobs, so we'll stop now.
306
306
This is useful if something's broken with the job we're running and we want to
307
307
pause runs to investigate or putz with the cluster, without deleting the object.
308
308
*/
@@ -315,7 +315,7 @@ func (r *CronJobReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
315
315
/*
316
316
### 5: Get the next scheduled run
317
317
318
- If we're not pause , we'll need to calculate the next scheduled run, and whether
318
+ If we're not paused , we'll need to calculate the next scheduled run, and whether
319
319
or not we've got a run that we haven't processed yet.
320
320
*/
321
321
@@ -328,7 +328,7 @@ func (r *CronJobReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
328
328
bail so that we don't cause issues on controller restarts or wedges.
329
329
330
330
Otherwise, we'll just return the missed runs (of which we'll just use the latest),
331
- and the next run, so that we can know the latest time to reconcile again.
331
+ and the next run, so that we can know when it's time to reconcile again.
332
332
*/
333
333
getNextSchedule := func (cronJob * batch.CronJob , now time.Time ) (lastMissed * time.Time , next time.Time , err error ) {
334
334
sched , err := cron .ParseStandard (cronJob .Spec .Schedule )
@@ -337,7 +337,7 @@ func (r *CronJobReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
337
337
}
338
338
339
339
// for optimization purposes, cheat a bit and start from our last observed run time
340
- // we could reconsitute this here, but there's not much point, since we've
340
+ // we could reconstitute this here, but there's not much point, since we've
341
341
// just updated it.
342
342
var earliestTime time.Time
343
343
if cronJob .Status .LastScheduleTime != nil {
@@ -361,8 +361,8 @@ func (r *CronJobReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
361
361
for t := sched .Next (earliestTime ); ! t .After (now ); t = sched .Next (t ) {
362
362
lastMissed = & t
363
363
// An object might miss several starts. For example, if
364
- // controller gets wedged on friday at 5:01pm when everyone has
365
- // gone home, and someone comes in on tuesday AM and discovers
364
+ // controller gets wedged on Friday at 5:01pm when everyone has
365
+ // gone home, and someone comes in on Tuesday AM and discovers
366
366
// the problem and restarts the controller, then all the hourly
367
367
// jobs, more than 80 of them for one hourly scheduledJob, should
368
368
// all start running with no further intervention (if the scheduledJob
@@ -377,7 +377,7 @@ func (r *CronJobReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
377
377
starts ++
378
378
if starts > 100 {
379
379
// We can't get the most recent times so just return an empty slice
380
- return nil , time.Time {}, fmt .Errorf ("Too many missed start time (> 100). Set or decrease .spec.startingDeadlineSeconds or check clock skew." )
380
+ return nil , time.Time {}, fmt .Errorf ("Too many missed start times (> 100). Set or decrease .spec.startingDeadlineSeconds or check clock skew." )
381
381
}
382
382
}
383
383
return lastMissed , sched .Next (now ), nil
@@ -522,7 +522,7 @@ func (r *CronJobReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
522
522
523
523
Finally, we'll update our setup. In order to allow our reconciler to quickly
524
524
look up Jobs by their owner, we'll need an index. We declare an index key that
525
- we can later use with the client as a pseudo-field name, and then descibe how to
525
+ we can later use with the client as a pseudo-field name, and then describe how to
526
526
extract the indexed value from the Job object. The indexer will automatically take
527
527
care of namespaces for us, so we just have to extract the owner name if the Job has
528
528
a CronJob owner.
0 commit comments