✨ (go/v4): Add custom k8s linter for logs to promote better observability#5396
Conversation
bf6b0ac to
541aa84
Compare
541aa84 to
81c71c5
Compare
9b1bdaf to
f9f164b
Compare
1261225 to
72064ab
Compare
72064ab to
83868c2
Compare
d1006e6 to
4f14542
Compare
| log.Error(err, "unable to delete old successful job", "job", job) | ||
| } else { | ||
| log.V(0).Info("deleted old successful job", "job", job) | ||
| log.V(1).Info("deleted old successful job", "job", job) |
There was a problem hiding this comment.
Fix issue found in the docs samples within
| log.Error(err, "unable to delete old successful job", "job", job) | ||
| } else { | ||
| log.V(0).Info("deleted old successful job", "job", job) | ||
| log.V(1).Info("deleted old successful job", "job", job) |
There was a problem hiding this comment.
Fix issue found in the docs samples within
| log.Error(err, "unable to delete old successful job", "job", job) | ||
| } else { | ||
| log.V(0).Info("deleted old successful job", "job", job) | ||
| log.V(1).Info("deleted old successful job", "job", job) |
There was a problem hiding this comment.
Fix issue found in the docs samples within
| log.Warn("Unable to find boilerplate file. "+ | ||
| "This file is used to generate the license header in the project. "+ | ||
| "Note that controller-gen will also use this. Therefore, ensure that you "+ | ||
| "add the license file or configure your project accordingly.", | ||
| log.Warn("Unable to find boilerplate file "+ | ||
| "used to generate the license header in the project "+ | ||
| "Note that controller-gen will also use this Therefore ensure that you "+ | ||
| "add the license file or configure your project accordingly", |
There was a problem hiding this comment.
This seems like a dup change from PR #5406
See also my #5406 (comment)
There was a problem hiding this comment.
Thank you .. it should not be part of the changes in this PR.
Out of scope.
4f14542 to
ff2b12b
Compare
…ability Assisted-by: Cursor
ff2b12b to
75d7e96
Compare
|
@vitorfloriano any reason for we not LGTM this one? |
vitorfloriano
left a comment
There was a problem hiding this comment.
I was a bit unsure at first because we use log/slog in Kubebuilder itself, but turns out the scaffolds use the logger from controller-runtime, which use logr and klog, so the linter works for the scaffolds.
\lgtm
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: camilamacedo86, vitorfloriano The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
We were able to reproduce the issue as well, and it shows up in our logs, so the current setup appears to be working correctly on our side. |
Long ago I asked similar question on the Slack channel #klog and I think you may find the answers I received there from @pohly (*) informative in the context here, quoting:
(*) I hope Patrick doesn't mind the mention, but I wanted to include persistent reference to source of that quote - I'm not 100% if the history of the Kubernetes Slack space persist. |
|
@mloskot I understand the the linter still valid right? |
|
/override pull-kubebuilder-e2e-k8s-1-34-0 |
|
@camilamacedo86: Overrode contexts on behalf of camilamacedo86: pull-kubebuilder-e2e-k8s-1-34-0 DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
@camilamacedo86 I'd expect the linter to be still valid, but I don't know for sure as I did not dig the topic of future of klog in K8s any further. |
|
I believe
But that's just my reading of the whole thing. |
|
@vitorfloriano Thanks for those references. It looks like there was a plan, that had changed along the way. Here is the part that, I think, can be considered as an update to the quote I posted in #5396 (comment), in this section:
|
What this PR does
Adds the custom linter
sigs.k8s.io/logtools/logcheckto validate logs in Kubebuilder scaffolds.This linter checks for common problematic logging scenarios and fails CI with actionable errors. Example failure output:
https://github.com/kubernetes-sigs/kubebuilder/actions/runs/21430987832/job/61710036984?pr=5396
Why we’re doing this
We checked with the
logcheckmaintainers and, while adoption is relatively low, the project appears stable and maintained:https://kubernetes.slack.com/archives/C020CCMUEAX/p1769592452395209
Given there have been no reported bugs since 2024, it seems like a good fit for improving the quality of scaffolded logging patterns in Kubebuilder.
Links
Fixes: #5330