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
Add hack/update-goimports.sh #76863
Add hack/update-goimports.sh #76863
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: johnSchnake If they are not already assigned, you can assign the PR to them by writing 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 |
Obviously a large diff but again, the only thing I did was add the script and run goimports just like To sanity check the changes I also ran:
Obviously, you can look at each but this was helpful to me. There are actually very few changes and they fall into a few categories:
|
So there is some gauth issue preventing some things from running (says the service is down) but besides that there is some issue for me to resolve/consider. I wouldn't have expected bazel to need updated after this but doing so I sfound a fair number of changes like this:
I guess it is picking up my local structure and using that instead of how it should be working. |
Confirmed that in some cases it did changes like this:
It added the local import path instead of the k8s.io one. |
62800ef
to
419150e
Compare
Got the 'not something we can merge' error; retesting. I think the fix for the vendor issue was to ensure go modules were getting used. /retest |
not something we can merge... /retest |
So using go modules fixed one set of problems but now I am running into an issue where goimports is redefining certain imports in addition to the one that is already there (ie adding the alias without removing the unalised version) Could fix up a number of files manually but the whole point of the script is that that shouldn't be necessary. |
@johnSchnake: The following tests failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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. I understand the commands that are listed here. |
the script and diff in the second commit LGTM (as much as github can show it).
sounds like a goimports bug. |
I'm effectively suggesting adding this because I needed it and it seemed like a useful util if other people do refactor with a similarly large impact. I effectively had so many files impacted that it made sense to script it, but then I hit all the other aliases and it made the diff even larger so I split it out into this PR. If we'd rather not put something like this explicitly in the code base I understand and will just try and leverage it to accomplish my goal without running goimports against all these other files. |
/remove-sig api-machinery |
@johnSchnake: PR needs rebase. 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. |
Did you place the kubernetes directory in I ran into the same problem with import error after running the script.... $ cat staging/src/k8s.io/client-go/kubernetes/typed/core/v1/fake/fake_namespace_expansion.go
// ...
package fake
import (
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
core "k8s.io/client-go/testing"
) |
/assign @timothysc @ixdy |
Going to close this since it has too much surface area to be feasible at this time, let alone the bugs that I seemed to run into. I will probably try smaller endeavors to just run goimports on swathes of the codebase which are of interest. Anyone is welcome to follow suit. |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
When doing large refactors, if you move functionality from
one package to another, it may be necessary to update the
imports of a large number of files. Rather than require
this to be a manual process, this script automates it.
In this initial commit, there are also a number of imports
updated as aliases. This is something goimports does as a
result of the real path differing from the import path
(due to symlinks in the repo).
Which issue(s) this PR fixes:
In support of:
ref #76206
ref #76728
Special notes for your reviewer:
This specifically came up when I was trying to work on #76728 which required updates to the imports of hundreds of files.
In this PR I simply added the update-goimports.sh file (modeled on update-gofmt.sh) and then ran it once.
Does this PR introduce a user-facing change?: