Skip to content
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

chore: structured logging for pkg/controller #1629

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

var childJobs appsv1alpha1.BroadcastJobList
if err := r.List(ctx, &childJobs, client.InNamespace(advancedCronJob.Namespace), client.MatchingFields{jobOwnerKey: advancedCronJob.Name}); err != nil {
klog.Error(err, "unable to list child Jobs", req.NamespacedName)
klog.ErrorS(err, "Unable to list child Jobs", "advancedCronJob", req)

Check warning on line 52 in pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go#L52

Added line #L52 was not covered by tests
return ctrl.Result{}, err
}

Expand Down Expand Up @@ -98,7 +98,7 @@
// the active jobs themselves.
scheduledTimeForJob, err := getScheduledTimeForJob(&job)
if err != nil {
klog.Error(err, "unable to parse schedule time for child broadcastjob ", job.Name, req.NamespacedName)
klog.ErrorS(err, "Unable to parse schedule time for child BroadcastJob", "broadcastJob", klog.KObj(&job), "advancedCronJob", req)

Check warning on line 101 in pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go#L101

Added line #L101 was not covered by tests
continue
}
if scheduledTimeForJob != nil {
Expand All @@ -120,15 +120,15 @@
for _, activeJob := range activeJobs {
jobRef, err := ref.GetReference(r.scheme, activeJob)
if err != nil {
klog.Error(err, "unable to make reference to active broadcastjob ", " job ", activeJob, req.NamespacedName)
klog.ErrorS(err, "Unable to make reference to active BroadcastJob", "broadcastJob", klog.KObj(activeJob), "advancedCronJob", req)

Check warning on line 123 in pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go#L123

Added line #L123 was not covered by tests
continue
}
advancedCronJob.Status.Active = append(advancedCronJob.Status.Active, *jobRef)
}

klog.V(1).Info("advancedCronJob count ", " active advancedCronJob ", len(activeJobs), " successful advancedCronJob ", len(successfulJobs), " failed advancedCronJob ", len(failedJobs), req.NamespacedName)
klog.V(1).InfoS("AdvancedCronJob count", "activeJobCount", len(activeJobs), "successfulJobCount", len(successfulJobs), "failedJobCount", len(failedJobs), "advancedCronJob", req)
if err := r.updateAdvancedJobStatus(req, &advancedCronJob); err != nil {
klog.Error(err, "unable to update AdvancedCronJob status", req.NamespacedName)
klog.ErrorS(err, "Unable to update AdvancedCronJob status", "advancedCronJob", req)

Check warning on line 131 in pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go#L131

Added line #L131 was not covered by tests
return ctrl.Result{}, err
}

Expand All @@ -154,9 +154,9 @@
break
}
if err := r.Delete(ctx, job, client.PropagationPolicy(metav1.DeletePropagationBackground)); client.IgnoreNotFound(err) != nil {
klog.Error(err, "unable to delete old failed broadcastjob", "job", job, req.NamespacedName)
klog.ErrorS(err, "Unable to delete old failed BroadcastJob", "oldFailedBroadcastJob", klog.KObj(job), "advancedCronJob", req)

Check warning on line 157 in pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go#L157

Added line #L157 was not covered by tests
} else {
klog.V(0).Info("deleted old failed broadcastjob", "job", job, req.NamespacedName)
klog.InfoS("Deleted old failed BroadcastJob", "oldFailedBroadcastJob", klog.KObj(job), "advancedCronJob", req)

Check warning on line 159 in pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go#L159

Added line #L159 was not covered by tests
}
}
}
Expand All @@ -173,9 +173,9 @@
break
}
if err := r.Delete(ctx, job, client.PropagationPolicy(metav1.DeletePropagationBackground)); (err) != nil {
klog.Error(err, "unable to delete old successful broadcastjob ", job.Name, req.NamespacedName)
klog.ErrorS(err, "Unable to delete old successful BroadcastJob", "oldSuccessfulBroadcastJob", klog.KObj(job), "advancedCronJob", req)

Check warning on line 176 in pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go#L176

Added line #L176 was not covered by tests
} else {
klog.V(0).Info("deleted old successful broadcastjob ", job.Name, req.NamespacedName)
klog.InfoS("Deleted old successful BroadcastJob", "oldSuccessfulBroadcastJob", klog.KObj(job), "advancedCronJob", req)

Check warning on line 178 in pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go#L178

Added line #L178 was not covered by tests
}
}
}
Expand All @@ -187,7 +187,7 @@
*/

if advancedCronJob.Spec.Paused != nil && *advancedCronJob.Spec.Paused {
klog.V(1).Info("advancedCronJob paused, skipping", req.NamespacedName)
klog.V(1).InfoS("AdvancedCronJob paused, skipping", "advancedCronJob", req)

Check warning on line 190 in pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go#L190

Added line #L190 was not covered by tests
return ctrl.Result{}, nil
}

Expand Down Expand Up @@ -265,7 +265,7 @@
now := realClock{}.Now()
missedRun, nextRun, err := getNextSchedule(&advancedCronJob, now)
if err != nil {
klog.Error(err, "unable to figure out CronJob schedule", req.NamespacedName)
klog.ErrorS(err, "Unable to figure out CronJob schedule", "advancedCronJob", req)
// we don't really care about requeuing until we get an update that
// fixes the schedule, so don't return an error
return ctrl.Result{}, nil
Expand All @@ -282,7 +282,7 @@
If we've missed a run, and we're still within the deadline to start it, we'll need to run a job.
*/
if missedRun.IsZero() {
klog.V(1).Info("no upcoming scheduled times, sleeping until next now ", now, " and next run ", nextRun, req.NamespacedName)
klog.V(1).InfoS("No upcoming scheduled times, sleeping until next run", "now", now, "nextRun", nextRun, "advancedCronJob", req)

Check warning on line 285 in pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go#L285

Added line #L285 was not covered by tests
return scheduledResult, nil
}

Expand All @@ -292,7 +292,7 @@
tooLate = missedRun.Add(time.Duration(*advancedCronJob.Spec.StartingDeadlineSeconds) * time.Second).Before(now)
}
if tooLate {
klog.V(1).Info("missed starting deadline for last run, sleeping till next", "current run", missedRun, req.NamespacedName)
klog.V(1).InfoS("Missed starting deadline for last run, sleeping till next run", "missedRun", missedRun, "advancedCronJob", req)

Check warning on line 295 in pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go#L295

Added line #L295 was not covered by tests
return scheduledResult, nil
}

Expand All @@ -304,7 +304,7 @@
// figure out how to run this job -- concurrency policy might forbid us from running
// multiple at the same time...
if advancedCronJob.Spec.ConcurrencyPolicy == appsv1alpha1.ForbidConcurrent && len(activeJobs) > 0 {
klog.V(1).Info("concurrency policy blocks concurrent runs, skipping", "num active", len(activeJobs), req.NamespacedName)
klog.V(1).InfoS("Concurrency policy blocks concurrent runs, skipping", "activeBroadcastJobCount", len(activeJobs), "advancedCronJob", req)

Check warning on line 307 in pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go#L307

Added line #L307 was not covered by tests
return scheduledResult, nil
}

Expand All @@ -313,7 +313,7 @@
for _, activeJob := range activeJobs {
// we don't care if the job was already deleted
if err := r.Delete(ctx, activeJob, client.PropagationPolicy(metav1.DeletePropagationBackground)); client.IgnoreNotFound(err) != nil {
klog.Error(err, "unable to delete active broadcastjob", "job", activeJob, req.NamespacedName)
klog.ErrorS(err, "Unable to delete active broadcastjob", "broadcastJob", klog.KObj(activeJob), "advancedCronJob", req)

Check warning on line 316 in pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go#L316

Added line #L316 was not covered by tests
return ctrl.Result{}, err
}
}
Expand Down Expand Up @@ -360,18 +360,18 @@
// actually make the job...
job, err := constructBrJobForCronJob(&advancedCronJob, missedRun)
if err != nil {
klog.Error(err, "unable to construct broadcastjob from template", req.NamespacedName)
klog.ErrorS(err, "Unable to construct broadcastjob from template", "advancedCronJob", req)

Check warning on line 363 in pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go#L363

Added line #L363 was not covered by tests
// don't bother requeuing until we get a change to the spec
return scheduledResult, nil
}

// ...and create it on the cluster
if err := r.Create(ctx, job); err != nil {
klog.Error(err, "unable to create BroadcastJob for CronJob", "job", job, req.NamespacedName)
klog.ErrorS(err, "Unable to create BroadcastJob for CronJob", "broadcastJob", klog.KObj(job), "advancedCronJob", req)

Check warning on line 370 in pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go#L370

Added line #L370 was not covered by tests
return ctrl.Result{}, err
}

klog.V(1).Info("created BroadcastJob for CronJob run", "job", job, req.NamespacedName)
klog.V(1).InfoS("Created BroadcastJob for CronJob run", "broadcastJob", klog.KObj(job), "advancedCronJob", req)

Check warning on line 374 in pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_broadcastjob_controller.go#L374

Added line #L374 was not covered by tests

/*
### 7: Requeue when we either see a running job or it's time for the next scheduled run
Expand Down
18 changes: 9 additions & 9 deletions pkg/controller/advancedcronjob/advancedcronjob_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,28 @@
// add adds a new Controller to mgr with r as the reconcile.Reconciler
func add(mgr manager.Manager, r reconcile.Reconciler) error {
// Create a new controller
klog.Info("Starting AdvancedCronJob Controller")
klog.InfoS("Starting AdvancedCronJob Controller")

Check warning on line 79 in pkg/controller/advancedcronjob/advancedcronjob_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_controller.go#L79

Added line #L79 was not covered by tests
c, err := controller.New("advancedcronjob-controller", mgr, controller.Options{Reconciler: r,
MaxConcurrentReconciles: concurrentReconciles, CacheSyncTimeout: util.GetControllerCacheSyncTimeout()})
if err != nil {
klog.Error(err)
klog.ErrorS(err, "Failed to create AdvandedCronJob controller")

Check warning on line 83 in pkg/controller/advancedcronjob/advancedcronjob_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_controller.go#L83

Added line #L83 was not covered by tests
return err
}

// Watch for changes to AdvancedCronJob
src := source.Kind(mgr.GetCache(), &appsv1alpha1.AdvancedCronJob{})
if err = c.Watch(src, &handler.EnqueueRequestForObject{}); err != nil {
klog.Error(err)
klog.ErrorS(err, "Failed to watch AdvancedCronJob")

Check warning on line 90 in pkg/controller/advancedcronjob/advancedcronjob_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_controller.go#L90

Added line #L90 was not covered by tests
return err
}

if err = watchJob(mgr, c); err != nil {
klog.Error(err)
klog.ErrorS(err, "Failed to watch Job")

Check warning on line 95 in pkg/controller/advancedcronjob/advancedcronjob_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_controller.go#L95

Added line #L95 was not covered by tests
return err
}

if err = watchBroadcastJob(mgr, c); err != nil {
klog.Error(err)
klog.ErrorS(err, "Failed to watch BroadcastJob")

Check warning on line 100 in pkg/controller/advancedcronjob/advancedcronjob_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_controller.go#L100

Added line #L100 was not covered by tests
return err
}
return nil
Expand Down Expand Up @@ -133,7 +133,7 @@

func (r *ReconcileAdvancedCronJob) Reconcile(_ context.Context, req ctrl.Request) (ctrl.Result, error) {
ctx := context.Background()
klog.Info("Running AdvancedCronJob job ", req.NamespacedName)
klog.InfoS("Running AdvancedCronJob job", "advancedCronJob", req)

namespacedName := types.NamespacedName{
Namespace: req.Namespace,
Expand All @@ -143,7 +143,7 @@
var advancedCronJob appsv1alpha1.AdvancedCronJob

if err := r.Get(ctx, namespacedName, &advancedCronJob); err != nil {
klog.Error(err, "unable to fetch CronJob", req.NamespacedName)
klog.ErrorS(err, "Unable to fetch CronJob", "advancedCronJob", req)

Check warning on line 146 in pkg/controller/advancedcronjob/advancedcronjob_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_controller.go#L146

Added line #L146 was not covered by tests
// we'll ignore not-found errors, since they can't be fixed by an immediate
// requeue (we'll need to wait for a new notification), and we can get them
// on deleted requests.
Expand All @@ -156,7 +156,7 @@
case appsv1alpha1.BroadcastJobTemplate:
return r.reconcileBroadcastJob(ctx, req, advancedCronJob)
default:
klog.Info("No template found", req.NamespacedName)
klog.InfoS("No template found", "advancedCronJob", req)

Check warning on line 159 in pkg/controller/advancedcronjob/advancedcronjob_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_controller.go#L159

Added line #L159 was not covered by tests
}

return ctrl.Result{}, nil
Expand All @@ -169,7 +169,7 @@
}

func (r *ReconcileAdvancedCronJob) updateAdvancedJobStatus(request reconcile.Request, advancedCronJob *appsv1alpha1.AdvancedCronJob) error {
klog.V(1).Info(fmt.Sprintf("Updating job %s status %#v", advancedCronJob.Name, advancedCronJob.Status))
klog.V(1).InfoS("Updating job status", "advancedCronJob", klog.KObj(advancedCronJob), "status", advancedCronJob.Status)
advancedCronJobCopy := advancedCronJob.DeepCopy()
return retry.RetryOnConflict(retry.DefaultRetry, func() error {
err := r.Status().Update(context.TODO(), advancedCronJobCopy)
Expand Down
36 changes: 18 additions & 18 deletions pkg/controller/advancedcronjob/advancedcronjob_job_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
advancedCronJob.Status.Type = appsv1alpha1.JobTemplate
var childJobs batchv1.JobList
if err := r.List(ctx, &childJobs, client.InNamespace(advancedCronJob.Namespace), client.MatchingFields{jobOwnerKey: advancedCronJob.Name}); err != nil {
klog.Error(err, "unable to list child Jobs", req.NamespacedName)
klog.ErrorS(err, "Unable to list child Jobs", "advancedCronJob", req)

Check warning on line 55 in pkg/controller/advancedcronjob/advancedcronjob_job_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_job_controller.go#L55

Added line #L55 was not covered by tests
return ctrl.Result{}, err
}

Expand Down Expand Up @@ -101,7 +101,7 @@
// the active jobs themselves.
scheduledTimeForJob, err := getScheduledTimeForJob(&job)
if err != nil {
klog.Error(err, "unable to parse schedule time for child job", "job", &job, req.NamespacedName)
klog.ErrorS(err, "Unable to parse schedule time for child job", "job", klog.KObj(&job), "advancedCronJob", req)

Check warning on line 104 in pkg/controller/advancedcronjob/advancedcronjob_job_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_job_controller.go#L104

Added line #L104 was not covered by tests
continue
}
if scheduledTimeForJob != nil {
Expand All @@ -123,15 +123,15 @@
for _, activeJob := range activeJobs {
jobRef, err := ref.GetReference(r.scheme, activeJob)
if err != nil {
klog.Error(err, "unable to make reference to active job", "job", activeJob, req.NamespacedName)
klog.ErrorS(err, "Unable to make reference to active job", "job", klog.KObj(activeJob), "advancedCronJob", req)

Check warning on line 126 in pkg/controller/advancedcronjob/advancedcronjob_job_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_job_controller.go#L126

Added line #L126 was not covered by tests
continue
}
advancedCronJob.Status.Active = append(advancedCronJob.Status.Active, *jobRef)
}

klog.V(1).Info("job count ", " active jobs ", len(activeJobs), " successful jobs ", len(successfulJobs), " failed jobs ", len(failedJobs), req.NamespacedName)
klog.V(1).InfoS("Job count", "activeJobCount", len(activeJobs), "successfulJobCount", len(successfulJobs), "failedJobCount", len(failedJobs), "advancedCronJob", req)
if err := r.updateAdvancedJobStatus(req, &advancedCronJob); err != nil {
klog.Error(err, "unable to update AdvancedCronJob status", req.NamespacedName)
klog.ErrorS(err, "Unable to update AdvancedCronJob status", "advancedCronJob", req)

Check warning on line 134 in pkg/controller/advancedcronjob/advancedcronjob_job_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_job_controller.go#L134

Added line #L134 was not covered by tests
return ctrl.Result{}, err
}

Expand All @@ -157,9 +157,9 @@
break
}
if err := r.Delete(ctx, job, client.PropagationPolicy(metav1.DeletePropagationBackground)); client.IgnoreNotFound(err) != nil {
klog.Error(err, "unable to delete old failed job ", job.Name, req.NamespacedName)
klog.ErrorS(err, "Unable to delete old failed job", "job", klog.KObj(job), "advancedCronJob", req)

Check warning on line 160 in pkg/controller/advancedcronjob/advancedcronjob_job_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_job_controller.go#L160

Added line #L160 was not covered by tests
} else {
klog.V(0).Info("deleted old failed job ", job.Name, req.NamespacedName)
klog.InfoS("Deleted old failed job", "job", klog.KObj(job), "advancedCronJob", req)

Check warning on line 162 in pkg/controller/advancedcronjob/advancedcronjob_job_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_job_controller.go#L162

Added line #L162 was not covered by tests
}
}
}
Expand All @@ -176,9 +176,9 @@
break
}
if err := r.Delete(ctx, job, client.PropagationPolicy(metav1.DeletePropagationBackground)); (err) != nil {
klog.Error(err, "unable to delete old successful job ", job.Name, req.NamespacedName)
klog.ErrorS(err, "Unable to delete old successful job", "job", klog.KObj(job), "advancedCronJob", req)

Check warning on line 179 in pkg/controller/advancedcronjob/advancedcronjob_job_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_job_controller.go#L179

Added line #L179 was not covered by tests
} else {
klog.V(0).Info("deleted old successful job ", job.Name, req.NamespacedName)
klog.InfoS("Deleted old successful job", "job", klog.KObj(job), "advancedCronJob", req)

Check warning on line 181 in pkg/controller/advancedcronjob/advancedcronjob_job_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_job_controller.go#L181

Added line #L181 was not covered by tests
}
}
}
Expand All @@ -190,7 +190,7 @@
*/

if advancedCronJob.Spec.Paused != nil && *advancedCronJob.Spec.Paused {
klog.V(1).Info("cronjob paused, skipping", req.NamespacedName)
klog.V(1).InfoS("CronJob paused, skipping", "advancedCronJob", req)

Check warning on line 193 in pkg/controller/advancedcronjob/advancedcronjob_job_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_job_controller.go#L193

Added line #L193 was not covered by tests
return ctrl.Result{}, nil
}

Expand Down Expand Up @@ -268,7 +268,7 @@
now := realClock{}.Now()
missedRun, nextRun, err := getNextSchedule(&advancedCronJob, now)
if err != nil {
klog.Error(err, "unable to figure out CronJob schedule", req.NamespacedName)
klog.ErrorS(err, "Unable to figure out CronJob schedule", "advancedCronJob", req)
// we don't really care about requeuing until we get an update that
// fixes the schedule, so don't return an error
return ctrl.Result{}, nil
Expand All @@ -285,7 +285,7 @@
If we've missed a run, and we're still within the deadline to start it, we'll need to run a job.
*/
if missedRun.IsZero() {
klog.V(1).Info("no upcoming scheduled times, sleeping until next now ", now, " and next run ", nextRun, req.NamespacedName)
klog.V(1).InfoS("No upcoming scheduled times, sleeping until next run", "now", now, "nextRun", nextRun, "advancedCronJob", req)

Check warning on line 288 in pkg/controller/advancedcronjob/advancedcronjob_job_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_job_controller.go#L288

Added line #L288 was not covered by tests
return scheduledResult, nil
}

Expand All @@ -295,7 +295,7 @@
tooLate = missedRun.Add(time.Duration(*advancedCronJob.Spec.StartingDeadlineSeconds) * time.Second).Before(now)
}
if tooLate {
klog.V(1).Info("missed starting deadline for last run, sleeping till next", "current run", missedRun, req.NamespacedName)
klog.V(1).InfoS("Missed starting deadline for last run, sleeping till next run", "missedRun", missedRun, "advancedCronJob", req)

Check warning on line 298 in pkg/controller/advancedcronjob/advancedcronjob_job_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_job_controller.go#L298

Added line #L298 was not covered by tests
return scheduledResult, nil
}

Expand All @@ -307,7 +307,7 @@
// figure out how to run this job -- concurrency policy might forbid us from running
// multiple at the same time...
if advancedCronJob.Spec.ConcurrencyPolicy == appsv1alpha1.ForbidConcurrent && len(activeJobs) > 0 {
klog.V(1).Info("concurrency policy blocks concurrent runs, skipping", "num active", len(activeJobs), req.NamespacedName)
klog.V(1).InfoS("Concurrency policy blocks concurrent runs, skipping", "activeJobCount", len(activeJobs), "advancedCronJob", req)

Check warning on line 310 in pkg/controller/advancedcronjob/advancedcronjob_job_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_job_controller.go#L310

Added line #L310 was not covered by tests
return scheduledResult, nil
}

Expand All @@ -316,7 +316,7 @@
for _, activeJob := range activeJobs {
// we don't care if the job was already deleted
if err := r.Delete(ctx, activeJob, client.PropagationPolicy(metav1.DeletePropagationBackground)); client.IgnoreNotFound(err) != nil {
klog.Error(err, "unable to delete active job", "job", activeJob, req.NamespacedName)
klog.ErrorS(err, "Unable to delete active job", "job", klog.KObj(activeJob), "advancedCronJob", req)

Check warning on line 319 in pkg/controller/advancedcronjob/advancedcronjob_job_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_job_controller.go#L319

Added line #L319 was not covered by tests
return ctrl.Result{}, err
}
}
Expand Down Expand Up @@ -363,18 +363,18 @@
// actually make the job...
job, err := constructJobForCronJob(&advancedCronJob, missedRun)
if err != nil {
klog.Error(err, "unable to construct job from template", req.NamespacedName)
klog.ErrorS(err, "Unable to construct job from template", "advancedCronJob", req)

Check warning on line 366 in pkg/controller/advancedcronjob/advancedcronjob_job_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_job_controller.go#L366

Added line #L366 was not covered by tests
// don't bother requeuing until we get a change to the spec
return scheduledResult, nil
}

// ...and create it on the cluster
if err := r.Create(ctx, job); err != nil {
klog.Error(err, "unable to create Job for AdvancedCronJob", "job", job, req.NamespacedName)
klog.ErrorS(err, "Unable to create Job for AdvancedCronJob", "job", klog.KObj(job), "advancedCronJob", req)

Check warning on line 373 in pkg/controller/advancedcronjob/advancedcronjob_job_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_job_controller.go#L373

Added line #L373 was not covered by tests
return ctrl.Result{}, err
}

klog.V(1).Info("created Job for AdvancedCronJob run", "job", job, req.NamespacedName)
klog.V(1).InfoS("Created Job for AdvancedCronJob run", "job", klog.KObj(job), "advancedCronJob", req)

Check warning on line 377 in pkg/controller/advancedcronjob/advancedcronjob_job_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_job_controller.go#L377

Added line #L377 was not covered by tests

/*
### 7: Requeue when we either see a running job or it's time for the next scheduled run
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/advancedcronjob/advancedcronjob_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}
if acj.Spec.TimeZone != nil {
if _, err := time.LoadLocation(*acj.Spec.TimeZone); err != nil {
klog.Errorf("Failed to load location %s for %s/%s: %v", *acj.Spec.TimeZone, acj.Namespace, acj.Name, err)
klog.ErrorS(err, "Failed to load location for advancedCronJob", "location", *acj.Spec.TimeZone, "advancedCronJob", klog.KObj(acj))

Check warning on line 26 in pkg/controller/advancedcronjob/advancedcronjob_utils.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/advancedcronjob/advancedcronjob_utils.go#L26

Added line #L26 was not covered by tests
return acj.Spec.Schedule
}
return fmt.Sprintf("TZ=%s %s", *acj.Spec.TimeZone, acj.Spec.Schedule)
Expand Down
Loading
Loading