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

Godep scripts cleanup #51766

Merged
merged 4 commits into from
Sep 30, 2017
Merged

Conversation

thockin
Copy link
Member

@thockin thockin commented Sep 1, 2017

Another try at sanitizing godep scripts. Instead of messing with containers, or assuming anything about GOPATHs, let's just work with whatever GOPATH we are given. If you want sane godep/restore behavior you can use ./hack/run-in-gopath.sh ./hack/godep-restore.sh. This will restore into your _output dir. You can update deps yourself, and then run ./hack/run-in-gopath.sh ./hack/godep-save.sh.

xref #44873

This also checks out godep into your working GOPATH. Without this, we have to go get it every time. We should just vendor it.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Sep 1, 2017
@k8s-github-robot
Copy link

Adding do-not-merge/release-note-label-needed because the release note process has not been followed.
One of the following labels is required "release-note", "release-note-action-required", "release-note-experimental" or "release-note-none".
Please see: https://github.com/kubernetes/community/blob/master/contributors/devel/pull-requests.md#write-release-notes-if-needed.

@k8s-github-robot k8s-github-robot added the do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. label Sep 1, 2017
@thockin thockin force-pushed the godep-scripts-cleanup branch 2 times, most recently from c848ea5 to f210a97 Compare September 1, 2017 16:26
@@ -1,11 +1,12 @@
{
"ImportPath": "k8s.io/kubernetes",
"GoVersion": "go1.8",
"GoVersion": "go1.9",
Copy link
Member

Choose a reason for hiding this comment

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

Are you running this locally? Master hasn't moved to go1.9 yet.

Copy link
Member Author

Choose a reason for hiding this comment

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

blarch, will revert that part :)

@@ -843,12 +844,12 @@
},
{
"ImportPath": "github.com/docker/distribution/digest",
"Comment": "v2.4.0-rc.1-38-gcd27f17",
"Comment": "v2.4.0-rc.1-38-gcd27f179",
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 the other reason to run godep in containers.. different git versions provided slightly different strings 😞 . Is this your local env, or inside a container?

Copy link
Member Author

Choose a reason for hiding this comment

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

local. The problem with doing this in containers is that some envs (jenkins) are already containerized, and we end up with a tangle of "is this already in a container? call a different script" sort of hacks. I want to move this forward as "it works locally, where locally can be in-a-container or not" as the general MO. Running this inside a container requires YET ANOTHER script to avoid rsyncing over the state in between steps.

kube::util::ensure_godep_version

kube::log::status "Downloading dependencies - this might take a while"
GOPATH="${GOPATH}:$(pwd)/staging" godep restore "$@"
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason you're using pwd over KUBE_ROOT?

Copy link
Member Author

Choose a reason for hiding this comment

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

From an earlier rev. Will fix

GOPATH="${KUBE_TEMP}/go" go install .
popd >/dev/null
kube::log::status "Installing godep version ${GODEP_VERSION}"
go install ./vendor/github.com/tools/godep/
Copy link
Member

Choose a reason for hiding this comment

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

I like this solution :)

Copy link
Member Author

Choose a reason for hiding this comment

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

there are others that can do the same - gazelle and kazel popped up. Later.

@cblecker
Copy link
Member

cblecker commented Sep 1, 2017

Cross build is broken: #51815

echo "- hack/update-bazel.sh to recreate the BUILD files"
echo "- hack/update-godep-licenses.sh if you added or removed a dependency!"
kube::log::status "Running godep save - this might take a while"
GOPATH="${GOPATH}:$(pwd)/staging" godep save "${REQUIRED_BINS[@]}"
Copy link
Member

Choose a reason for hiding this comment

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

KUBE_ROOT here instead of pwd?

@cblecker
Copy link
Member

cblecker commented Sep 1, 2017

This looks pretty good. Pulling down and testing locally.

@cblecker
Copy link
Member

cblecker commented Sep 1, 2017

Noticed #51819 while testing

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.

Okay, kicked the tires on this in a bunch of ways, and it looks pretty solid. Couple things, then lgtm:

@@ -22,40 +22,65 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${KUBE_ROOT}/hack/lib/init.sh"
source "${KUBE_ROOT}/hack/lib/util.sh"

TMPPFX="_godep_tmp."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested patch:

diff --git a/hack/godep-save.sh b/hack/godep-save.sh
index 3c04e341ab..400bdd0232 100755
--- a/hack/godep-save.sh
+++ b/hack/godep-save.sh
@@ -22,34 +22,35 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
 source "${KUBE_ROOT}/hack/lib/init.sh"
 source "${KUBE_ROOT}/hack/lib/util.sh"
 
-TMPPFX="_godep_tmp."
-
 kube::log::status "Ensuring prereqs"
 kube::util::ensure_single_dir_gopath
 kube::util::ensure_no_staging_repos_in_gopath
-
 kube::util::ensure_godep_version
+kube::util::ensure-temp-dir
+
+GODEP_TMPPFX="${KUBE_TEMP}/_godep_tmp."
+
 
-function cleanup() {
-    if [[ -d "${TMPPFX}vendor" ]]; then
-        kube::log::error "${TMPPFX}vendor exists, restoring it"
+function kube::godep::cleanup() {
+    if [[ -d "${GODEP_TMPPFX}vendor" ]]; then
+        kube::log::error "${GODEP_TMPPFX}vendor exists, restoring it"
         rm -rf vendor
-        mv "${TMPPFX}vendor" vendor
+        mv "${GODEP_TMPPFX}vendor" vendor
     fi
-    if [[ -d "${TMPPFX}Godeps" ]]; then
-        kube::log::error "${TMPPFX}Godeps exists, restoring it"
+    if [[ -d "${GODEP_TMPPFX}Godeps" ]]; then
+        kube::log::error "${GODEP_TMPPFX}Godeps exists, restoring it"
         rm -rf Godeps
-        mv "${TMPPFX}Godeps" Godeps
+        mv "${GODEP_TMPPFX}Godeps" Godeps
     fi
 }
-trap cleanup EXIT
+kube::util::trap_add kube::godep::cleanup EXIT
 
 # Clear old state, but save it in case of error
 if [[ -d vendor ]]; then
-    mv vendor "${TMPPFX}vendor"
+    mv vendor "${GODEP_TMPPFX}vendor"
 fi
 if [[ -d Godeps ]]; then
-    mv Godeps "${TMPPFX}Godeps"
+    mv Godeps "${GODEP_TMPPFX}Godeps"
 fi
 
 # Some things we want in godeps aren't code dependencies, so ./...
@@ -83,4 +84,4 @@ kube::log::status "Updating LICENSES file"
 hack/update-godep-licenses.sh >/dev/null
 
 # Clean up
-rm -rf "${TMPPFX}vendor" "${TMPPFX}Godeps"
+rm -rf "${GODEP_TMPPFX}vendor" "${GODEP_TMPPFX}Godeps"
diff --git a/hack/lib/util.sh b/hack/lib/util.sh
index 2b832335f1..4ddc7bbf99 100755
--- a/hack/lib/util.sh
+++ b/hack/lib/util.sh
@@ -85,7 +85,7 @@ kube::util::trap_add() {
     if [[ -z "${existing_cmd}" ]]; then
       new_cmd="${trap_add_cmd}"
     else
-      new_cmd="${existing_cmd};${trap_add_cmd}"
+      new_cmd="${trap_add_cmd};${existing_cmd}"
     fi
 
     # Assign the test

What this does:

  • Uses ensure-temp-dir to create a system temp directory that gets cleaned up, out of tree (so that _godep_tmp dirs don't get left behind)
  • Uses a more specific variable name
  • Fixes ordering in the trap_add function so that more recently added traps will get completed first (such as restoring the vendor dir before the temp dir is cleaned up)

WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

KUBE_TEMP is not guaranteed to be on the same device, which could turn the mv into a slow cp. We could instead do _output/local/tmp/$RANDOM or something, if you feel strongly.

Will apply parts of your patch and we can discuss the rest. PTAL

@@ -2281,7 +2292,7 @@
},
{
"ImportPath": "github.com/pmezard/go-difflib/difflib",
"Rev": "d8ed2627bdf02c080bf22230dbb337003b7aba2d"
"Rev": "f78a839676152fd9f4863704f5d516195c18fc14"
Copy link
Member

Choose a reason for hiding this comment

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

This change requires a hack/update-staging-godeps.sh run on it to pick up in the staging repos too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, Maybe I should undo this. This is where godep kind of stinks. Which is a better choice?

Copy link
Member

Choose a reason for hiding this comment

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

@@ -22,40 +22,65 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${KUBE_ROOT}/hack/lib/init.sh"
source "${KUBE_ROOT}/hack/lib/util.sh"

GODEP_TMPPFX="_godep_save__tmp."
Copy link
Member

Choose a reason for hiding this comment

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

The other option here would be:

mkdir -p "${KUBE_ROOT}/_tmp/"
GODEP_TMPPFX="${KUBE_ROOT}/_tmp/_godep_save__tmp."

This would work too as /_tmp/ is in .gitignore and isn't rsync'd, but would be in tree so it would be on the same device.

Copy link
Member Author

Choose a reason for hiding this comment

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

Does anything clean up _tmp ? is _output/local/tmp better or worse? Is that rsynced?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not aware of anything that cleans up _tmp.

I think either of them would work, as the two are treated similarly by gitignore and rsync. The only folder that is touched by rsync is _output/dockerized/bin, and it's copied to _output/bin. _output is also used by the build-image and generating the release files.

_tmp on the other hand is used by doc generation, by jenkins, and by the godep-licences script:

# create a nice clean place to put our new godeps
# must be in the user dir (e.g. KUBE_ROOT) in order for the docker volume mount
# to work with docker-machine on macs
mkdir -p "${KUBE_ROOT}/_tmp"
_tmpdir="$(mktemp -d "${KUBE_ROOT}/_tmp/kube-godep-licenses.XXXXXX")"
#echo "Created workspace: ${_tmpdir}"
function cleanup {
#echo "Removing workspace: ${_tmpdir}"
rm -rf "${_tmpdir}"
}
trap cleanup EXIT

based on that, _tmp seems like the right candidate. also looks like some cleanup could be done in that verify script to match this one (but that could also be a separate 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.

pushed now with _tmp. We should probably add that to make clean though.

@cblecker
Copy link
Member

cblecker commented Sep 1, 2017

Hmm.. this didn't happen for me locally. Going to clear out my gopath and try again:

W0901 20:52:55.095] godep: error restoring dep (golang.org/x/tools/go/vcs): Wanted to restore rev 1f1b3322f67af76803c942fd237291538ec68262, already restored rev 2382e3994d48b1d22acc2c86bcad0a2aff028e32 for another package in the repo
W0901 20:52:55.404] godep: Error restoring some deps. Aborting check.
W0901 20:52:55.411] !!! Error in ./hack/godep-restore.sh:35
W0901 20:52:55.411]   Error in ./hack/godep-restore.sh:35. 'GOPATH="${GOPATH}:${KUBE_ROOT}/staging" godep restore "$@"' exited with status 1

That looks to be from adding godep to Godeps

@thockin
Copy link
Member Author

thockin commented Sep 1, 2017

indeed. Let me pull off the last commit, we can deal with that on its own. It looks like godep is utterly failing to handle this. Surprise.

@thockin
Copy link
Member Author

thockin commented Sep 1, 2017

oh, this was my fault. I manually fixed one rev, but missed the other from the same repo.

@cblecker
Copy link
Member

cblecker commented Sep 1, 2017

I0901 22:27:53.986] Godeps Verify failed.
I0901 22:27:53.986] If you're seeing this locally, run the below command to fix your directories:
I0901 22:27:53.986] patch -p0 < vendordiff.patch
I0901 22:27:53.987] (The above output can be saved as godepdiff.patch if you're not running this locally)
I0901 22:27:53.987] (The patch file should also be exported as a build artifact if run through CI)
I0901 22:27:53.987] Copying patch to artifacts..
I0901 22:27:53.987] Leaving /tmp/gopath.6afuma for you to examine or copy. Please delete it manually when finished. (rm -rf /tmp/gopath.6afuma)
I0901 22:27:53.987] FAILED   hack/make-rules/../../hack/verify-godeps.sh	1082s

https://storage.googleapis.com/kubernetes-jenkins/pr-logs/pull/51766/pull-kubernetes-verify/49544/artifacts/vendordiff.patch

@thockin
Copy link
Member Author

thockin commented Sep 1, 2017

had to revert one pwd because godep barfs on staging stuff during save (not too surprising - we're doing strange stuff)

"./..."
)

pushd "${KUBE_ROOT}" > /dev/null
Copy link
Member

@cblecker cblecker Sep 1, 2017

Choose a reason for hiding this comment

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

Oh! I think that's because previously we were pushd'ing into KUBE_ROOT before start. We still used KUBE_ROOT in the original save command below.

@thockin thockin added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Sep 15, 2017
@thockin
Copy link
Member Author

thockin commented Sep 15, 2017

@cblecker any clues on what was up in your env?

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

thockin commented Sep 28, 2017

@cblecker Now that 1.8 is locked and loaded, I'd like to get this in and see if it really hurts anyone besides you :)

@cblecker
Copy link
Member

@thockin Sorry, day job has been getting in the way. I'll take another stab at it

@thockin
Copy link
Member Author

thockin commented Sep 28, 2017

/retest

bitbucket gave a 404. nice.

exit 1
kube::util::ensure_godep_version

TMPDIR=_tmp/godep-save.$RANDOM
Copy link
Member

@cblecker cblecker Sep 29, 2017

Choose a reason for hiding this comment

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

Okay! Thanks for your patience @thockin. Debugged this, and the issue for me is the naming of this variable. Darwin uses TMPDIR as a system ENVVAR. When this got to the updating bazel step, the kube::util::go_install_from_commit function uses the system TMPDIR and everything blows up. If you rename this to something script-specific (e.g. TMPGODEPDIR in my testing) then everything seems to run just fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

DONE!

@cblecker
Copy link
Member

/retest

1 similar comment
@cblecker
Copy link
Member

/retest

@cblecker
Copy link
Member

/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 Sep 30, 2017
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

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

Associated issue: 44873

The full list of commands accepted by this bot can be found here.

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

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to @fejta).

Review the full test history for this PR.

@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 d2bbeb6 into kubernetes:master Sep 30, 2017
k8s-github-robot pushed a commit to kubernetes/community that referenced this pull request Sep 30, 2017
Automatic merge from submit-queue.

Rewrite docs on godep

This corresponds to kubernetes/kubernetes#51766 - do not merge until we get confirmation on that PR.
k8s-github-robot pushed a commit that referenced this pull request Jan 31, 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>.

Fix installation and use of vendored godep

**What this PR does / why we need it**:
Fixes the installation of the vendored godep to ensure that the binary ends up in the path when it's done.

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes #58975

**Special notes for your reviewer**:
It looks like this broke in #51766, but didn't matter because our pinned version was the same as the latest version (so we didn't notice). This fixes it in my local env -- hopefully it will in CI too.

**Release note**:
```release-note
NONE
```
@thockin thockin deleted the godep-scripts-cleanup 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/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

7 participants