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

Vendor gazelle and kazel #57600

Merged
merged 4 commits into from
Apr 2, 2018
Merged

Conversation

thockin
Copy link
Member

@thockin thockin commented Dec 23, 2017

Rather that relying on upstream git repos that can break, vendor it all. These are NOT head of tree, respectively - they are some backrev forms that were previously being used.

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Dec 23, 2017
@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 24, 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 Dec 27, 2017
@fejta
Copy link
Contributor

fejta commented Dec 27, 2017

Love the idea. Any idea why tests are failing?

@thockin
Copy link
Member Author

thockin commented Dec 27, 2017

godep is not picking up a transitive dep - trying to figure out why. Some of teh bazel repos were renamed, and kazel uses the old name, so I wonder if something is confused. Of course, godep is useless...

github.com/bazelbuild/buildifier is now github.com/bazelbuild/buildtools

@cblecker
Copy link
Member

Just came across this.. was taking a look at the viability of this last week!

The transitive dep issue is fixed in this one: kubernetes/repo-infra#54.. repo-infra doesn't have a dependency definition file at all, just a vendor dir.. but you can't vendor a vendor dir.

@thockin: Is it safer to install these utils to a temp gopath, rather than clobber whatever version is in the running user's gopath? (my WIP branch: https://github.com/kubernetes/kubernetes/compare/master...cblecker:vendor-bazel-stuff?expand=1)

@thockin
Copy link
Member Author

thockin commented Dec 27, 2017

I started installing to the phony local GOPATH, but I am torn on it. It's trivial to do (1 line). The godep scripts don't do that either. Open to opinion

@thockin
Copy link
Member Author

thockin commented Dec 27, 2017

Indeed, it seems that godep satisfies itself with github.com/kubernetes/repo-infra/vendor/github.com/bazelbuild/buildifier/core but that does not include the tables sub-package. It's amazing this works at all.

@thockin
Copy link
Member Author

thockin commented Dec 27, 2017

Ugh, I hate GOPATH. Non-hermetic no matter what I do. Kazel only builds because of it. If I run-in-gopath, then the missing dep is satisfied from GOPATH but ONLY IF I previously ran godep-restore.

I really want different GOPATHs for different purposes...

@fejta
Copy link
Contributor

fejta commented Dec 28, 2017

Agreed that GOPATH and how golang handles symlinks is pretty terrible 😞

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

thockin commented Jan 10, 2018

Need to re-run the godep imports, out of time for tonight.

"Rev": "737df20c53499fd84b67f04c6ca9ccdee2e77089"
},
{
"ImportPath": "github.com/bazelbuild/rules_go/go/tools/gazelle/gazelle",
Copy link
Member

Choose a reason for hiding this comment

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

note for when you revisit this: the 0.8.0 tag in bazelbuild/bazel-gazelle is compatible with the version of gazelle we're using now, and is preferred over the gazelle in rules_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.

no 0.8.0, but 0.8 matches the hash.

k8s-github-robot pushed a commit that referenced this pull request Jan 15, 2018
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Install gazelle from bazelbuild/bazel-gazelle instead of rules_go

**What this PR does / why we need it**: downloads gazelle from its new home; it's being removed from `bazelbuild/rules_go`. It also removes @spiffxp's workaround from a few weeks ago.

**Special notes for your reviewer**: these should really be vendored (#57600), but this prevents us from running into issues in the meantime.

**Release note**:

```release-note
NONE
```

/approve no-issue
/assign @BenTheElder
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 17, 2018
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 17, 2018
@thockin
Copy link
Member Author

thockin commented Jan 17, 2018

Pushed with updated gazelle and repo-infra that satisfies godep.

Copy link
Member

@ixdy ixdy left a comment

Choose a reason for hiding this comment

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

I think this might finally be ready for final rebase and merge.

Note we're now using gazelle 0.10.1 in k/k. I've also ensured that the master branch of kazel now builds with the version of bazelbuild/buildtools vendored by gazelle.

578e73e57d6a4054ef933db1553405c9284322c7
# Install tools we need, but only from vendor/...
go install ./vendor/github.com/bazelbuild/bazel-gazelle/cmd/gazelle
if ! which gazelle >/dev/null 2>&1; then
Copy link
Member

@ixdy ixdy Mar 27, 2018

Choose a reason for hiding this comment

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

this seems pretty fragile - it's can be possible that $GOPATH/bin is not in your PATH, but there might already be a gazelle installed in $PATH anyway, which will cause this to pass unexpectedly.

Maybe instead set GOBIN="${KUBE_OUTPUT_BINPATH}" (i.e. $KUBE_ROOT/_output/bin) before running go install?

this is what I did for kubernetes/test-infra#7429 and kubernetes/repo-infra#65 and it seems to be working well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not a bad idea. I forgot we have that.

@thockin
Copy link
Member Author

thockin commented Mar 29, 2018

Rebased & revendored. Let's see...

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 29, 2018
@ixdy
Copy link
Member

ixdy commented Mar 29, 2018

Oh, hah, verify-bazel.sh is also diffing _output/local/bin. This PR is cursed.

I0329 17:08:15.675] Verifying verify-bazel.sh
I0329 17:08:15.691] 
I0329 17:08:15.692] +++ Running case: verify.bazel 
I0329 17:08:15.694] +++ working dir: /go/src/k8s.io/kubernetes
I0329 17:08:15.696] +++ command: bash "hack/make-rules/../../hack/verify-bazel.sh"
W0329 17:08:29.053] hack/make-rules/../../hack/verify-bazel.sh: line 45: warning: command substitution: ignored null byte in input
W0329 17:08:31.307] diff -Naupr /go/src/k8s.io/kubernetes/_output/local/bin/gazelle /tmp/verify-bazel.ZI9Uhx/go/src/k8s.io/kubernetes/_output/local/bin/gazelle
W0329 17:08:31.308] --- /go/src/k8s.io/kubernetes/_output/local/bin/gazelle	1970-01-01 00:00:00.000000000 +0000
W0329 17:08:31.308] +++ /tmp/verify-bazel.ZI9Uhx/go/src/k8s.io/kubernetes/_output/local/bin/gazelle	2018-03-29 17:08:20.781360056 +0000
W0329 17:08:31.309] @@ -0,0 +1,32099 @@
W0329 17:08:31.309] +�ELF����>�À¤E@p�@8
...

@cblecker
Copy link
Member

I have a feeling that the method I use in #59210 would work here. Because we install it, then record the path it was installed to for re-use, it doesn't try to do things like install it a second time into temp paths.

@thockin
Copy link
Member Author

thockin commented Mar 29, 2018

/retest

@@ -40,7 +40,7 @@ mkdir -p "${_tmp_kuberoot}/.."
cp -a "${KUBE_ROOT}" "${_tmp_kuberoot}/.."

cd "${_tmp_kuberoot}"
GOPATH="${_tmp_gopath}" ./hack/update-bazel.sh
GOPATH="${_tmp_gopath}" PATH="${_tmp_gopath}/bin:${PATH}" ./hack/update-bazel.sh

diff=$(diff -Naupr "${KUBE_ROOT}" "${_tmp_kuberoot}" || true)
Copy link
Member

Choose a reason for hiding this comment

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

I think adding an exclude on _output to the diff should fix the remaining failure:

diff --git a/hack/verify-bazel.sh b/hack/verify-bazel.sh
index 4a110ebad0..132428fc12 100755
--- a/hack/verify-bazel.sh
+++ b/hack/verify-bazel.sh
@@ -42,7 +42,7 @@ cp -a "${KUBE_ROOT}" "${_tmp_kuberoot}/.."
 cd "${_tmp_kuberoot}"
 GOPATH="${_tmp_gopath}" PATH="${_tmp_gopath}/bin:${PATH}" ./hack/update-bazel.sh
 
-diff=$(diff -Naupr "${KUBE_ROOT}" "${_tmp_kuberoot}" || true)
+diff=$(diff -Naupr -x '_output' "${KUBE_ROOT}" "${_tmp_kuberoot}" || true)
 
 if [[ -n "${diff}" ]]; then
   echo "${diff}" >&2

@thockin
Copy link
Member Author

thockin commented Mar 30, 2018

w00t! it's green.

Copy link
Member

@cblecker cblecker left a comment

Choose a reason for hiding this comment

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

Mostly fine. One question, and one potential request for follow up.

github.com/bazelbuild/bazel-gazelle/cmd/gazelle \
0.10.1
# Ensure that we find the binaries we build before anything else.
export GOBIN="${KUBE_OUTPUT_BINPATH}"
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to export this? I don't like modifying a user's environment beyond the life of the script. There's a couple other cases that you're doing this too, so I'm not sure if it's strictly a requirement.

Copy link
Member Author

Choose a reason for hiding this comment

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

export exists for the life of the shell, not longer. Maybe I misunderstand. I did not put it in a generic place that gets sourced, for this reason.

$ echo $FOO; (export FOO=foo; echo $FOO; (export FOO=bar; echo $FOO); echo $FOO); echo $FOO

foo
bar
foo

GP="$(echo $GOPATH | cut -f1 -d:)"
hash -r # force bash to clear PATH cache
PATH="${GP}/bin:${PATH}"
if ! which godep >/dev/null 2>&1; then
Copy link
Member

Choose a reason for hiding this comment

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

I don't like that there is inconsistency between the way we handle godep, and the way we are handling gazelle/kazel/misspell.

It's not enough of a dislike to block this PR that we badly need, but I'd really like if we could unify on a single way (maybe via a helper util function) to install a specific version of a go app from vendor, use it in the context of the script, with as little pollution of the environment as possible. Maybe I'll look at this in a follow up PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could set GOBIN in init.sh or something, and then always call $GOBIN/godep

But as long as we're checking the version of godep, it shouldn't matter. I agree it would be cleaner to be consistent. Our scripts are a mess here.

function gobin() {
  echo "${KUBE_OUTPUT_BINPATH}"
}

function go_install() {
  GOBIN="$(gobin)" go install "$@"
}

function run_private() {
  PATH="$(gobin):${PATH}" "$@"
}

function run_global() {
  "$@"
}


go_install ./vendor/github.com/tools/godep/
run_private godep save

alternatively, make teh callers of ensure_godep_version pass the path to the godep they are using, and they can pass ${GOBIN}/godep ?

Agree it should be a followup

@cblecker
Copy link
Member

cblecker commented Apr 2, 2018

/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 2, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cblecker, thockin

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

@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 3ea4e44 into kubernetes:master Apr 2, 2018
@@ -17,6 +17,7 @@ openapi_library(
"pkg/kubelet/apis/kubeletconfig/v1beta1",
"pkg/proxy/apis/kubeproxyconfig/v1alpha1",
"pkg/version",
"vendor/github.com/kubernetes/repo-infra/kazel",
Copy link
Member

Choose a reason for hiding this comment

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

welp, the openapi generator in kazel is picking up itself, erroneously. I'll fix this.

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks

k8s-github-robot pushed a commit that referenced this pull request Jun 11, 2018
…57600-#62499-upstream-release-1.10

Automatic merge from submit-queue.

Automated cherry pick of #61575: Remove all upstream BUILD, BUILD.bazel, and WORKSPACE #57600: Vendor gazelle #62499: Update kazel to include openapi tag detection fix

Cherry pick of #61575 #57600 #62499 on release-1.10.

#61575: Remove all upstream BUILD, BUILD.bazel, and WORKSPACE
#57600: Vendor gazelle
#62499: Update kazel to include openapi tag detection fix

This is an alternative to #64928, and would fix #64925.

We can't just cherry-pick #57600, since there was a prerequisite PR and a fixup PR afterwards.
@thockin thockin deleted the vendor-gazelle branch August 14, 2019 17:43
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/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.

None yet

9 participants