CronJob tutorial: old successful Job cleanup does not ignore NotFound errors
What broke? What's expected?
In the CronJob tutorial controller, the cleanup of old finished Jobs handles errors differently for failed and successful Jobs.
Failed Jobs ignore NotFound: https://github.com/kubernetes-sigs/kubebuilder/blob/bd42805bc8/hack/docs/internal/cronjob-tutorial/controller_implementation.go#L407
if err := r.Delete(ctx, job, client.PropagationPolicy(metav1.DeletePropagationBackground)); client.IgnoreNotFound(err) != nil {Successful Jobs do not: https://github.com/kubernetes-sigs/kubebuilder/blob/bd42805bc8/hack/docs/internal/cronjob-tutorial/controller_implementation.go#L438
if err := r.Delete(ctx, job, client.PropagationPolicy(metav1.DeletePropagationBackground)); err != nil {If an old successful Job is already gone (for example, the cache still lists a Job that was just deleted), the controller logs unable to delete old successful job as an error, even though the Job is already deleted.
This looks unintentional.
Before #1285, both deletes used the old ignoreNotFound(err) helper. In commit f9f8f599 (#1285), the failed-job delete was changed to client.IgnoreNotFound(err), but the successful-job delete became (err) != nil
There is no functional impact, but it is a misleading error log, and the tutorial shows two different patterns for the same operation.
Expected: use client.IgnoreNotFound(err) for successful Jobs too, the same as for failed Jobs.
The same code is in the generated testdata for the cronjob and multiversion tutorials.
I'd like to send a PR for this!
Reproducing this issue
No runtime reproduction needed; it can be seen in the code above.
KubeBuilder (CLI) Version
4.16.0
PROJECT version
3
Plugin versions
go.kubebuilder.io/v4Other versions
- Go 1.26.4
- controller-runtime v0.25.0
- controller-tools v0.22.0
Extra Labels
/kind documentation
Source: kubernetes-sigs/kubebuilder