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

Stop relying on -modfile to allow vendorization #968

Merged
merged 1 commit into from
Sep 10, 2021

Conversation

honza
Copy link
Member

@honza honza commented Sep 7, 2021

The Makefile targets we use to build our tools rely on the -modfile
flag of the go build command. Unfortunately, the golang build
toolchain doesn't respect the vendor directory relative to the go.mod
file specified by -modfile, and instead uses the vendor directory
relative to the current working directory. Since each subdirectory in
this repository that contains a go.mod file needs to have its own
vendor directory in order to be built in vendorized scenarios, relying
on -modfile doesn't work.

The patch modifies the affected Makefile targets to instead change to
the directory of the tool being built instead of using the -modfile
flag. This makes vendorization possible in downstream environments.

Finally, for consistency, we start building the kustomize tool in the
same way as controller-gen, and golangci-lint.

@metal3-io-bot metal3-io-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Sep 7, 2021
@ardaguclu
Copy link
Contributor

This is a good catch @honza, thanks.
/lgtm

@metal3-io-bot
Copy link
Contributor

@ardaguclu: adding LGTM is restricted to approvers and reviewers in OWNERS files.

In response to this:

This is a good catch @honza, thanks.
/lgtm

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.

@s3rj1k
Copy link
Member

s3rj1k commented Sep 7, 2021

/test-integration
/approve

@hardys
Copy link
Member

hardys commented Sep 8, 2021

/approve
/cc @zaneb

@metal3-io-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hardys, s3rj1k

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@metal3-io-bot metal3-io-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 8, 2021
@zaneb
Copy link
Member

zaneb commented Sep 8, 2021

This is unfortunate :( the -modfile approach seemed quite elegant compared to switching directories.
I wonder if in future we should create a second Makefile so that we can do e.g. make -C hack/tools controller-gen

There is another use of -modfile in tools/deploy.sh. Does that also need changing? Otherwise this LGTM.

@honza
Copy link
Member Author

honza commented Sep 8, 2021

There is another use of -modfile in tools/deploy.sh. Does that also need changing?

Fixed

Copy link
Member

@zaneb zaneb left a comment

Choose a reason for hiding this comment

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

/lgtm

tools/deploy.sh Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
@metal3-io-bot metal3-io-bot added the lgtm Indicates that a PR is ready to be merged. label Sep 8, 2021
@metal3-io-bot metal3-io-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed lgtm Indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Sep 8, 2021
@zaneb
Copy link
Member

zaneb commented Sep 9, 2021

/test-integration
/lgtm

@metal3-io-bot metal3-io-bot added the lgtm Indicates that a PR is ready to be merged. label Sep 9, 2021
@metal3-io-bot metal3-io-bot removed the lgtm Indicates that a PR is ready to be merged. label Sep 9, 2021
@honza
Copy link
Member Author

honza commented Sep 9, 2021

/test-integration

@honza
Copy link
Member Author

honza commented Sep 9, 2021

/test-integration

@honza
Copy link
Member Author

honza commented Sep 9, 2021

/test-integration

@honza
Copy link
Member Author

honza commented Sep 10, 2021

/test-integration

The Makefile targets we use to build our tools rely on the `-modfile`
flag of the `go build` command.  Unfortunately, the golang build
toolchain doesn't respect the vendor directory relative to the `go.mod`
file specified by `-modfile`, and instead uses the vendor directory
relative to the current working directory.  Since each subdirectory in
this repository that contains a `go.mod` file needs to have its own
vendor directory in order to be built in vendorized scenarios, relying
on `-modfile` doesn't work.

The patch modifies the affected Makefile targets to instead change to
the directory of the tool being built instead of using the `-modfile`
flag.  This makes vendorization possible in downstream environments.

Finally, for consistency, we start building the kustomize tool in the
same way as controller-gen, and golangci-lint.
@honza
Copy link
Member Author

honza commented Sep 10, 2021

/test-integration

@zaneb
Copy link
Member

zaneb commented Sep 10, 2021

/lgtm

@metal3-io-bot metal3-io-bot added the lgtm Indicates that a PR is ready to be merged. label Sep 10, 2021
@metal3-io-bot metal3-io-bot merged commit 5e75754 into metal3-io:master Sep 10, 2021
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. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants