Skip to content
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

Clean the GO mod files by removing the unnecessary indirect imports #1454

Merged
merged 1 commit into from Apr 13, 2020

Conversation

camilamacedo86
Copy link
Member

@camilamacedo86 camilamacedo86 commented Apr 1, 2020

Description

  • Clean the GO mod files by removing the unnecessary indirect imports
  • fix make generate target to do cause the scenario again.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 1, 2020
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 1, 2020
@camilamacedo86 camilamacedo86 reopened this Apr 1, 2020
@camilamacedo86 camilamacedo86 reopened this Apr 1, 2020
@camilamacedo86
Copy link
Member Author

/test pull-kubebuilder-e2e-k8s-1-16-2

@Adirio
Copy link
Contributor

Adirio commented Apr 2, 2020

My understanding of go mod is pretty basic, I just know what it is needed to use them, but not the internals, so I'm not sure if those indirect imports are needed or not.

P.S.: Checking that tests pass in this case doesn't seem enough because probably none of those of those libraries made a backwards incompatible change so removing the indirect requirement may just get the last version and still work. But in case they make a backwards incompatible change it may break the build.

@camilamacedo86
Copy link
Member Author

camilamacedo86 commented Apr 2, 2020

/assign @mengqiy

@camilamacedo86 camilamacedo86 changed the title remove indirect imports Remove the indirect imports and clean the GO mod file. Apr 2, 2020
@camilamacedo86 camilamacedo86 force-pushed the clean-imports branch 2 times, most recently from d9555e8 to f64df06 Compare April 2, 2020 15:05
@camilamacedo86 camilamacedo86 changed the title Remove the indirect imports and clean the GO mod file. Clean the GO mod files by removing the unnecessary indirect imports Apr 2, 2020
@mengqiy
Copy link
Member

mengqiy commented Apr 2, 2020

I'd trust the go modules to do the job of tracking necessary entries in the go.mod file.
@camilamacedo86 What you can try is that first remove indirect entries and then run go mod tidy. If go modules add some entries back, then we probably should keep them.

@camilamacedo86
Copy link
Member Author

camilamacedo86 commented Apr 2, 2020

Hi @mengqiy,

Unfortunately, go mod tidy has been not removing the unnecessary imports from the go.mod. Note that shows that it has some issues opened for it. May solved for 1.4+?. (E.g golang/go#33008 )

See for example that "github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e" is not required in the main module.

$ go mod why github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e
# github.com/niemeyer/pretty
sigs.k8s.io/kubebuilder/internal/config
sigs.k8s.io/yaml
gopkg.in/yaml.v2
gopkg.in/yaml.v2.test
gopkg.in/check.v1
github.com/niemeyer/pretty

# v0.0.0-20200227124842-a10e7caefd8e
(main module does not need package v0.0.0-20200227124842-a10e7caefd8e)
camilamacedo@Camilas-MacBook-Pro ~/go/src/sigs.k8s.io/kubebuilder (master) $  

Also, note that these indirect imports are just added when we run make generated. And then, see that all indirect imports are in the same situation.

# v0.0.0-20200301022130-244492dfa37a
(main module does not need package v0.0.0-20200301022130-244492dfa37a)
# v0.0.0-20200302083256-062a44052db1
(main module does not need package v0.0.0-20200302083256-062a44052db1)
# v0.0.0-20191204190536-9bdfabe68543
(main module does not need package v0.0.0-20191204190536-9bdfabe68543)
# v1.0.0-20200227125254-8fa46927fb4f
(main module does not need package v1.0.0-20200227125254-8fa46927fb4f)
$ go mod why gopkg.in/yaml.v2 v2.2.8 // indirect
# gopkg.in/yaml.v2
sigs.k8s.io/kubebuilder/internal/config
sigs.k8s.io/yaml
gopkg.in/yaml.v2

# v2.2.8
(main module does not need package v2.2.8)

# /
(main module does not need package /)

# indirect
(main module does not need package indirect)

Is it make sense @mengqiy? Are you ok with we clean it?

@mengqiy
Copy link
Member

mengqiy commented Apr 2, 2020

Also, note that these indirect imports are just added when we run make generated.

Though we do go mod tidy in

go mod tidy
, if go get in
- GO111MODULE=on go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.5
still cause the problem, we should do go get in a temp directory. This can avoid it messing up the go.mod file.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 9, 2020
@camilamacedo86
Copy link
Member Author

HI @mengqiy,

Now the go mod is clean the make generate target is fixed. I mean it will no longer install the indirect modules.

Comment on lines -60 to -63
.PHONY: generate-setup
generate-setup: ## Current workarround to generate the testdata with the correct controller-gen version
- rm -rf $(CONTROLLER_GEN_BIN_PATH)
- GO111MODULE=on go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to remove this section. I imagine that what you can do here is

  1. create a temp directory (e.g. using https://golang.org/pkg/io/ioutil/#TempDir)
  2. cd to that directory
  3. run go get with go modules on
  4. cd to the previous working directory
  5. remove the temp dir.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makefile target was added just to ensure that the correct version will be used.
Note that we just need to remove any pre-existent installation to ensure that. And then, the defined version in the makefile which will be scaffolded will be installed and used. So, it is not required at all and because of this, I keep just the rm -rf line and did not the tmp dir. See: https://github.com/kubernetes-sigs/kubebuilder/pull/1454/files#diff-b67911656ef5d18c4ae36cb6741b7965R57 Is it make sense?

Makefile Outdated
@@ -45,7 +52,9 @@ install: ## Build and install the binary with the current source code. Use it to

.PHONY: generate
generate: ## Update/generate all mock data. You should run this commands to update the mock data after your changes.
make generate-setup
# if an controller-gen be locally installed already it will be removed to ensure that the generate will
# get and use the correct version defined in the testdata makefiles instead of an previous installation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This statement doesn't match what is done.
controller-gen is not installed after removing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HI @mengqiy.

See:

When we start the controller-gen removed

Screenshot 2020-04-13 at 17 55 26

And then in it got in the by the scaffold files

Screenshot 2020-04-13 at 17 55 53

And then the gen installed when it finishes.

Screenshot 2020-04-13 at 17 58 07

So, what is your suggestion for the comment/explanation?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha... You rely on the Makefile in the generated project to install the controller-gen for you.
I didn't realized it. It's not intuitive, but seems to be OK.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the comment here to reflect how it work.
Then it should be OK to go.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if you are ok with the updates in the comment. Really tks for your review,

Copy link
Member

@mengqiy mengqiy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 13, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: camilamacedo86, mengqiy

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:
  • OWNERS [camilamacedo86,mengqiy]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit c8d4a3d into kubernetes-sigs:master Apr 13, 2020
@camilamacedo86 camilamacedo86 deleted the clean-imports branch April 13, 2020 23:45
@camilamacedo86 camilamacedo86 mentioned this pull request Apr 20, 2020
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants