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

Don't check in zz_generated.openapi.go. #41106

Merged
merged 3 commits into from
Apr 27, 2017
Merged

Conversation

spxtr
Copy link
Contributor

@spxtr spxtr commented Feb 8, 2017

zz_generated.openapi.go is the file that causes the most merge conflicts of all. In #33440, @thockin updated the makefile to support generating these files on demand, but that didn't play well with bazel/gazel.

In this PR, I add a new build macro that will generate this file with a go_genrule. I added support for keeping the BUILD file up to date in mikedanese/gazel#34.

Release note:

NONE

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Feb 8, 2017
@k8s-github-robot k8s-github-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. release-note-label-needed labels Feb 8, 2017
@k8s-reviewable
Copy link

This change is Reviewable

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-label-needed labels Feb 8, 2017
@spxtr spxtr force-pushed the gen3 branch 3 times, most recently from 421831e to 16a502a Compare February 8, 2017 01:49
@spxtr spxtr mentioned this pull request Feb 9, 2017
@@ -22,5 +22,8 @@ source "${KUBE_ROOT}/hack/lib/init.sh"

git config http.https://gopkg.in.followRedirects true

go get -u gopkg.in/mikedanese/gazel.v13/gazel
# Remove generated files prior to running gazel.
rm -f "${KUBE_ROOT}/pkg/generated/openapi/zz_generated.openapi.go"
Copy link
Member

Choose a reason for hiding this comment

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

... :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Eventually this will be make clean_generated instead, but for now this will have to do.

gazel isn't smart enough to do it any other way iiuc.

@spxtr spxtr force-pushed the gen3 branch 2 times, most recently from a7c8780 to 8626cdc Compare February 10, 2017 19:46
@@ -22,5 +22,8 @@ source "${KUBE_ROOT}/hack/lib/init.sh"

git config http.https://gopkg.in.followRedirects true

# Remove generated files prior to running gazel.
rm -f "${KUBE_ROOT}/pkg/generated/openapi/zz_generated.openapi.go"
Copy link
Member

Choose a reason for hiding this comment

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

Will this exist forever? This means that any time we run gazel, we will have to rebuild all generated files, even if net nothing changed...

Or does this come with a TODO?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we only use Bazel to build then we can delete this, since Bazel doesn't put the generated file in with the rest of the source. As long as we support both Bazel and make we'll need this.

We could consider adding the ability to gazel to move files to somewhere else and then back after the run, but I don't think it's worth it.

Copy link
Member

Choose a reason for hiding this comment

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

Can we maybe use +build tags to make bazel ignore it or something? Or can it come with a TODO comment to remove this line completely once Bazel is the only way to build?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a TODO. Our generated code has the !ignore_autogenerated tag on it that we might be able to use, but only once bazel can generate all of our code.

export KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
cd "${KUBE_ROOT}"
# List go packages with the k8s:openapi-gen tag.
files=$(grep --color=never -l '+k8s:openapi-gen=' \
Copy link
Member

Choose a reason for hiding this comment

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

This is going to include vendor/ - is that intended? The find used in the Make process is very carefully written...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I copied the find from the makefile, but I'm not sure that there's a good way to keep it up to date. We do want to include vendor/.

Using the make process, if I touch vendor/k8s.io/apimachinery/pkg/apis/meta/v1/doc.go then run make generated_files, it will recreate the generated files under there. Evidently the source of truth for that stuff is vendor/...

Copy link
Member

Choose a reason for hiding this comment

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

ugggggggggh, I didn't see that coming - the repo splits now force us to codegen for a vendored repo.

Copy link
Member

Choose a reason for hiding this comment

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

but when we codegen, we exclude vendor...

hack/make-rules/helpers/cache_go_dirs.sh

how does it work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I rm vendor/k8s.io/apimachinery/pkg/apis/meta/v1/zz_generated.deepcopy.go and then run make generated_files, it recreates the file. Not sure how it works, but for now I was planning on maintaining that behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This whole staging and vendor thing is super confusing.

@@ -22,6 +22,9 @@ source "${KUBE_ROOT}/hack/lib/init.sh"

git config http.https://gopkg.in.followRedirects true

# Remove generated files prior to running gazel.
rm -f "${KUBE_ROOT}/pkg/generated/openapi/zz_generated.openapi.go"
Copy link
Member

Choose a reason for hiding this comment

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

same comment as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same response.

Copy link
Member

Choose a reason for hiding this comment

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

same response

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copied the TODO here as well.



def openapi_library(name, tags, srcs):
deps = [
Copy link
Member

Choose a reason for hiding this comment

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

is this file generated? From what? I'm not seeing where it originates..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, this file is hand-written. However, gazel will still automanage the go_default_library in pkg/generated/openapi/BUILD. This isn't a big deal for this generated file, since its only source is doc.go, but it will be important for the other zz_generated files.

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 14, 2017
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 14, 2017
@spxtr
Copy link
Contributor Author

spxtr commented Feb 14, 2017

Trivial rebase, no changes outside of zz_generated.openapi.go, which is deleted.

@spxtr
Copy link
Contributor Author

spxtr commented Feb 16, 2017

@thockin PTAL

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 16, 2017
@thockin
Copy link
Member

thockin commented Feb 17, 2017

This seems OK (modulo comments) for this, but now I am worried about the other generators wrt vendor/ - should we hold off on merge until we know we know what is happening there?

@spxtr
Copy link
Contributor Author

spxtr commented Feb 17, 2017

@mikedanese has a PR out (#40777) to put BUILD files in individual vendor directories. This will significantly cut back on rebases, since vendor/BUILD is terrible, but it will also make it so that I can autogenerate the files in vendor/k8s.io/apimachinery and the like using the same strategy.

I think this PR can go in before we know what happens with vendor/ and staging/, but the next one that will add zz_generated.{deepcopy,conversion,defaults}.go should probably wait.

@k8s-github-robot k8s-github-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Feb 17, 2017
load("@io_kubernetes_build//defs:go.bzl", "go_genrule")

OPENAPI_TARGETS = [
"cmd/libs/go2idl/client-gen/test_apis/testgroup/v1",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@thockin: After talking with @mikedanese, I think it's a good idea to automanage these lists with gazel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 30, 2017
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 26, 2017
@spxtr
Copy link
Contributor Author

spxtr commented Apr 26, 2017

#40777 is in, so this can proceed.

"doc.go",
"zz_generated.openapi.go",
srcs = ["doc.go"],
openapi_targets = [
Copy link
Member

Choose a reason for hiding this comment

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

Remind me - this list is manually maintained? Or do we auto-figure that out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gazel automanages it :)

@thockin
Copy link
Member

thockin commented Apr 26, 2017

I'm OK to get this in, but I think being manually managed will catch up with us very quickly.

@spxtr
Copy link
Contributor Author

spxtr commented Apr 26, 2017

@k8s-bot gce etcd3 e2e test this

@thockin
Copy link
Member

thockin commented Apr 26, 2017 via email

@spxtr
Copy link
Contributor Author

spxtr commented Apr 26, 2017

Do I need to change anything in this one or should it go in as-is? It's going to make #3340 need a rebase.

@thockin
Copy link
Member

thockin commented Apr 27, 2017 via email

@spxtr
Copy link
Contributor Author

spxtr commented Apr 27, 2017

If we end up merging both and need to rollback both then we can do so in one PR with multiple git revert calls.

@mikedanese
Copy link
Member

I'm happy to give this a shot when you guys are.

multiple git revert calls.

git revert allows for a revert of a merge commit, which reverts all commits that were merged in a single go. Checkout git revert -m option.

@mikedanese
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 27, 2017
@thockin
Copy link
Member

thockin commented Apr 27, 2017

/approve

@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mikedanese, spxtr, thockin

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 27, 2017
Copy link
Member

@thockin thockin left a comment

Choose a reason for hiding this comment

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

My PR still needs genrules :)

go get gopkg.in/mikedanese/gazel.v16/gazel
# Remove generated files prior to running gazel.
# TODO(spxtr): Remove this line once Bazel is the only way to build.
rm -f "${KUBE_ROOT}/pkg/generated/openapi/zz_generated.openapi.go"
Copy link
Member

Choose a reason for hiding this comment

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

In my PR I went the other way - force it to be generated before running gazel. Otherwise some symbols are missing for other genfiles

@mikedanese mikedanese added do-not-merge DEPRECATED. Indicates that a PR should not merge. Label can only be manually applied/removed. and removed do-not-merge DEPRECATED. Indicates that a PR should not merge. Label can only be manually applied/removed. labels Apr 27, 2017
@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit 98398d5 into kubernetes:master Apr 27, 2017
@spxtr spxtr deleted the gen3 branch April 27, 2017 18:49
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. release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants