-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Fix local imports, add appropriate linter #2962
Conversation
Hi @kolyshkin. Thanks for your PR. I'm waiting for a google member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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/test-infra repository. |
The steps this commit was made are:
|
/ok-to-test |
057aa73
to
108705a
Compare
Going to redo this in a cleaner way |
4670a26
to
9003f48
Compare
/retest |
No longer a draft. @bobbypage can you please re-trigger the e2e ci job? |
/retest |
sorry for conflict, can you please rebase? |
This is required because goimports@v0.1.7 fails to recognize this import, adding a duplicated one. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This is required since goimports@v0.1.7 can not recognize that import "github.com/mesos/mesos-go/api/v1/lib" gives the name "mesos" to the imported package (frankly, I can't do that either). The patch is generated by git grep -l '"github.com/mesos/mesos-go/api/v1/lib"' | \ xargs sed -i 's|"github.com/mesos/mesos-go/api/v1/lib"|mesos \0|' Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
NP; done |
94cbb3c
to
1ef61c2
Compare
@bobbypage PTAL; need to re-run e2e test again; apparently I can't initiate it. |
/retest |
/retest |
hmm, now the prow presubmit is failing with
I think it's because it's using COS (https://cloud.google.com/container-optimized-os/docs) as OS image there, and docker runs to be run under sudo in COS... Not sure on best solution, maybe we can check if we need to use sudo on docker or not? Or maybe alternatively we can install the |
The doc (https://cloud.google.com/container-optimized-os/docs/how-to/run-container-instance) does not tell anything about sudo, and uses I have added a debug commit, let's see what it shows.
Surely I can do that, too. |
My debug don't reveal anything, and alas I know nothing about prow or COS.
As much as I don't like shortcuts, it seems the best option is to install golangci-lint if not available. I'll add it to Makefile. |
Changes from v1 are: - Adds GOBIN to the PATH - Proxy Support - stable input - Bug Fixes (including issues around version matching and semver) Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Check if golangci-lint is available locally -- if not, install it to GOPATH/bin. This helps with cases when golangci-lint is not available on the host (such as in prow). As we now have golangci-lint installation in Makefile, remove the code installing it from .github/workflows/test.yml for better maintainability. While at it, add lint to .PHONY targets. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Redid with golangci-lint being auto-installed from Makefile if absent. Apparently, since now test CI job runs make presubmit, which runs golangci-lint, the whole lint job is no longer required, so I have removed it 👍🏻 This means that after this PR is merged, you need to go to https://github.com/google/cadvisor/settings/branches, find "Branch protection rules" and edit those to remove lint jobs from the list of required ones. Now lint is part of test. |
In fact you have to do it before the merge, because apparently GHA CI is run using config from the PR (rather than the master branch). |
@bobbypage it's finally ready 🥵 |
@Creatone this "let's fix those imports" remark resulted in much more work that I had anticipated 😃 |
@kolyshkin I meant fix only imports for changed files :D Thanks for your contribution! |
@bobbypage PTAL 🙏🏻 (the "missing" checks are removed, see #2962 (comment)) |
Big thank you @kolyshkin for all your work here and cleanup in process. I've removed the lint github action checks as you suggested since they're no longer necessary. LGTM! |
One last comment - #2962 (comment). Please let me know if there is any changes needed there that we can simplify and we can merge this! |
1. Modify Makefile's format target to format imports in three groups: - standard library packages; - third-party packages; - local packages (i.e. ones with the `github.com/google/cadvisor` prefix). Note goimports does the same job as gofmt, plus imports sorting. It can't do what gofmt -s does, but it was not done before (although this is checked according to .golangci.yml), so let's leave it as is. Note we don't have to use $(pkgs) and $(cmd_pkgs) in Makefile's format target, as goimports works recursively given the current directory, and it also skips vendor dir. 2. Add goimports linter with proper configuration to check imports formatting in CI. Check that the linter complains. 3. Actually implements these changes by running "make format". Check that the linter no longer complains. 4. Fix presubmit target to make sure it checks the new formatting rules. Instead of modifying build/check_gofmt.sh, let's use golangci-lint which already does this check (and more). While at it, let's remove vet target, as lint (golangci-lint) already calls it. Now, since make presumbit is already there in test job, the whole lint job is superseded by it, so let's remove it. While doing it, make sure we use the code from lint job to run make presubmit, with the following two exceptions: - "set -e" is not required, as it is set by GHA CI; - GOFLAGS="$GO_FLAGS" is not required, as it is done by Makefile. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This one is ready I think. I found another semi-related issue though -- since As this is definitely not an issue with this PR, I am going to address this separately. |
perfect, thanks again @kolyshkin! |
@Creatone points out in #2959 comments that imports are not properly grouped.
This PR
Fixes a few imports that
goimports
chokes on (first 2 commits).Modifies Makefile's format target to format imports in three groups:
github.com/google/cadvisor
prefix).Note goimports does the same thing as gofmt, plus imports sorting.
It can't do what
gofmt -s
does, but it was not done before (althoughit is checked according to
.golangci.yml)
, so let's leave it as is.Adds goimports linter with proper configuration to check imports
formatting in CI. At this step we have checked that the linter does complain.
Actually implements these changes by running
make format
.The linter no longer complains.
Please review commit-by-commit.