-
Notifications
You must be signed in to change notification settings - Fork 174
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
Use golangci-lint #111
Use golangci-lint #111
Conversation
Ideally, I would prefer to get rid of this legacy file in favor of golangci-lint, which is the tool that we are using in all the other subprojects. Do you think you could do the migration in this PR? |
Ok, I also prefer golangci-lint a lot. I'll update the PR (and the prometheus-adapter's one) to use it. |
PR updated with golangci-lint. Most changes are just formatting / style / variables renaming (or adding
|
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.
The project really needed it 😆, thank you for looking into that @olivierlemasle
.golangci.yml
Outdated
issues: | ||
exclude-use-default: true | ||
exclude-rules: | ||
# We don't check duplicate code in the tests. |
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.
This is odd, why do we need it?
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.
You're right, I should remove this exclusion.
It was for duplicated code between handleCustomMetrics
and handleExternalMetrics
; but I could refactor that.
Makefile
Outdated
# Format and lint | ||
# --------------- | ||
|
||
GOLANGCI_VERSION:=1.50.1 |
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.
nit: this would be more convenient to have at the top-level for the future since it would allow having all the versions of the tools defined in one block
pkg/apiserver/apiserver.go
Outdated
@@ -41,7 +41,7 @@ func init() { | |||
eminstall.Install(Scheme) | |||
|
|||
// we need custom conversion functions to list resources with options | |||
installer.RegisterConversions(Scheme) | |||
installer.RegisterConversions(Scheme) //nolint: errcheck |
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.
Let's add a todo here to fix this errcheck, not checking errors is pretty bad.
More generally, this piece of code shouldn't be in a init()
function, also it installs both custom-metrics and external-metrics every time even though some projects might only want to import one API.
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.
Ok. I added a nolint exception because I thought it was the same thing that was all over Kubernetes with these zz_generated.conversion.go
files (e.g. here), but with a closer look, it's not.
I agree that this code needs to be reworked because custom-metrics and external-metrics should not be both statically installed unconditionally.
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.
Oh correct, I didn't check what RegisterConversions
was doing when commenting but now that you've explained that is written the same way as zz_generated.conversion.go
generated by the code-generator from k8s, I am fine with keeping the exception.
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.
I switched to k8s.io/apimachinery/pkg/util/runtime.Must()
, which is used in this kind of cases in Kubernetes. It would panic the same way in case of error, but at least it is not linter-specific.
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.
lgtm
@dgrisonnet can we please release a new version once this PR is merged? So we can consume k8s 0.25 deps? Thanks! |
Sure |
Thanks @olivierlemasle! /lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dgrisonnet, olivierlemasle, zroubalik The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Original PR:
Switch to golangci-lint